chess moves are working; need more tests
[naja.git] / naja / actions.py
index 0535c8be1b37964d752773636d2538c877adc78b..f92961cd4bdfc38e61d8e5eb33b521aa55446d11 100644 (file)
@@ -1,4 +1,4 @@
-from naja.constants import BITS
+from naja.constants import BITS, CHESS_PIECES
 
 
 class LocationAction(object):
@@ -15,6 +15,7 @@ class LocationAction(object):
 
     def get_text(self):
         substitutions = self.data.copy()
+
         if 'direction' in self.data:
             substitutions['rowcol'] = {
                 'NORTH': 'column',
@@ -22,6 +23,10 @@ class LocationAction(object):
                 'EAST': 'row',
                 'WEST': 'row',
             }[self.data['direction']]
+
+        if 'chesspiece' in self.data:
+            substitutions['chesspiece_name'] = self.data['chesspiece'].lower()
+
         return self.TEXT % substitutions
 
     def check_available(self, player):
@@ -108,3 +113,12 @@ class ShiftLocations(LocationAction):
 
     def perform_action(self, board, location):
         board.shift_locations(self.data['direction'])
+
+
+class AllowChessMove(LocationAction) :
+    TEXT = "Move like a %(chesspiece_name)s for one turn."
+
+    def perform_action(self, board, location):
+        if self.data['chesspiece'] in CHESS_PIECES:
+            chesspiece = CHESS_PIECES[self.data['chesspiece']]
+            board.allow_chess_move(chesspiece)