generated from mwc/project_game
I used AI to help me through some issues, but all the coding I understood and worked through and typed on my own I learned a lot about the structure and when AI would suggest something I could be like thats now going to solve my issue I need to do this which felt very motivating
37 lines
962 B
Python
37 lines
962 B
Python
class Obstacle:
|
|
character = 'O'
|
|
|
|
def __init__(self, position):
|
|
self.position = position
|
|
|
|
|
|
def handle_keystroke(self, keystroke, game):
|
|
froggy = game.get_agent_by_name('froggy')
|
|
if keystroke.name != "KEY_UP":
|
|
return
|
|
_, height = game.board_size
|
|
x, y =self.position
|
|
if y == height -1:
|
|
game.remove_agent(self)
|
|
return
|
|
new_position = (x,y + 1)
|
|
if new_position == froggy.position:
|
|
game.end()
|
|
return
|
|
if game.on_board(new_position) and game.is_empty(new_position):
|
|
self.position = new_position
|
|
|
|
def play_turn(self, game):
|
|
width, height = game.board_size
|
|
if game.turn_number % 2 == 0:
|
|
x, y = self.position
|
|
if y >= height:
|
|
game.remove_agent(self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|