Repository navigation
Expand file tree
/
Copy pathadv.py
More file actions
181 lines (158 loc) · 7.2 KB
/
Copy pathadv.py
File metadata and controls
181 lines (158 loc) · 7.2 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
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
from room import Room
from player import Player
from item import Item
from item import Septre
from item import GoldCoins
from item import HolyGrail
from item import Map
# Declare all the rooms
room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons", []),
'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", [
Septre(
'Septre',
'The septre of the king that could make any one invincible',
'Gold')]),
'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""", [
Map('Map', 'Helps you find your way to the treasure',
'Medieval times'),
GoldCoins('GoldCoins', 'Hidden in the overlook! Find it.',
'Millions')
]),
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", [
HolyGrail('HolyGrail',
'Everybody thinks its in the treasure chamber',
'You will become the know-it-all developer!!')
]),
'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south.""", [
Item('Book', 'Python for dummies')
]),
}
# Link rooms together
room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
#
# Main
#
# Make a new player object that is currently in the 'outside' room.
player_name = input('\nPlease input your name to start the game: ')
if (len(player_name) == 0 or len(player_name.strip()) == 0):
player_name = 'Anonymous'
np = Player(player_name, [])
print(f"\nLet's start playing, {player_name}! Good Luck :)")
# Write a loop that:
#
# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
# * Waits for user input and decides what to do.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
is_done_playing = False
def possible_rooms(current_room):
input_str = "You can choose one of following room(s) to move - \n"
if (current_room == 'outside'):
input_str += "\n(n)orth to Foyer"
elif (current_room == 'foyer'):
input_str += "\n(n)orth to overlook\n(s)outh to outside"
input_str += "\n(e)ast to narrow"
elif (current_room == 'overlook'):
input_str += "\n(s)outh to foyer"
elif (current_room == 'narrow'):
input_str += "\n(w)est to foyer\n(n)orth to treasure"
elif (current_room == 'treasure'):
input_str += "\n(s)outh to narrow"
if (len(room[np.current_room].items)) > 0:
input_str += f"\n(g)et items - {room[np.current_room].items}"
if (len(np.items) > 0):
input_str += f"\n(d)rop items - {np.items}"
input_str += "\n(i)nventory of items avaialable with you currently"
return input_str+"\n(q)uit to end game\n\nEnter your input:"
while (is_done_playing is False):
print("\n----------------------------------------------------------------")
print(f"\n{np.name}, u r currently in {room[np.current_room].name}")
print(f"\n{room[np.current_room].description}")
if len(room[np.current_room].items) > 0:
print(f"\nItems in room: {room[np.current_room].items}")
else:
print("\nThere is currently, no items in this room.")
print("\n----------------------------------------------------------------")
input_str = possible_rooms(np.current_room)
user_input = input(f"\n{input_str}")
if (len(user_input) == 0 or len(user_input.strip()) == 0):
user_input = 'q'
else:
user_input = user_input.lower().strip()[0]
if (user_input.lower() == 'q' or len(user_input) == 0
or len(user_input.strip()) == 0):
is_done_playing = True
break
elif (user_input.lower() == 'i'):
if len(np.items) > 0:
print("\n********** ITEMS AVAILABLE WITH YOU CURRENTLY **********")
for item in np.items:
print(f"\n{item.name} :: {item.description}")
else:
print("\n** NO ITEMS AVAIALBLE IN YOUR INVENTORY CURRENTLY **")
elif (user_input.lower() == 'n'
and hasattr(room[np.current_room], "n_to")):
np.set_current_room(((room[np.current_room].n_to).name)
.lower().partition(' ')[0])
elif (user_input.lower() == 's'
and hasattr(room[np.current_room], "s_to")):
np.set_current_room(((room[np.current_room].s_to).name).lower()
.partition(' ')[0])
if (np.current_room == 'outside' and np.items[0].name == 'Book'):
print("\n*****************************************************\n")
print("\n***YOU HAVE WON THE GAME!! NOW GO READ THE BOOK :)***\n")
print("\n*****************************************************\n")
break
elif (user_input.lower() == 'e'
and hasattr(room[np.current_room], "e_to")):
np.set_current_room(((room[np.current_room].e_to).name).lower()
.partition(' ')[0])
elif (user_input.lower() == 'w'
and hasattr(room[np.current_room], "w_to")):
np.set_current_room(((room[np.current_room].w_to).name).lower()
.partition(' ')[0])
elif (user_input.lower() == 'g'):
is_item_moved = False
item_taken = input('\nEnter the name of the item to take from room: ')
for item in room[np.current_room].items:
if (item.name.lower() == item_taken.lower().strip()):
is_item_moved = True
np.add_item(item)
room[np.current_room].remove_items(item_taken)
item.take_item()
if is_item_moved is False:
print('\n The item selected, is not available in the room to take')
elif (user_input.lower() == 'd'):
is_item_moved = False
item_dropped = input('\nEnter the name of the item to be dropped: ')
for item in np.items:
if (item.name.lower() == item_dropped.lower().strip()):
is_item_moved = True
np.remove_item(item_taken)
room[np.current_room].add_item(item)
item.drop_item()
if is_item_moved is False:
print('\n The item selected, is not available your inventory')
if (np.current_room == 'grand'):
np.set_current_room('overlook')
print(f"\n\n The current room is {np.current_room}")
print(f"\nAdios!! Thank you for playing, {np.name}. Come back soon!\n\n")