-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileTraveller.py
108 lines (84 loc) · 2.85 KB
/
TileTraveller.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# https://github.com/omarbessi04/TileTraveller
# 1. Create functions to move player and check for directions
# 2. Prompt player with input
# 3. Move player based on input OR don't
# 4. Once player has reached goal, end program
#functions that move player
def goNorth():
global y, coordinates_of_player
y += 1
coordinates_of_player = [x,y]
def goSouth():
global y, coordinates_of_player
y -= 1
coordinates_of_player = [x,y]
def goEast():
global x, coordinates_of_player
x += 1
coordinates_of_player = [x,y]
def goWest():
global x, coordinates_of_player
x -= 1
coordinates_of_player = [x,y]
def Check_Valid_Directions():
for i in range(len(directions)):
if coordinates_of_player in (directions)[i]:
if (directions)[i] == directions[0]:
Valid_directions.append("(N)orth")
if (directions)[i] == directions[1]:
Valid_directions.append("(E)ast")
if (directions)[i] == directions[2]:
Valid_directions.append("(S)outh")
if (directions)[i] == directions[3]:
Valid_directions.append("(W)est")
x = 1
y = 1
coordinates_of_player = [x,y]
Invalid_direction = True
#list of all the tiles that are available, N, E, S, W
directions = [[[1,1], [1,2], [2,1], [3,1], [3,2]],
[[1,3], [1,2], [2,3]],
[[1,2], [1,3], [2,2], [3,3], [3,2]],
[[3,3], [2,3], [2,2]]]
Valid_directions = []
Check_Valid_Directions()
print("You can travel: ", " or ".join(Valid_directions), end=".\n")
while coordinates_of_player != [3, 1]:
Valid_directions = []
Check_Valid_Directions()
player_move = input("Direction: ")
if player_move.lower() == "n":
if "(N)orth" in Valid_directions:
goNorth()
Invalid_direction = False
else:
Invalid_direction = True
elif player_move.lower() == "s":
if "(S)outh" in Valid_directions:
goSouth()
Invalid_direction = False
else:
Invalid_direction = True
elif player_move.lower() == "e":
if "(E)ast" in Valid_directions:
goEast()
Invalid_direction = False
else:
Invalid_direction = True
elif player_move.lower() == "w":
if "(W)est" in Valid_directions:
goWest()
Invalid_direction = False
else:
Invalid_direction = True
if Invalid_direction:
print("Not a valid direction!")
Valid_directions = []
Check_Valid_Directions()
print("You can travel: ", " or ".join(Valid_directions), end=".\n")
else:
if coordinates_of_player != [3,1]:
Valid_directions = []
Check_Valid_Directions()
print("You can travel: ", " or ".join(Valid_directions), end=".\n")
print("Victory!")