X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Factions.py;h=35f4342a3afc40c74196ce516473599d0ab68ec2;hb=5fe12b55d1908f850145eec16a1ee2c8e61ba6ef;hp=f92961cd4bdfc38e61d8e5eb33b521aa55446d11;hpb=aac1783aa9c84031bb37d74616ee72a7b32ebeac;p=naja.git diff --git a/naja/actions.py b/naja/actions.py index f92961c..35f4342 100644 --- a/naja/actions.py +++ b/naja/actions.py @@ -1,4 +1,5 @@ from naja.constants import BITS, CHESS_PIECES +from naja.utils import bit_glyphs, move_glyph class LocationAction(object): @@ -13,7 +14,7 @@ class LocationAction(object): self.required_bits = required_bits self.data = data - def get_text(self): + def get_text(self, location=None): substitutions = self.data.copy() if 'direction' in self.data: @@ -23,9 +24,17 @@ class LocationAction(object): 'EAST': 'row', 'WEST': 'row', }[self.data['direction']] + substitutions['direction'] = '{%s}' % (substitutions['direction'],) if 'chesspiece' in self.data: - substitutions['chesspiece_name'] = self.data['chesspiece'].lower() + substitutions['chesspiece_name'] = move_glyph( + self.data['chesspiece']) + + if location is None: + substitutions['location_bits'] = 'bits specified by this location' + else: + substitutions['location_bits'] = bit_glyphs( + location.bitwise_operand) return self.TEXT % substitutions @@ -33,7 +42,8 @@ class LocationAction(object): return player.bits.check_bits(self.required_bits) def perform_action(self, board, location): - raise NotImplementedError("TODO") + raise NotImplementedError( + "%s does not implement perform_action()." % (type(self).__name__,)) def check_and_clear_MSB(self, player): if player.bits.check_bit(BITS.MSB): @@ -56,7 +66,7 @@ class DoNothing(LocationAction): class LoseHealthOrMSB(LocationAction): - TEXT = "Lose health or MSB." + TEXT = "Lose {HEALTH} or {MSB}." USES_MSB = True def perform_action(self, board, location): @@ -65,21 +75,21 @@ class LoseHealthOrMSB(LocationAction): class SetBits(LocationAction): - TEXT = "Set bits specified by this location." + TEXT = "Set %(location_bits)s." def perform_action(self, board, location): board.player.bits.set_bits(location.bitwise_operand) class ToggleBits(LocationAction): - TEXT = "Toggle bits specified by this location." + TEXT = "Toggle %(location_bits)s." def perform_action(self, board, location): board.player.bits.toggle_bits(location.bitwise_operand) class LoseHealthOrMSBAndSetBits(LocationAction): - TEXT = "Lose health or MSB, then set bits specified by this location." + TEXT = "Lose {HEALTH} or {MSB}, then set %(location_bits)s." USES_MSB = True def perform_action(self, board, location): @@ -89,7 +99,7 @@ class LoseHealthOrMSBAndSetBits(LocationAction): class AcquireWinToken(LocationAction): - TEXT = "Acquire a win token, then clear all key bits." + TEXT = "Gain {WINTOKEN}, then clear {RED,GREEN,BLUE}." def perform_action(self, board, location): board.acquire_win_token() @@ -99,7 +109,7 @@ class AcquireWinToken(LocationAction): class GainHealthAndClearBitsOrMSB(LocationAction): - TEXT = "Gain health, then clear bits specified by this location or MSB." + TEXT = "Gain {HEALTH}, then clear %(location_bits)s or {MSB}." USES_MSB = True def perform_action(self, board, location): @@ -115,7 +125,7 @@ class ShiftLocations(LocationAction): board.shift_locations(self.data['direction']) -class AllowChessMove(LocationAction) : +class AllowChessMove(LocationAction): TEXT = "Move like a %(chesspiece_name)s for one turn." def perform_action(self, board, location):