generated from mwc/project_game
At first it was tough for me to figure out how to get the cars to move from left to right. I was able to figure this out by emailing you and also thinking about where it was telling the cars to spawn in the retro lab and changing that part of the code. I had to change a few lines of code where it used the height parameter and changed it to width. I was able to overcome this by thinking about what each individual line of code did and what I needed to change to fix it. I have gotten a lot better at debugging code and understanding what each line of code is doing throughout the semester. I would tell a future student to really think about what each line of code is doing and try to follow along and you should find many of your mistakes.
24 lines
923 B
Python
24 lines
923 B
Python
class Person:
|
|
name = "person"
|
|
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 in ("KEY_LEFT", "KEY_RIGHT","KEY_UP", "KEY_DOWN"):
|
|
if keystroke.name == "KEY_LEFT":
|
|
new_position = (x - 1, y)
|
|
if keystroke.name == "KEY_RIGHT":
|
|
new_position = (x + 1, y)
|
|
if keystroke.name == "KEY_UP":
|
|
new_position = (x, y - 1)
|
|
if keystroke.name == "KEY_DOWN":
|
|
new_position = (x, y + 1)
|
|
if game.on_board(new_position):
|
|
if game.is_empty(new_position):
|
|
self.position = new_position
|
|
else:
|
|
game.end() |