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
|
from Room import Room
from sugar.util import unique_id
class Dungeon:
def __init__( self, name, theme, next, width, height, room_str = None, id = None ):
if id:
self.id = id
else:
self.id = unique_id()
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 has_door_type(self, key):
for room_row in self.roomlist:
for room in room_row:
for door_key in room.doors:
if room.doors[door_key][1] == key:
return True
return False
def valid_dungeon(self):
return self.has_door_type( 'e' ) and self.has_door_type( 'x' )
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 = self.name + "\n"
text += self.id + "\n"
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
|