Ability to move player with location.
authorSimon Cross <hodgestar@gmail.com>
Sat, 17 May 2014 22:53:57 +0000 (00:53 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 17 May 2014 22:54:33 +0000 (00:54 +0200)
naja/actions.py
naja/player.py

index 869c6925eead025248ac397f4e65efdaeeb640de..e1ec1e0a40b2cf58bbc741e0fcdd71cbc966602f 100644 (file)
@@ -296,6 +296,12 @@ class ShiftLocations(LocationAction):
         board.shift_locations(
             self.data['direction'],
             self.data.get('skip_current', True))
+        if self.data.get('move_player', False):
+            pos = {
+                'NORTH': (0, -1), 'SOUTH': (0, 1),
+                'EAST': (1, 0), 'WEST': (-1, 0),
+            }.get(self.data['direction'], (0, 0))
+            board.player.force_position(pos, delta=True)
 
 
 class RotateLocations(LocationAction):
index 58cb8245e6c5f0f3b466f25bf2d007dba2e544ef..d47e82682cce298a57424eaae1918d3f100e9615 100644 (file)
@@ -151,6 +151,13 @@ class Player(object):
             return True
         return False
 
+    def force_position(self, pos, delta=True):
+        if delta:
+            pos = (self.position[0] + pos[0],
+                   self.position[1] + pos[1])
+        if (0 <= pos[0] < 5 and 0 <= pos[1] < 5):
+            self.position = pos
+
     def set_gameboard(self, gameboard):
         self.gameboard = gameboard