X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/git-logo.png?a=blobdiff_plain;f=game_common.py;h=5aa4b2544729d337fcef2ee939fe1ddeddc3ea63;hb=9c3865bbfc4fe7721f8c2f057bce85e2300ea528;hp=689398ddbce3cd85f93e7bcee5cbd1d2ce9e8c0a;hpb=827134a13175939231b85fbc159c013e0f024e78;p=plomrogue2-experiments diff --git a/game_common.py b/game_common.py index 689398d..5aa4b25 100644 --- a/game_common.py +++ b/game_common.py @@ -18,21 +18,18 @@ 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] 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: @@ -42,6 +39,9 @@ class World: self.things += [t] return t + def new_map(self, yx): + self.map_ = self.Map(yx, '?') + class Thing: @@ -52,12 +52,12 @@ class Thing: self.position = [0,0] -class Commander: +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)