Files
lab_retro/asteroid.py

27 lines
835 B
Python

# asteroid.py
# ------------
# By MWC Contributors
# This module defines an asteroid agent class.
class Asteroid:
character = 'O'
def __init__(self, position):
self.position = position
def play_turn(self, game):
lives = 5
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:
lives = lives-1
game.state["lives"] -=1
if game.state["lives"] == 0:
game.end()
else:
self.position = new_position