Repository navigation
Expand file tree
/
Copy pathplayer.py
More file actions
43 lines (38 loc) · 1.44 KB
/
Copy pathplayer.py
File metadata and controls
43 lines (38 loc) · 1.44 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
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player():
def __init__(self, name, current_room):
self.name = name
self.current_room = current_room
self.inventory = []
def travel(self, direction):
#Grab the n/s/e/w attribute from the room
next_room = getattr(self.current_room, f'{direction}_to')
#item = getattr(self.current_room, self.current_room.items)
if next_room is not None:
self.current_room = next_room
# self.current_room.items = item
print(self.current_room)
# print(self.current_room.items)
else:
print('You cannot go that direction')
def take_item(self, item):
found = False
for i in self.current_room.items:
if i.name.lower() == item:
self.inventory.append(i)
self.current_room.items.remove(i)
found = True
i.on_take()
if not found:
print(f'This {item} is not in this room')
def drop_item(self, item):
found = False
for i in self.inventory:
if i.name.lower() == item:
self.inventory.remove(i)
self.current_room.items.append(i)
found = True
i.on_drop()
if not found:
print(f'The {item} was not found in your inventory')