generated from mwc/project_game
A recent success that I am proud of is that I was able to give the player the ability to move up, down, left, and right. When implementing the ability to move up and down it seemed that the code was opposite of what I expected it to be. I was able to figure out how to implement it the correct way.
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
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
|
|
|
|
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 |