generated from mwc/project_game
I'm proud of making the circles fall from the top one at a time. I was stuck on making the circle fall.
26 lines
847 B
Python
26 lines
847 B
Python
class Player:
|
|
name = "player"
|
|
character = '^'
|
|
|
|
def __init__(self, board_size):
|
|
board_width, board_height = board_size
|
|
self.position = (board_width // 2, board_height - 1)
|
|
|
|
def handle_keystroke(self, keystroke, game):
|
|
x, y = self.position
|
|
if keystroke.name == "KEY_LEFT":
|
|
new_position = (x - 1, y)
|
|
elif keystroke.name == "KEY_RIGHT":
|
|
new_position = (x + 1, y)
|
|
elif keystroke.name == "KEY_UP":
|
|
new_position = (x, y - 1)
|
|
elif keystroke.name == "KEY_DOWN":
|
|
new_position = (x, y + 1)
|
|
else:
|
|
return
|
|
if game.on_board(new_position):
|
|
if game.is_empty(new_position):
|
|
self.position = new_position
|
|
else:
|
|
game.end()
|