From 0dcb7a00f2ad80c4b544e3e04dce4b008dac1ad7 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sun, 18 May 2014 00:53:57 +0200 Subject: [PATCH] Ability to move player with location. --- naja/actions.py | 6 ++++++ naja/player.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/naja/actions.py b/naja/actions.py index 869c692..e1ec1e0 100644 --- a/naja/actions.py +++ b/naja/actions.py @@ -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): diff --git a/naja/player.py b/naja/player.py index 58cb824..d47e826 100644 --- a/naja/player.py +++ b/naja/player.py @@ -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 -- 2.34.1