generated from mwc/lab_retro
24 lines
727 B
Python
24 lines
727 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):
|
|
if game.turn_number % 2 == 0:
|
|
x, y = self.position
|
|
if y == 25 - 1:
|
|
# if y == HEIGHT - 1: <--I got a height is not defined error
|
|
game.remove_agent_by_name(self.name)
|
|
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 |