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):
12 self.required_bits = frozenset(required_bits)
15 def check_available(self, player):
16 return player.bits.check_bits(self.required_bits)
18 def perform_action(self, board, location):
19 raise NotImplementedError("TODO")
21 def check_and_clear_MSB(self, player):
22 if player.bits.check_bit(BITS.MSB):
23 player.bits.clear_bit(BITS.MSB)
29 return {'required_bits': list(self.required_bits),
31 'action_class': self.__class__.__name__}
34 class DoNothing(LocationAction):
37 def perform_action(self, board, location):
41 class LoseHealthOrMSB(LocationAction):
42 TEXT = "Lose health. If MSB is set, it will be cleared instead."
44 def perform_action(self, board, location):
45 if not self.check_and_clear_MSB(board.player):
49 class SetBits(LocationAction):
50 TEXT = "Set bits specified by this location."
52 def perform_action(self, board, location):
53 board.player.bits.set_bits(location.bitwise_operand)
56 class ToggleBits(LocationAction):
57 TEXT = "Toggle bits specified by this location."
59 def perform_action(self, board, location):
60 board.player.bits.toggle_bits(location.bitwise_operand)