Files
lab_retro/asteroid.py
caglazir 9a4ef2eb8d This program differed from Unit 1 programs because
it felt more foreign, if that makes sense. The code used in this program
was not my work hence, I did not feel as though I completely understood how
each agent was doing what it was doing. I guess I can see the value of
agents because they really do cut things short and functional. But I much
prefer the labs and programs that had more original input for the learning
experience! At this stage I don't know if I am comfortable or confident going
into the game project but I will try to think more about the agents
to understand better.
2025-12-01 21:31:36 -05:00

23 lines
684 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):
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