IB Year 1 Standard Level Computer Science

Tuesday 24 September 2024 - Block 1
← previous note | most current note | next note →
 

Daily Note

I know you have been learning alot, so the next few classes will be nothing but problem sets to help you practice, practice, practice. 

 

4X Spaceship Game: Building a Fleet Using OOP in Python

Objective:  
You will design and code a fleet of spaceships using object-oriented programming (OOP) concepts in Python. By the end of this activity, you should have a functioning class structure that models a fleet, individual spaceships, and their abilities. You will also simulate some interactions between your spaceships, like combat or exploration.

Part 1: Basic Class Design 

1. Create a Spaceship Class:
   - Define a `Spaceship` class. Each spaceship should have the following attributes:
     - `name`: The name of the spaceship (string).
     - `hull_strength`: The hull strength of the spaceship (integer, starts at 100).
     - `shields`: The shield strength of the spaceship (integer, starts at 50).
     - `firepower`: The weapon strength of the spaceship (integer).
     - `fuel`: The amount of fuel (integer, starts at 100).
   - Methods:
     - `attack(target)`: Attacks another spaceship (target), reducing their shield or hull strength.
     - `take_damage(amount)`: Reduces the shields, then hull strength if shields are depleted.
     - `status()`: Prints the spaceship's current status (name, hull, shields, and fuel).
   
2. Create a Fleet Class:
   - Define a `Fleet` class. A fleet consists of multiple spaceships. The `Fleet` class should:
     - Store a list of `Spaceship` objects.
     - Have methods to:
       - `add_ship(ship)`: Adds a spaceship to the fleet.
       - `remove_ship(ship_name)`: Removes a spaceship by name.
       - `fleet_status()`: Prints the status of all spaceships in the fleet.
  
Part 2: Adding Game Mechanics

1. Add Exploration and Fuel Mechanics:
   - Add a method to the `Spaceship` class called `explore(distance)`:
     - Each spaceship can explore a certain distance. However, traveling consumes fuel. For every 10 units of distance, reduce the fuel by 5 units.
     - If the spaceship runs out of fuel, it should print a message saying it can no longer explore.
   
2. Combat Simulation:
   - Modify the `attack(target)` method in the `Spaceship` class so that when a spaceship attacks another:
     - It reduces the target’s shields first.
     - If the shields reach 0, it begins to reduce the target’s hull strength.
     - Once the hull strength hits 0, the spaceship is destroyed.
   - After the attack, print a summary of the target spaceship’s remaining health.

Part 3: Scenario Simulation

1. Create a Fleet Battle:
   - Write a simulation where two fleets engage in combat. You should:
     - Create two fleets (one for your team, and one for the opposing team).
     - Add at least **3 spaceships** to each fleet.
     - Alternate turns where spaceships from both fleets attack each other.
     - After each attack, print the status of the target spaceship.
     - Continue the battle until one fleet has no remaining ships.
   
2. Victory Conditions:
   - A fleet wins if the other fleet’s spaceships are all destroyed. Print a victory message for the winning fleet.

Optional Bonus: Advanced Features

If you complete the main tasks early, add one or more of the following:

- Resource Management: Add `resources` to your fleet and make it so that attacking or repairing a spaceship consumes resources.
- Repairs: Add a `repair` method to your `Spaceship` class that allows the spaceship to repair its hull and shields using resources.
- Special Ship Types: Create subclasses for different types of spaceships (e.g., `Battlecruiser`, `Scout`, `Carrier`), each with unique attributes and methods.

---

Deliverables:
1. A Python script that defines your `Spaceship` and `Fleet` classes.
2. A battle simulation between two fleets, with detailed logs of each turn.

End of Class: At the end of the activity, we will discuss your fleet design and strategies. Be prepared to share your approach and any challenges you faced.

 

 

A little less comfortable

Content

Programs must solve the problem they were create to solve. We can worry about how effieciently or elegantly they solve the problem later on; not right now. The content of a program entails input, processing and output. All three of these elements must be clearly observable. A key question you will be asked (and you should ask yourself) is: to what extent does your code implement the features required by the specification?  

Process

Within the process, we are looking at six guiding questions: 

  • To what extent is your code written well (i.e. clearly, efficiently, elegantly, and/or logically)?
  • To what extent is your code eliminating repetition?
  • To what extent is your code using functions appropriately?
  • To what extent is your code readable?
  • To what extent is your code commented?
  • To what extent are your variables well named?

Product

As opposed to content, this section we focus on how well you solved the problem. A key question here is to what extent is your code free of bugs?

 

A little more comfortable

Content

Programs must solve the problem they were create to solve. You should ask yourself "Am I solving this elegantly?". The content of a program entails input, processing and output. All three of these elements must be clearly observable, and we must see evidence of sanitizing input and raising exceptions.  A key question you will be asked (and you should ask yourself) is: to what extent does your code implement the features required by the specification?  

Process

Within the process, we are looking at six guiding questions: 

  • To what extent is your code written well (i.e. clearly, efficiently, elegantly, and/or logically)?
  • To what extent is your code eliminating repetition?
  • To what extent is your code using functions appropriately?
  • To what extent is your code readable?
  • To what extent is your code commented?
  • To what extent are your variables well named?

For those more comfortable programming, we expect succinct, secure and effecient problem solving. 

Product

As opposed to content, this section we focus on how well you solved the problem. A key question here is to what extent is your code free of bugs? The real difference here is the complexity of the problem you have chosen to solve and how well you solved it. 

Our Big idea

The big idea for today is Programming.

The essential questions for this topic are:

How do we plan, write, execute, and test instructions a computer can understand and process?

It takes time to explore and really understand a big idea. If you want to
learn more about programming (which is connected to today's daily note), please click here .

We are learning this because as a designers must understand scientific and technical innovation. Designers use systems, models, methods, and processes to solve problems.



Reminders & routines:

Please read and follow these reminders:

  1. IF today ==  testing_day_for_me:
         remember to go get tested!
     
  2. IF today == Friday:
         current_event_activity()