-
Notifications
You must be signed in to change notification settings - Fork 0
/
room.py
executable file
·137 lines (88 loc) · 3.14 KB
/
room.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
#!/usr/bin/env python3
class Room:
def __init__(self, id, name):
self.id = id
self.name = name
self.state = '0'
self.description = {}
self.items = []
self.to_north = ''
self.to_south = ''
self.to_east = ''
self.to_west = ''
self.enter_sound_id = ''
def getID(self):
return self.id
def setID(self, text):
self.id = text
def getName(self):
return self.name
def setName(self, text):
self.name = text
def getState(self):
return self.state
def setState(self, text):
self.state = text
def getDescription(self):
return self.description[self.state]
def addDescription(self, text, state='0'):
self.description[state] = text
def addItemID(self, item_id):
if not item_id in self.items:
self.items.append(item_id)
def removeItemID(self, item_id):
if item_id in self.items:
self.items.remove(item_id)
def getItemsID(self):
return self.items
def getToDirection(self, d):
if type(d) is str:
direction = d
else:
direction = d['go_to']
return direction
def getToNorth(self):
return self.getToDirection(self.to_north)
def setToNorth(self, new_room_id):
self.to_north = new_room_id
def getToSouth(self):
return self.getToDirection(self.to_south)
def setToSouth(self, new_room_id):
self.to_south = new_room_id
def getToEast(self):
return self.getToDirection(self.to_east)
def setToEast(self, new_room_id):
self.to_east = new_room_id
def getToWest(self):
return self.getToDirection(self.to_west)
def setToWest(self, new_room_id):
self.to_west = new_room_id
def setEnterSoundID(self, id_sound):
self.enter_sound_id = id_sound
def hasEnterSoundID(self):
return (not self.enter_sound_id == '')
def enterSoundID(self):
return self.enter_sound_id
def removeParamFromCurrentDescription(self, item_id):
remove_done = False
text = self.description[self.state]
if item_id in text:
count_open = text.count('{')
count_close = text.count('}')
param_begin_index = 0
i = 0
still_to_be_replaced = True
while i < count_open and still_to_be_replaced:
param_begin_index = text.find('{', param_begin_index) + 1
param_end_index = text.find('}', param_begin_index)
param_to_remove = text[param_begin_index:param_end_index]
if param_to_remove == item_id:
to_replace = '{' + param_to_remove + '}'
text = text.replace(to_replace, '')
still_to_be_replaced = False
param_begin_index = param_end_index + 1
i += 1
self.description[self.state] = text.replace(' ', ' ').replace(' .', '.').replace('..', '.').replace(', .','.')
self.items.remove(item_id)
remove_done = True
return remove_done