X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new2%2Fplomrogue%2Fgame.py;h=0c09b01d07206e2b44c5c3c2b6bb6c9e6a924041;hb=1fcb132eabcaa1a95bf2b527dc18c92c15016d2a;hp=1cb6e2232b7d59542a37e08e9264a58da538efde;hpb=3f6aeac609f6337713f6cca17e4f54960ecf4d7f;p=plomrogue2-experiments diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index 1cb6e22..0c09b01 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -1,8 +1,8 @@ from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_FLATTEN_SURROUNDINGS) from plomrogue.errors import GameError, PlayError -from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING, - cmd_TURN, cmd_MAP_LINE, cmd_MAP, cmd_GET_ANNOTATION, +from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING, cmd_MAP, + cmd_TURN, cmd_MAP_LINE, cmd_GET_ANNOTATION, cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE) from plomrogue.io import GameIO from plomrogue.misc import quote @@ -16,6 +16,7 @@ class GameBase: def __init__(self): self.turn = 0 self.things = [] + self.map_geometry = MapGeometrySquare(YX(24, 40)) def get_thing(self, id_, create_unfound): # No default for create_unfound because every call to get_thing @@ -42,7 +43,6 @@ class Game(GameBase): 'MOVE': Task_MOVE, 'WRITE': Task_WRITE, 'FLATTEN_SURROUNDINGS': Task_FLATTEN_SURROUNDINGS} - self.map_geometry = MapGeometrySquare(YX(24, 40)) self.commands = {'QUERY': cmd_QUERY, 'ALL': cmd_ALL, 'LOGIN': cmd_LOGIN, @@ -75,11 +75,16 @@ class Game(GameBase): import string if string_option_type == 'direction': return self.map_geometry.get_directions() - if string_option_type == 'char': + elif string_option_type == 'char': return [c for c in string.digits + string.ascii_letters + string.punctuation + ' '] + elif string_option_type == 'map_geometry': + return ['Hex', 'Square'] return None + def get_map_geometry_shape(self): + return self.map_geometry.__class__.__name__[len('MapGeometry'):] + def send_gamestate(self, connection_id=None): """Send out game state data relevant to clients.""" @@ -91,7 +96,8 @@ class Game(GameBase): self.io.send('TURN ' + str(self.turn)) for t in self.things: send_thing(t) - self.io.send('MAP %s %s' % (self.map_geometry.size, quote(self.map.terrain))) + self.io.send('MAP %s %s %s' % (self.get_map_geometry_shape(), + self.map_geometry.size, quote(self.map.terrain))) for yx in self.portals: self.io.send('PORTAL %s %s' % (yx, quote(self.portals[yx]))) self.io.send('GAME_STATE_COMPLETE') @@ -179,7 +185,8 @@ class Game(GameBase): with open(self.io.save_file, 'w') as f: write(f, 'TURN %s' % self.turn) - write(f, 'MAP %s' % (self.map_geometry.size,)) + map_geometry_shape = self.get_map_geometry_shape() + write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,)) for y, line in self.map.lines(): write(f, 'MAP_LINE %5s %s' % (y, quote(line))) for yx in self.annotations: @@ -187,7 +194,7 @@ class Game(GameBase): for yx in self.portals: write(f, 'PORTAL %s %s' % (yx, quote(self.portals[yx]))) - def new_world(self, size): - self.map_geometry = MapGeometrySquare(YX(size.y, size.x)) + def new_world(self, map_geometry): + self.map_geometry = map_geometry self.map = Map(self.map_geometry.size) self.annotations = {}