-
Notifications
You must be signed in to change notification settings - Fork 0
/
brad_lab11.py
104 lines (80 loc) · 3.1 KB
/
brad_lab11.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
class Item:
name = None
action = None
def __init__(self, name, action):
self.name = name
self.action = action
def getName(self):
return self.name
def getAction(self):
return self.action
class Player:
knapsack = [];
def pickUp(self, item):
self.knapsack.append(item)
def hasItem(self, item):
for item in self.knapsack:
if item.getName() == name:
return True
return False
def discardItem(self, item):
count = 0
for item in self.knapsack:
if item.getName() == name:
self.knapsack.pop(count)
count = count + 1
def useItem(self, item):
for item in self.knapsack:
if item.getName() == name:
return item.getAction()
def listItems(self):
for item in self.knapsack:
printNow(item.getName() + ", cabability: " + item.getAction())
def welcome():
printNow("Hello. Welcome to the Winchester Mystery House.")
printNow("Each time you enter a new room you will be facing north.")
printNow("Find your way to the staircase that leads to the second floor, and you will have won the game.")
printNow("At any time you may type exit to end the game")
printNow("When requested, type the direction you would like to go.")
printNow("To see this message again type help anytime.")
return
def entry():
player = Player()
welcome()
printNow("You are now in the entryway")
printNow("You may enter the house by going north.")
direction = requestString("Which direction would you like to go: ")
while direction.lower() != "north" and direction.lower() != "exit" and direction.lower() != "help":
direction = requestString("Please enter a valid direction: ")
if direction.lower() == "help":
welcome()
if direction.lower() == "north":
grandFoyer(player)
elif direction.lower() == "exit":
sys.exit("Goodbye. Thank you for playing.")
def grandFoyer(player):
key = Item('key', 'unlock')
printNow("You have entered the Grand Foyer.")
printNow("On a small table in the Foyer, you see a tiny golden key.")
printNow("You may go north into the Middle Hallway, west into the Library, east into the Art Gallery, south to exit the House, or you may 'pick up the key'.")
direction = requestString("What would you like to do: ")
while direction.lower() != "north" and direction.lower() != "east" and direction.lower() != "west" and direction.lower() != "south" and direction.lower() != "pick up the key" and direction.lower() != "exit" and direction.lower() != "help":
direction = requestString("Please enter a valid direction: ")
if direction.lower() == "help":
welcome()
if direction.lower() == "north":
middleHallway()
elif direction.lower() == "east":
artGallery()
elif direction.lower() == "west":
library()
elif direction.lower() == "south":
entry()
elif direction.lower() == "pick up the key":
player.pickUp(key)
printNow("You have picked up the key")
printNow("You now have:")
printNow(player.listItems())
elif direction.lower() == "exit":
sys.exit("Goodbye. Thank you for playing.")
entry()