from plomrogue.io import GameIO
from plomrogue.misc import quote
from plomrogue.things import Thing, ThingPlayer
+from plomrogue.mapping import MapGeometrySquare
self.io = GameIO(self)
self.tasks = {'WAIT': Task_WAIT,
'MOVE': Task_MOVE}
- self.commands = {'QUERY': cmd_QUERY, 'ALL': cmd_ALL, 'LOGIN': cmd_LOGIN}
+ self.map_geometry = MapGeometrySquare()
+ self.commands = {'QUERY': cmd_QUERY,
+ 'ALL': cmd_ALL,
+ 'LOGIN': cmd_LOGIN}
self.thing_type = Thing
self.thing_types = {'player': ThingPlayer}
self.sessions = {}
def get_string_options(self, string_option_type):
if string_option_type == 'direction':
- return ['UP', 'DOWN', 'LEFT', 'RIGHT']
+ return self.map_geometry.get_directions()
return None
def send_gamestate(self, connection_id=None):
def __str__(self):
return 'Y:%s,X:%s' % (self.y, self.x)
+
+
+
+class MapGeometry():
+
+ def get_directions(self):
+ directions = []
+ for name in dir(self):
+ if name[:5] == 'move_':
+ directions += [name[5:]]
+ return directions
+
+ def move(self, start_pos, direction):
+ mover = getattr(self, 'move_' + direction)
+ return mover(start_pos)
+
+
+
+class MapGeometryWithLeftRightMoves(MapGeometry):
+
+ def move_LEFT(self, start_pos):
+ return YX(start_pos.y, start_pos.x - 1)
+
+ def move_RIGHT(self, start_pos):
+ return YX(start_pos.y, start_pos.x + 1)
+
+
+
+class MapGeometrySquare(MapGeometryWithLeftRightMoves):
+
+ def move_UP(self, start_pos):
+ return YX(start_pos.y - 1, start_pos.x)
+
+ def move_DOWN(self, start_pos):
+ return YX(start_pos.y + 1, start_pos.x)
from plomrogue.errors import GameError
-#from plomrogue.misc import quote
from plomrogue.mapping import YX
argtypes = 'string:direction'
def get_move_target(self):
- moves = {
- 'UP': YX(-1, 0),
- 'DOWN': YX(1, 0),
- 'LEFT': YX(0, -1),
- 'RIGHT': YX(0, 1),
- }
- return self.thing.position + moves[self.args[0]]
+ return self.thing.game.map_geometry.move(self.thing.position,
+ self.args[0])
def check(self):
test_pos = self.get_move_target()