-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreasurehunt.py
More file actions
45 lines (40 loc) · 1.18 KB
/
Copy pathtreasurehunt.py
File metadata and controls
45 lines (40 loc) · 1.18 KB
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
import random
grid = []
def griddisign(x, y):
for r in range(x):
row = []
for c in range(y):
row.append("__")
grid.append(row)
return grid
def placetreasure(x, y):
row = random.randint(0, y-1)
col = random.randint(0, x-1)
return row, col
def give_hint(gx, gy, tx, ty):
if gy < ty:
return "Move down"
elif gy > ty:
return "Move up"
elif gx < tx:
return "Move right"
elif gx > tx:
return "Move left"
else:
return "Congatulations! You have found the treasure! We're rich!"
def treasure_hunt():
grid = griddisign(5, 5)
ty, tx = placetreasure(5, 5)
print("There is a treasure hidden here... Find it and you're RICH!")
while True:
for r in grid:
print(" ".join(r))
gy = int(input("Enter row number (0-4): "))
gx = int(input("Enter col number (0-4): "))
if (gx == tx) and (gy == ty):
print("Congatulations! You have found the treasure! We're rich!")
break
else:
hint = give_hint(gx, gy, tx, ty)
print(hint)
treasure_hunt()