wrote code in asteroid.py, asteroid_spawner.py, spaceship.py, and nav_game.py in order to create an interactive game where the spaceship (player) must avoid incoming asteroids

This commit is contained in:
kated
2026-05-12 10:59:35 -04:00
parent b2457e7525
commit 5c5883ec33
9 changed files with 149 additions and 0 deletions

View File

@@ -2,3 +2,23 @@
# ------------
# By MWC Contributors
# This module defines an asteroid agent class.
class Asteroid:
character = "0"
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:
game.end()
else:
self.position = new_position