generated from mwc/project_game
I am getting very close to finishing the project. I was having a problem where I made the symbol for the cars 'OO' and only one of the 'O' was leaving the screen when it made it to the far right of the screen. I emailed you and you said to only make the symbol 'O' and spawn 2 right next to each other. I figured out how to do this by myself but am now trying to figure out why they are breaking apart.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
class Car:
|
|
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 = 3
|
|
width, height = game.board_size
|
|
if game.turn_number: #% 3 == 0:
|
|
x, y = self.position
|
|
if x == width - 1:
|
|
game.remove_agent(self)
|
|
else:
|
|
person = game.get_agent_by_name('person')
|
|
new_position = (x+1, y)
|
|
|
|
# if game.turn_number % 2 == 1:
|
|
# x, y = self.position
|
|
#if x == width - 1:
|
|
# game.remove_agent(self)
|
|
# else:
|
|
# person = game.get_agent_by_name('person')
|
|
# new_position = (x-1, y)
|
|
|
|
|
|
|
|
|
|
if new_position == person.position:
|
|
lives = lives-1
|
|
game.state["lives"] -=1
|
|
if game.state["lives"] == 0:
|
|
game.end()
|
|
else:
|
|
self.position = new_position |