-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
109 lines (99 loc) · 4.83 KB
/
main.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
#!/usr/bin/env python3.10
from subprocess import run
from random import randint, choice
from time import sleep
from rooms import getRooms
import stats
run("clear")
def intro(stats):
input("Welcome to 'Hunt the Wumpus!' (hit enter to continue)")
input("\nYou have chosen to hunt the evil Wumpus. The Wumpus lives in a cave made up of a maze of 20 rooms.\nEach room has three tunnels connecting to another room.")
input("\nBut be careful! There are known to be drafty bottomless pits in this cave, and rustling super bats that might carry you off into the cave.")
input("\nThankfully, you are armed with your trusty bow and five (5) crooked arrows. All you have to do is aim the arrow into a room, and it will fly crooked and true through the other rooms.")
print("\nGood luck!")
sleep(2)
run("clear")
main(stats)
def main(stats):
while True:
if stats.wumpus == stats.player:
print("\nThe Wumpus got you!!")
break
if stats.bottomlessPit1 == stats.player or stats.bottomlessPit2 == stats.player:
print("You fall into a bottomless pit.")
break
if stats.superBat1 == stats.player:
print("You startle a super bat. It picks you up, carries you to a random room, then drops you there and flies off.")
stats.player = randint(1, 20)
stats.superBat1 = randint(1, 20)
elif stats.superBat2 == stats.player:
print("You startle a super bat. It picks you up, carries you to a random room, then drops you there and flies off.")
stats.player = randint(1, 20)
stats.superBat2 = randint(1, 20)
print("\nYou are in room {}. The tunnels branching off go to rooms {}, {}, and {}.".format(stats.player, getRooms(stats.player)[0], getRooms(stats.player)[1], getRooms(stats.player)[2]))
if stats.superBat1 in getRooms(stats.player) or stats.superBat2 in getRooms(stats.player):
print(" I hear a bat.")
if stats.bottomlessPit1 in getRooms(stats.player) or stats.bottomlessPit2 in getRooms(stats.player):
print(" I feel a draft.")
if stats.wumpus in getRooms(stats.player):
print(" I smell a wumpus.")
result = input("\nShoot or Move? [S-M] ")
if result.upper() == "M":
while True:
try:
result = int(input("Which room? [{}, {}, {}] ".format(getRooms(stats.player)[0], getRooms(stats.player)[1], getRooms(stats.player)[2])))
assert result in getRooms(stats.player)
break
except:
print("Nope.")
stats.player = result
continue
elif result.upper() == "S":
shoot(stats)
def shoot(stats):
if stats.crookedArrows != 0:
while True:
try:
distance = int(input("How far do you want to shoot the arrow? [1-5] "))
assert 0 < distance < 6
break
except:
print("\nPlease. Did you really think that would work?\n")
continue
while True:
try:
direction = int(input("Which room do you want to shoot the crooked arrow into? [{}, {}, {}] ".format(getRooms(stats.player)[0], getRooms(stats.player)[1], getRooms(stats.player)[2])))
break
except:
print("\nWhy are you still trying this? I might sic the wumpus on you.\n")
continue
if direction not in getRooms(stats.player):
direction = choice(getRooms(stats.player))
for i in range(0, distance):
if i == 0:
arrow = direction
cameFrom = stats.player
print(" Your arrow flies into room {}.".format(direction))
else:
while True:
num = choice(getRooms(arrow))
if num == cameFrom: #Don't allow the arrow to turn right around and skewer you.
continue
else:
arrow = num
break
print(" Your arrow flies into the next room.")
if arrow == stats.player:
print("Your stinkin' crooked arrow flew back and hit you.")
quit()
if arrow == stats.wumpus:
print("\nAHA! You got the wumpus!\nHEE HEE HEE - The Wumpus'll get you next time!!")
quit()
sleep(0.4)
print("You missed, you are now minus one arrow, plus you startled the Wumpus.")
stats.crookedArrows -= 1
stats.wumpus = choice(getRooms(stats.wumpus))
return
print(choice(["Sorry buster. You used up all off your crooked arrows.", "Sorry charlie. You're empty."]))
if __name__ == "__main__":
intro(stats)