forked from bloominstituteoftechnology/Intro-Python-II
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadv.py
More file actions
113 lines (88 loc) · 4.18 KB
/
Copy pathadv.py
File metadata and controls
113 lines (88 loc) · 4.18 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
from room import Room
from player import Player
def main():
room = {
'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons", ['Common Staff', 'Common Sword']),
'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", ['Rare Staff', 'Rare Sword', 'Rare Armor']),
'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.""", ['Rare Gloves', 'Epic Sword', 'Epic Staff', 'Epic Bow', 'Epic Glove']),
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
'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."""),
}
room['outside'].assign_room('s', room['foyer'])
room['foyer'].assign_room('s', room['overlook'])
room['foyer'].assign_room('w', room['narrow'])
room['overlook'].assign_room('n', room['foyer'])
room['narrow'].assign_room('s', room['treasure'])
valid_choices = list('newsqi') + ['inventory']
# Make a new player object that is currently in the 'outside' room.
player = Player('Me', room['outside'])
# Player's __str__ method prints its name and room location
while True:
print('\n------------------------------------------------- \n')
print(player)
# get room will return the room the player is currently in
print('\n' + player.get_room().get_description())
choice = input('Please choose what direction you would like to go or enter a take/drop command: ').split(' ')
# only if len(choice) < 1 or take or drop not inside choice
if (len(choice) < 1 or (not len(choice) == 1 and 'take' not in choice and 'drop' not in choice)):
continue
elif (len(choice) == 1):
choice = ''.join(choice)
if (choice not in valid_choices):
print(f'Choices can only be {", ".join(valid_choices).rstrip() }.')
continue
if (choice == 'q'):
return
if (choice == 'i' or choice == 'inventory'):
print(f"""\n\t\tPlayer Inventory\n-------------------------------------------------
{', '.join([ str(item) for item in player.inventory])}
""")
continue
try:
player.enter_room(choice)
continue
except ValueError:
print('Unfortunately, that path does not exist, please try again')
continue
# here the choices > 1
current_room = player.get_room()
verb, *item = choice
item = ' '.join(item)
# if user enters get/take
if verb == 'get' or verb == 'take':
# check current room for item name
# if item in room
if (item in current_room):
# remove item from room and add to player's inventory
current_room.remove_item(item)
player.add_item(item)
continue
# if not in the room
# print error -> continue
print(f"{item} does not exist in room. Please try again")
continue
# check verb to be remove or drop
if verb == 'remove' or verb == 'drop':
# now we want to check if the item is in the player's inventory
if item in player:
# remove item from player and drop into room if it is
player.drop_item(item)
current_room.add_item(item)
if __name__ == '__main__':
main()
# 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.