This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtileTraveller4.py
119 lines (101 loc) · 2.7 KB
/
tileTraveller4.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
109
110
111
112
113
114
115
116
117
118
119
def getDirections(x, y):
''' Returns the directions one could travel in from x, y according to the diagram '''
n = True
s = True
e = True
w = True
#check borders
if y == 3:
n = False
elif y == 1:
s = False
if x == 1:
w = False
elif x == 3:
e = False
#check walls
if y == 1:
e = False
w = False
elif x == 2 and y == 2:
n = False
e = False
elif x == 3 and y == 2:
w = False
elif x == 2 and y == 3:
s = False
return n, e, s, w
def printAvailableDirections(x, y):
''' Prints the directions one could travel in from x, y '''
n, e, s, w = getDirections(x, y)
print("You can travel:", end=" ")
if n:
print("(N)orth", end="")
if e or w or s:
print(" or", end=" ")
if e:
print("(E)ast", end="")
if w or s:
print(" or", end=" ")
if s:
print("(S)outh", end="")
if w:
print(" or", end=" ")
if w:
print("(W)est", end="")
print(".")
def getValidInput(x, y):
''' Returns a user inputted direction that one could travel in from x, y '''
n, e, s, w = getDirections(x, y)
while True:
direction = input("Direction: ").upper()
if direction == "N" and n:
break
elif direction == "E" and e:
break
elif direction == "S" and s:
break
elif direction == "W" and w:
break
print("Not a valid direction!")
return direction
def movePlayer(x, y, direction):
''' Returns the moved x, y coordinates according to the direction '''
if direction == "N":
y += 1
elif direction == "E":
x += 1
elif direction == "S":
y -= 1
elif direction == "W":
x -= 1
return x, y
def isLeverTile(x, y):
''' Returns wether the x, y tile is a lever tile or not'''
if y == 2 or (x == 2 and y == 3):
return True
else:
return False
def leverPull(coins):
''' Promts player to pull the lever, if they do 1 is added to their coin total. '''
answer = input("Pull a lever (y/n): ")
if answer.lower() == "y":
coins += 1
print("You received 1 coins, your total is now {}.".format(coins))
return coins
def play():
coins = 0
x, y = 1, 1
while not (x == 3 and y == 1):
if isLeverTile(x, y):
coins = leverPull(coins)
printAvailableDirections(x, y)
direction = getValidInput(x, y)
x, y = movePlayer(x, y, direction)
print("Victory!")
def main():
cont = "y"
while cont == "y":
play()
cont = input("Play again (y/n): ").lower()
main()