I did not realize this had to be three submissions. My first progress was the add lives to the asteroid game.

For this feature, I added a health system so the player has three
lives instead of losing instantly. In nav_game.py, I added "health": 3
to the game state, and in spaceship.py I created a take_damage method
that subtracts one life when the ship is hit. If the player's health
reaches zero, the game ends. This change is important because it
makes the game less punishing, gives the player more chances to
recover from mistakes, and makes gameplay feel more balanced and fun.
This commit is contained in:
angelotr
2025-12-08 23:39:17 -05:00
parent 3816c0bac0
commit 47a9e1abe3
9 changed files with 179 additions and 0 deletions

31
bullet.py Normal file
View File

@@ -0,0 +1,31 @@
from asteroid import Asteroid
class Bullet:
"""A bullet fired by the spaceship that moves upward and destroys asteroids."""
character = '|'
def __init__(self, position):
self.position = position
def play_turn(self, game):
# Move bullet up one row each turn
x, y = self.position
y -= 1
# If the bullet goes off the top, remove it
if y < 0:
game.remove_agent(self)
return
self.position = (x, y)
# Check if we hit an asteroid
# We loop over a copy of the agents list because we may remove agents
for agent in list(game.agents):
if isinstance(agent, Asteroid) and agent.position == self.position:
# Destroy the asteroid and the bullet
game.remove_agent(agent)
game.remove_agent(self)
# Reward points for hitting an asteroid
game.state["score"] += 10
return