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 #here