-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreasure_hunt.py
99 lines (77 loc) · 3.79 KB
/
treasure_hunt.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
"""A CLI-based Treasure Hunt game."""
ASCII_TREASURE_ART = '''
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."'` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
'''
def choose_colours() -> None:
"""Asks the player to pick a door colour."""
print("\n\nYou arrive at the island unharmed. There is a house "
"with 3 doors of different colours.")
print(
"\nDoor Colours:\033[91m Red\033[0m,\033[93m Yellow\033[0m,\033[94m Blue\033[0m")
colours = ["red", "yellow", "blue"]
while True:
colour_choice = input("\nChoose a colour: ").lower()
if colour_choice in colours[:1]:
print("\nIt's a room full of fire. Game Over.\n")
break
if colour_choice in colours[:2]:
print("\nYou found the treasure! You Win!\n")
break
if colour_choice in colours[-1]:
print("\nYou enter a room of beasts. Game Over.\n")
break
print("\nRed, Yellow, and Blue Only!")
def ask_wait_or_swim() -> None:
"""Asks the player to choose to wait or swim."""
print("\n\nYou've come to a lake. There is an island in the middle of the lake.")
print(
"\nType\033[1m 'wait'\033[0m to wait for a boat. Type\033[1m 'swim'\033[0m to swim across.")
while True:
wait_or_swim = input("\nWait or Swim: ").lower()
if wait_or_swim == "swim":
print("\nYou get attacked by an angry trout. Game Over.\n")
break
if wait_or_swim == "wait":
choose_colours()
break
print("\nWait or Swim Only!")
def ask_left_right() -> None:
"""Asks the player to choose left or right."""
while True:
print("\n\nYou are at a cross road, and you can only go "
"left or right. Where do you want to go?")
left_or_right = input("\nLeft / Right: ").lower()
if left_or_right == "right":
print("\nYou fell into a hole. Game Over.\n")
break
if left_or_right == "left":
ask_wait_or_swim()
break
print("\nLeft or Right Only!")
def play_game():
"""Start the game."""
print(ASCII_TREASURE_ART)
print("\nWelcome to Treasure Island.")
print("\nYour mission is to find the treasure.")
ask_left_right()
if __name__ == "__main__":
play_game()