-
Notifications
You must be signed in to change notification settings - Fork 0
/
floor.py
60 lines (46 loc) · 1.58 KB
/
floor.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
'''
Defining class Floor which contains all info for a single floor
'''
from build import Build
class Floor:
'''a floor is initally a dict of strings, when loaded, it is a dict of
different types of Objs, could be Item or Character'''
def __init__(self, n, *args):
self._num = n
self._floor = {}
for point, item in args:
self.set_floor(*point, item)
self._active = False
def set_floor(self, i, j, item):
self._floor[(i, j)] = item
def get_floor(self, i, j):
return self._floor.get((i, j))
def del_floor(self, i, j):
self._floor.pop((i, j))
def get_item(self, name):
for (i, j), item in self._floor.items():
if (isinstance(item, str) and item == name) or \
(isinstance(item, Build) and item.get_name() == name):
return i, j
@property
def active(self):
return self._active
@active.setter
def active(self, value):
self._active = value
@property
def floor(self):
return self._floor
@property
def num(self):
return self._num
def __str__(self):
return ''.join([str((point, item))if isinstance(item, str)
else str((point, item.get_name())) for point, item in self._floor.items()])
def __iter__(self):
for point, item in self._floor.items():
yield (point, item)
def save_floor(self):
with open('floor.flo', 'w') as file:
for point, item in self._floor.items():
file.write(str((point, item)))