-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdungeon.py
More file actions
89 lines (70 loc) · 2.18 KB
/
Copy pathdungeon.py
File metadata and controls
89 lines (70 loc) · 2.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
class Player():
def __init__(self):
self.inventory = []
self.alive = True
self.has_won = False
def room_001_event():
if 'some really gross cheese' in player.inventory:
choice = input('Give cheese to skeleton?')
if choice == 'yes':
print('you give the skeleton some cheese.')
print('he becomes your friend.')
player.has_won == True
else:
pass
return
def room_002_event():
pass
def room_003_event():
pass
def room_004_event():
global player
print("You see some gross moldy cheese.")
choice = input('Eat the cheese, take the cheese, or leave?')
if choice == 'eat':
print('you eat the moldy cheese and die.')
player.alive = False
elif choice == 'take':
player.inventory.append('some really gross cheese')
else:
pass
return
class Room():
def __init__(self, raw_string):
lines = raw_string.split('\n')
self.id = lines[0]
self.exits = lines[-1]
self.room_text = "\n".join(lines[1:-1])
def visit(self):
print(self.room_text)
event_dict[self.id]()
def move(self):
choices = {}
print("There are rooms to the following directions:")
for item in self.exits.split(','):
item_direction, item_id = item.split(':')
print(item_direction)
choices[item_direction] = item_id
decision = input( "Where do you want to go?" )
return choices[decision]
player = Player()
file = open('map_01.txt')
rooms_raw_text = file.read().split('%%%%%')
rooms = [Room(text.strip()) for text in rooms_raw_text]
event_dict = {
'room_001':room_001_event,
'room_002':room_002_event,
'room_003':room_003_event,
'room_004':room_004_event
}
id_dict = {item.id:item for item in rooms}
current_room = rooms[0]
while player.alive and not player.has_won:
current_room.visit()
if player.alive and not player.has_won:
new_room_id = current_room.move()
current_room = id_dict[new_room_id]
if player.has_won:
print("Yay, you win")
if not player.alive:
print("You died in the dungeon")