1 from parser import ArgError
11 self.Thing = Thing # child classes may use an extended Thing class here
13 def set_map_size(self, yx):
15 self.map_size = (y, x)
17 for y in range(self.map_size[0]):
18 self.terrain_map += '?' * self.map_size[1]
20 def set_map_line(self, y, line):
21 width_map = self.map_size[1]
22 if y >= self.map_size[0]:
23 raise ArgError('too large row number %s' % y)
24 width_line = len(line)
25 if width_line > width_map:
26 raise ArgError('too large map line width %s' % width_line)
27 self.terrain_map = self.terrain_map[:y * width_map] + line + \
28 self.terrain_map[(y + 1) * width_map:]
30 def get_thing(self, id_):
31 for thing in self.things:
34 t = self.Thing(self, id_)
41 def __init__(self, world, id_):
50 def cmd_MAP_SIZE(self, yx):
51 """Set self.map_size to yx, redraw self.terrain_map as '?' cells."""
52 self.world.set_map_size(yx)
53 cmd_MAP_SIZE.argtypes = 'yx_tuple:nonneg'
55 def cmd_TERRAIN_LINE(self, y, terrain_line):
56 self.world.set_map_line(y, terrain_line)
57 cmd_TERRAIN_LINE.argtypes = 'int:nonneg string'
59 def cmd_THING_TYPE(self, i, type_):
60 t = self.world.get_thing(i)
62 cmd_THING_TYPE.argtypes = 'int:nonneg string'
64 def cmd_THING_POS(self, i, yx):
65 t = self.world.get_thing(i)
67 cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'