asteroid.py asteroid_spawner.py spaceship.py nav_game.py

This commit is contained in:
njmason2
2025-11-14 00:29:44 -05:00
parent 5356f5076b
commit 24476f3bed
8 changed files with 79 additions and 0 deletions

View File

@@ -2,3 +2,26 @@
# ------------
# By MWC Contributors
# This module defines an asteroid agent class.
class Asteroid:
character = 'O'
color="orange" # color added
def __init__(self, position):
self.position = position
def play_turn(self, game):
width, height = game.board_size
if game.turn_number % 2 == 0:
x, y = self.position
if y == height - 1:
game.remove_agent(self)
else:
ship = game.get_agent_by_name('ship')
new_position = (x, y + 1)
if new_position == ship.position: # Watch Out!
ship.character="*" # changed to a collision indicator
ship.color="red" # changed to a collision indicator
game.end()
else:
self.position = new_position