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
|
from Room import Room
class Dungeon:
def __init__( self, name, theme, next, width, height, room_str = None ):
self.name = name
self.theme = theme
self.next = next
self.width = width
self.height = height
self.roomlist = []
for y in range(0, height):
room_row = []
for x in range(0, width):
if room_str:
room_row.append( Room(x,y, room_str.pop(0) ) )
else:
room_row.append( Room(x,y) )
self.roomlist.append(room_row)
def get_room_array(self):
return self.roomlist
def get_adj_room( self, room, dir ):
if dir == "N":
next_x = room._x
next_y = room._y-1
elif dir == "E":
next_x = room._x+1
next_y = room._y
elif dir == "S":
next_x = room._x
next_y = room._y+1
elif dir == "W":
next_x = room._x-1
next_y = room._y
else:
return False
if next_x < 0 or next_y < 0:
return False
try:
return self.roomlist[next_y][next_x]
except:
return False
def update_room(self, room):
self.roomlist[room._y][room._x] = room
def export(self):
text = str(self.width) + "x" + str(self.height) + "\n"
text += str(self.theme) + "\n"
text += str(self.next) + "\n"
for row in self.roomlist:
for room in row:
text += room.room_to_string() + "\n"
return text
|