from plomrogue.io import GameIO
from plomrogue.misc import quote
from plomrogue.things import Thing, ThingPlayer
-from plomrogue.mapping import MapGeometrySquare
+from plomrogue.mapping import YX, MapGeometrySquare
self.io = GameIO(self)
self.tasks = {'WAIT': Task_WAIT,
'MOVE': Task_MOVE}
- self.map_geometry = MapGeometrySquare()
+ self.map_geometry = MapGeometrySquare(YX(24, 40))
self.commands = {'QUERY': cmd_QUERY,
'ALL': cmd_ALL,
'LOGIN': cmd_LOGIN}
class MapGeometry():
+ def __init__(self, size):
+ self.size = size
+
def get_directions(self):
directions = []
for name in dir(self):
def move(self, start_pos, direction):
mover = getattr(self, 'move_' + direction)
- return mover(start_pos)
+ target = mover(start_pos)
+ if target.y < 0 or target.x < 0 or \
+ target.y >= self.size.y or target.x >= self.size.x:
+ return None
+ return target
def check(self):
test_pos = self.get_move_target()
- if test_pos.y < 0 or test_pos.x < 0 or test_pos.y >= 24 or test_pos.x >= 40:
+ if test_pos is None:
raise GameError('would move out of map')
def do(self):