Commits

Dominic Kexel  committed da54bc5

more function in ABC and documentation

  • Participants
  • Parent commits e90dbd0

Comments (0)

Files changed (2)

File game/game.py

             ChangePilesEvent().post(self.ev)
             ChangeHandEvent(self.active_player).post(self.ev)
             
-    def play_card(self, player, card_id, free=False, is_duration=False, update=True):
+    def play_card(self, player, card_id, free=False, is_duration=False):
         """Let the player play a card"""
 
         if not player is self.active_player:
         if card.cardtype & ACTION and not free:
             player.actions -= 1
         
-        if update:
-            self.update_player(player)
+        self.update_player(player)
 
     def add_cost_mod(self, mod):
         self.cost_mod.append(mod)
             self.subphase_cache.append(subphaseinfo)
 
     def _restore_subphase(self):
-        """Get back to the last subphase"""
+        """Get back to the last subphase
+
+        The on_restore_callback-handlers are important for attack cards that do something after changing the sub-phase
+        to resolve an effect. For example, the Swindler forces each player to reveal the top card of the deck. After
+        each player revealed the card, the sub-phase changes back from the attack sub-phase to the previous sub-phase,
+        and this is the point in time where the Swindler wants to decide which cards are replaced.
+        """
 
         cb = self.subphaseinfo.on_restore_callback
 

File game/gameinterface.py

 
 
 class GameInterface(object):
+    """The interface for the cards to interact with the game
+    """
     __metaclass__ = abc.ABCMeta
 
     @abc.abstractmethod
         """
         Let the player pick some cards from his hand
 
+        Example: Haven lets the player pick a card from his hand to put this beneath itself
+
         :param card: the card that triggers this action
         :type card: Card
         :param text: the message that will be displayed to the player
         """
         Let the player pick a pile of cards from the board
 
+        Example: Feast lets the player pick a pile of cards and checks if the cost of the cards is up to 5
+
         :param card: the card that triggers this action
         :type card: Card
         :param text: the message that will be displayed to the player
         :param callback: the callback function that is invoked after the player picked a pile
         :type callback: function
         """
+
+    @abc.abstractmethod
+    def add_action_step_handler(self, card_class, callback):
+        """Register a callback function that is invoked if a specific card is played in the action step.
+
+        Example: The Coppersmith registers a function that adds 1 to the players coins whenever a Copper is played.
+
+        All callbacks are cleared when the player finishes his turn.
+
+        :param card_class: the class of the card that triggers the callback function
+        :type card_class: Class
+        :param callback: the callback function invoked when a card of the given class is player in the action step
+        :type callback: function
+        """
+    
+    @abc.abstractmethod
+    def add_buy_step_handler(self, card_class, callback):
+        """Register a callback function that is invoked if a specific card is played in the buy step
+
+        Example: The Coppersmith registers a function that adds 1 to the players coins whenever a Copper is played.
+
+        All callbacks are cleared when the player finishes his turn.
+
+        :param card_class: the class of the card that triggers the callback function
+        :type card_class: Class
+        :param callback: the callback function invoked when a card of the given class is player in the buy step
+        :type callback: function
+        """
+
+    @abc.abstractmethod
+    def add_cost_mod(self, mod):
+        """Register a function that is invoked when the cost of a card is calculated
+
+        Example: The Brigde registers a function that subtracts 1 coin of the cost of each card.
+
+        :param mod: a function taking the parameters 'coins' and 'potions' and returning a tuple of (coins, potions)
+        :type mod: function
+        """
+    
+    @abc.abstractmethod
+    def allpiles(self):
+        """Get all piles (kingdom cards and common cards)
+
+        :returns: a list of all piles of kingdom and common cards
+        :rtype: list
+        """
+
+    @abc.abstractmethod
+    def ask(self, card, text, answers, callback=None, on_restore_callback=None):
+        """Ask the active player to pick an answer to the given question
+
+        Example: The Minion asks the player to either get money or to discard/draw cards
+
+        :param card: the card that triggers this action
+        :type card: Card
+        :param text: the text displayed to/question asked the player
+        :type text: str
+        :param answers: the possible answers to the question
+        :type answers: tuple
+        :param callback: the callback function invoked when the player picked his answer
+        :type callback: function
+        :param on_restore_callback: the callback function invoked when the sub-phase is restored
+        :type on_restore_callback: function
+        """
+    
+    @abc.abstractmethod
+    def ask_all_players(self, card, askplayerinfo, handler=None, player_filter=None):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def ask_yes_no(self, card, text, callback=None, on_restore_callback=None, card_to_show=None):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def attack(self, card, attack_handler=None, subphase=None, info=None,
+               expect_answer=True, on_restore_callback=None, keep_WAIT=False):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def attack_ask(self, card, info, attack_handler=None,
+               expect_answer=True, on_restore_callback=None):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def attack_let_pick_from_hand(self, card, text, attack_handler=None,
+               expect_answer=True, on_restore_callback=None):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def discard_card(self, player, card):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def discard_cards(self, cards, player=None):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def discard_hand(self, player):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def draw_card(self, player=None, count=1):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def enter_subphase(self, subphaseinfo):
+        """
+        
+        """
+    
+    @abc.abstractmethod
+    def get_cost(self, pile_or_card):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def get_pile(self, cardtype):
+        """
+
+        """
+    
+    @abc.abstractmethod
+    def get_player_by_id(self, player_id):
+        """
+
+        """
+
+    @abc.abstractmethod
+    def has_played(self, card_class):
+        """
+
+        """