Ignore:
Timestamp:
09/05/13 13:58:24 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Protagonist actions, now required for operating doors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/environment.py

    r32 r281  
    7575
    7676
     77class PuzzleStateCondition(ProtagonistCondition):
     78    """Condition that is met if the provided function returns `True`.
     79    """
     80    def __init__(self, puzzler):
     81        self.puzzler = puzzler
     82
     83    def check(self, protagonist):
     84        return self.puzzler.get_state()
     85
     86
    7787class Action(object):
    7888    """Representation of an action that can be performed.
    7989
    8090    If the (optional) condition is met, the provided function will be called
    81     with the protagonist and the target as parameters.
     91    with the protagonist as a parameter. It is assumed that the function
     92    already knows about the target.
    8293    """
    8394    def __init__(self, func, condition=None):
     
    90101        return self.condition.check(protagonist)
    91102
    92     def perform(self, protagonist, target):
     103    def perform(self, protagonist):
    93104        if not self.check(protagonist):
    94105            raise ValueError("Attempt to perform invalid action.")
    95         return self.func(protagonist, target)
     106        return self.func(protagonist)
    96107
    97108
     
    103114        self.actions = actions
    104115
     116    def set_game_object(self, game_object):
     117        self.game_object = game_object
     118
    105119    def select_action(self, protagonist):
    106120        """Select a possible action given the protagonist's state.
Note: See TracChangeset for help on using the changeset viewer.