forked from BradleyCodeU/lab-rats-the-avenger-comixs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
191 lines (168 loc) · 9.95 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from room import Room
from flashlight import Flashlight
from character import Enemy
from container import Container
heldItems = []
myHealth = 53
visitedRooms = []
# ********************************* SET UP THE ROOMS *********************************
# Kitchen
#
# Room descriptions should include interactive containers like CABINET, BIN, DESK, SHELF, SHOEBOX that contain/hide other interactive items
kitchen = Room("Kitchen","A dark and dirty room with flies buzzing around. There are dirty beakers, graduated cylinders, and pipettes in the sink. There is a CUPBOARD above the sink and a CABINET under the sink.")
# The kitchen has a CUPBOARD object that contains/hides 3 interactive items, a sponge, a plate, a can of soup
# Once this container is open, the interactive items will no longer be hidden in the container
kitchen.cupboard = Container("cupboard above the sink",["sponge","plate","can of "+u'\u0411\u043E\u0440\u0449'+" soup"])
# The kitchen has a CABINET object that contains/hides 2 interactive items, a knife and a twinkie
# Once this container is open, the interactive items will no longer be hidden in the container
kitchen.cabinet = Container("cabinet under the sink",["knife","twinkie"])
# Create an interactive item that's show in a room (not hidden in a container) with create_room_item()
kitchen.create_room_item("spoon")
kitchen.create_room_item("rat")
# Library
#
library=Room("Library","It's a mysterious place very dark and very quiet. You see a DESK as well as a SHELF.")
#Library has a DESK that contains/hides 2 items, a key, and a quarter
library.desk=Container("inside the desk.",["key","quarter"])
library.shelf=Container("on the shelf.",["Sniper","can"])
library.create_room_item("rat")
library.create_room_item("fork")
# Small Office
#
smalloffice = Room("Small Office","A dark room with a mess of books and papers covering the desk. There is some mail and an ozon.ru PACKAGE. You can READ a book. You can look in the DESK.")
smalloffice.desk = Container("desk",["battery","envelope"])
smalloffice.package = Container("ozon.ru package",["sheet of bubble wrap","porcelain figurine of a bear","red flashlight"])
smalloffice.create_room_item("guinea pig")
redFlashlight = Flashlight("red",0,False)
# Laboratory
#
lab = Room("Laboratory","A bright room with sunlight shining through windows secured by prison bars. There is a messy SHELF on the north wall.")
# The lab has a SHELF object that contains 3 interactive items. Shelf gets a third argument because you'd say ON the shelf, not IN the shelf
lab.shelf = Container("shelf",["brass key","spork","yellow flashlight"],"on")
lab.create_room_item("rat")
yellowFlashlight = Flashlight("yellow",1,True)
# Supply Closet
#
supplycloset = Room("Supply Closet","A small dark room with a musty smell. On one side is a filing CABINET and a large plastic BIN. On the other side is a SHELF with supplies and a SHOEBOX.")
# Create a fake room called locked that represents all permenently locked doors
#
locked = Room("locked","")
# Connect rooms. These are one-way connections.
kitchen.link_room(library, "EAST")
kitchen.link_room(smalloffice, "SOUTH")
kitchen.link_room(locked, "WEST")
supplycloset.link_room(smalloffice, "EAST")
smalloffice.link_room(kitchen, "NORTH")
smalloffice.link_room(lab, "EAST")
smalloffice.link_room(locked, "SOUTH")
smalloffice.link_room(supplycloset, "WEST")
lab.link_room(locked, "SOUTH")
lab.link_room(smalloffice, "WEST")
library.link_room(kitchen, "WEST")
current_room = kitchen
# Set up characters
dmitry = Enemy("Dmitry", "A smelly zombie")
dmitry.set_speech("Brrlgrh... rgrhl... brains...")
dmitry.set_weaknesses(["FORK","SPORK","KNIFE"])
supplycloset.set_character(dmitry)
# This is a procedure that simply prints the items the player is holding and tells them if they can do something with that item
def playerItems():
# Print out the player's Held Items and let player know if they can USE an item to fight a character or something
if len(heldItems) == 1:
print("You are holding a "+heldItems[0])
print("You can DROP "+heldItems[0].upper())
if current_room.character is not None:
print("You can USE "+heldItems[0].upper()+" to fight "+current_room.character.name)
elif len(heldItems) >= 2:
print("Your hands are full. You must drop something before you can pick anything else up.")
print("You are holding a "+heldItems[0]+" and a "+heldItems[1])
print("You can DROP "+heldItems[0].upper()+" or DROP "+heldItems[1].upper())
if current_room.character is not None:
print("You can USE "+heldItems[0].upper()+" to fight "+current_room.character.name+" or USE "+heldItems[1].upper())
# ********************************* SPECIAL ITEM INTERFACES *********************************
# If holding a special item, then display the item's interface with get_interface()
if "red flashlight" in heldItems:
redFlashlight.get_interface(heldItems,current_room)
if "yellow flashlight" in heldItems:
yellowFlashlight.get_interface(heldItems,current_room)
# This fuction checks the player's command and then runs the corresponding method
def checkUserInput(current_room,command,heldItems):
# Convert it to ALL CAPS
command = command.upper()
# All possible user input commands go here
print("\n")
# ********************************* SPECIAL USER INPUT *********************************
# If holding a special item, then check for that item's UI keywords with check_input()
if "red flashlight" in heldItems and "RED FLASHLIGHT" in command:
redFlashlight.check_input(command,heldItems,current_room)
elif "yellow flashlight" in heldItems and "YELLOW FLASHLIGHT" in command:
yellowFlashlight.check_input(command,heldItems,current_room)
# ********************************* USE, TAKE, DROP *********************************
# Use an item to fight an enemy
elif "USE " in command and current_room.get_character() is not None:
# command[4:] is used to get the characters typed after "USE "
enemyHealth = current_room.character.fight(command[4:])
if enemyHealth < 1:
print(current_room.character.name+" is dead")
current_room.remove_character() # If the enemy is dead, then remove them from the room
# Take lets you pick up an item
elif "TAKE " in command:
# command[5:] is used to get the characters typed after "TAKE "
heldItems = current_room.take_room_item(command[5:],heldItems)
# Drop lets you set down an item
elif "DROP " in command:
# command[5:] is used to get the characters typed after "DROP "
heldItems = current_room.add_room_item(command[5:],heldItems)
# Talk and Fight aren't currently used in this version of the game, but could be implemented in your version of the game
elif "TALK" in command and current_room.get_character() is not None:
current_room.character.talk()
elif "FIGHT" in command and current_room.get_character() is not None:
current_room.character.talk()
# ********************************* ROOM SPECIFIC USER INPUTS *********************************
# Interactive containers look like this... elif current_room.name == "Laboratory" and command == "SHELF"
elif current_room.name == "Kitchen" and command == "CUPBOARD":
# Open kitchen.cupboard and concat each of the contents to the end of room_items
current_room.room_items += kitchen.cupboard.open()
# Can only open cabinet if holding a flashlight that isOn
elif current_room.name == "Kitchen" and command == "CABINET" and (("red flashlight" in heldItems and redFlashlight.isOn) or ("yellow flashlight" in heldItems and yellowFlashlight.isOn)):
# Open kitchen.cabinet and concat each of the contents to the end of room_items
print("You use the flashlight to look inside the cabinet.")
current_room.room_items += kitchen.cabinet.open()
elif current_room.name == "Kitchen" and command == "CABINET":
print("You check the cabinet, but it's too dark to see if there is anything inside.")
elif current_room.name == "Small Office" and command == "PACKAGE":
# Open smalloffice.desk and concat each of the contents to the end of room_items
current_room.room_items += smalloffice.package.open()
elif current_room.name == "Small Office" and command == "READ":
print(u'\u0420\u043e\u0441\u0441\u0438\u044f\u262D'+" You can't read it. It's written is some strange Cyrillic script.")
elif current_room.name == "Small Office" and command == "DESK" and "brass key" in heldItems:
# Open smalloffice.desk and concat each of the contents to the end of room_items
print("You use the brass key to unlock the desk.")
current_room.room_items += smalloffice.desk.open()
elif current_room.name == "Small Office" and command == "DESK":
print("The desk drawer is locked.")
elif current_room.name == "Laboratory" and command == "SHELF":
# Open lab.shelf and concat each of the contents to the end of room_items
current_room.room_items += lab.shelf.open()
elif current_room.name == "Library" and command == "DESK":
current_room.room_items += library.desk.open()
elif current_room.name == "Library" and command == "SHELF":
current_room.room_items += library.shelf.open()
# ********************************* MOVE *********************************
else:
current_room = current_room.move(command,visitedRooms) # If it was none of those commands, assume it was a direction. Try to move.
return current_room
#THE LOOP
while True:
print("\n")
# Print current room info
myHealth = current_room.info(heldItems,myHealth,visitedRooms) # this returns myHealth cuz an enemy in the room could hurt you
if myHealth <= 0:
print("You died.\nGAME OVER")
break
# Print player items
playerItems()
# Get user input
command = input("> ")
# Check the user input
current_room = checkUserInput(current_room,command,heldItems)