1 from naja.constants import BITS
4 class LocationAction(object):
6 An action that may be performed on a location.
11 def __init__(self, required_bits, **data):
13 for bit in required_bits:
14 # Convert names to numbers if applicable.
15 bits.add(BITS.get(bit, bit))
16 self.required_bits = frozenset(bits)
19 def check_available(self, player):
20 return player.bits.check_bits(self.required_bits)
22 def perform_action(self, board, location):
23 raise NotImplementedError("TODO")
25 def check_and_clear_MSB(self, player):
26 if player.bits.check_bit(BITS.MSB):
27 player.bits.clear_bit(BITS.MSB)
33 return {'required_bits': list(self.required_bits),
35 'action_class': self.__class__.__name__}
38 class DoNothing(LocationAction):
41 def perform_action(self, board, location):
45 class LoseHealthOrMSB(LocationAction):
46 TEXT = "Lose health. If MSB is set, it will be cleared instead."
48 def perform_action(self, board, location):
49 if not self.check_and_clear_MSB(board.player):
53 class SetBits(LocationAction):
54 TEXT = "Set bits specified by this location."
56 def perform_action(self, board, location):
57 board.player.bits.set_bits(location.bitwise_operand)
60 class ToggleBits(LocationAction):
61 TEXT = "Toggle bits specified by this location."
63 def perform_action(self, board, location):
64 board.player.bits.toggle_bits(location.bitwise_operand)