-
Notifications
You must be signed in to change notification settings - Fork 0
/
human_play.py
61 lines (49 loc) · 1.2 KB
/
human_play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from game import Game
# Define Constants
LEFT = 0
UP = 1
RIGHT = 2
DOWN = 3
# Create game object (from game.py)
game = Game()
# Run the game until game over
while not game.gameOver:
# Display the board
game.display()
# Prompt for user input
print("Possible inputs:")
print("w, a, s, d")
print("vim shortcuts")
print("arrow keys")
print("or q to quit")
print()
choice = input("Input: ")
# If user chooses left...
if choice in ["a", "^[[D", "h"]:
# Move left
game.move(LEFT)
# If user chooses right...
elif choice in ["d", "\x1b[D", "l"]:
# Move right
game.move(RIGHT)
# If user chooses up...
elif choice in ["w", "\x1b[A", "k"]:
# Move up
game.move(UP)
# If user chooses down...
elif choice in ["s", "\x1b[B", "j"]:
# Move down
game.move(DOWN)
# If user chooses to quit
elif choice == "q":
# Set gameOver to True
game.gameOver = True
# Otherwise...
else:
print("That wasn't a choice")
# Check for game over sequence
if game.gameOver:
game.display()
game.update_high_score()
print("Game Over.")
print()