From: Christian Heller Date: Thu, 17 Jan 2019 23:18:30 +0000 (+0100) Subject: Create new Map object instead of changing it. X-Git-Url: https://plomlompom.com/repos/ledger?a=commitdiff_plain;h=9c3865bbfc4fe7721f8c2f057bce85e2300ea528;p=plomrogue2-experiments Create new Map object instead of changing it. --- diff --git a/game_common.py b/game_common.py index b729a29..5aa4b25 100644 --- a/game_common.py +++ b/game_common.py @@ -18,13 +18,6 @@ class Map: 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] @@ -32,10 +25,11 @@ class Map: 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: @@ -45,6 +39,9 @@ class World: self.things += [t] return t + def new_map(self, yx): + self.map_ = self.Map(yx, '?') + class Thing: @@ -57,10 +54,10 @@ 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) diff --git a/server.py b/server.py index 6eb7016..2a7b55c 100755 --- a/server.py +++ b/server.py @@ -20,7 +20,7 @@ if os.path.exists(game_file_name): 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"') diff --git a/server_/game.py b/server_/game.py index 5e38daa..60c0f47 100644 --- a/server_/game.py +++ b/server_/game.py @@ -111,6 +111,7 @@ class World(game_common.World): 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 @@ -276,7 +277,7 @@ class Game(game_common.CommonCommandsMixin): 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)))