self.terrain = self.terrain[:y * width_map] + line +\
self.terrain[(y + 1) * width_map:]
- def set_size(self, yx):
- y, x = yx
- self.size = (y, x)
- self.terrain = ''
- for y in range(self.size[0]):
- self.terrain += '?' * self.size[1]
-
def get_position_index(self, yx):
return yx[0] * self.size[1] + yx[1]
class World:
def __init__(self):
+ self.Map = Map # child classes may use an extended Map class here
+ self.Thing = Thing # child classes may use an extended Thing class here
self.turn = 0
- self.map_ = Map()
+ self.map_ = self.Map()
self.things = []
- self.Thing = Thing # child classes may use an extended Thing class here
def get_thing(self, id_):
for thing in self.things:
self.things += [t]
return t
+ def new_map(self, yx):
+ self.map_ = self.Map(yx, '?')
+
class Thing:
class CommonCommandsMixin:
- def cmd_MAP_SIZE(self, yx):
- """Set self.map_size to yx, redraw self.terrain_map as '?' cells."""
- self.world.map_.set_size(yx)
- cmd_MAP_SIZE.argtypes = 'yx_tuple:nonneg'
+ def cmd_MAP(self, yx):
+ """Create new map of size yx and only '?' cells."""
+ self.world.new_map(yx)
+ cmd_MAP.argtypes = 'yx_tuple:nonneg'
def cmd_THING_TYPE(self, i, type_):
t = self.world.get_thing(i)
print("FILE INPUT LINE %s: %s" % (i, line), end='')
game.io.handle_input(line, store=False)
else:
- game.io.handle_input('MAP_SIZE Y:5,X:5')
+ game.io.handle_input('MAP Y:5,X:5')
game.io.handle_input('TERRAIN_LINE 0 "xxxxx"')
game.io.handle_input('TERRAIN_LINE 1 "x...x"')
game.io.handle_input('TERRAIN_LINE 2 "x.X.x"')
def __init__(self):
super().__init__()
self.Thing = Thing # use local Thing class instead of game_common's
+ self.Map = Map # use local Map class instead of game_common's
self.map_ = Map() # use extended child class
self.player_id = 0
return 'Y:' + str(tuple_[0]) + ',X:' + str(tuple_[1])
self.io.send('NEW_TURN ' + str(self.world.turn))
- self.io.send('MAP_SIZE ' + stringify_yx(self.world.map_.size))
+ self.io.send('MAP ' + stringify_yx(self.world.map_.size))
visible_map = self.world.get_player().get_visible_map()
for y, line in visible_map.lines():
self.io.send('VISIBLE_MAP_LINE %5s %s' % (y, self.io.quote(line)))