Changeset 32:0e49648f8d74
- Timestamp:
- 09/01/13 14:39:13 (8 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- nagslang
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
nagslang/environment.py
r28 r32 10 10 11 11 class AllConditions(ProtagonistCondition): 12 """Condition that is met if all provided conditions are met. 13 14 Conditions are evaluated lazily, so the first condition to fail stops 15 processing. 16 """ 12 17 def __init__(self, *conditions): 13 18 self.conditions = conditions … … 21 26 22 27 class AnyCondition(ProtagonistCondition): 28 """Condition that is met if any provided condition is met. 29 30 Conditions are evaluated lazily, so the first condition to pass stops 31 processing. 32 """ 23 33 def __init__(self, *conditions): 24 34 self.conditions = conditions … … 32 42 33 43 class WolfFormCondition(ProtagonistCondition): 44 """Condition that is met if the protagonist is in wolf form. 45 """ 34 46 def check(self, protagonist): 35 47 return protagonist.in_wolf_form() … … 37 49 38 50 class HumanFormCondition(ProtagonistCondition): 51 """Condition that is met if the protagonist is in human form. 52 """ 39 53 def check(self, protagonist): 40 54 return protagonist.in_human_form() … … 42 56 43 57 class ItemRequiredCondition(ProtagonistCondition): 58 """Condition that is met if the protagonist has the required item. 59 """ 44 60 def __init__(self, required_item): 45 61 self.required_item = required_item … … 47 63 def check(self, protagonist): 48 64 return protagonist.has_item(self.required_item) 65 66 67 class FunctionCondition(ProtagonistCondition): 68 """Condition that is met if the provided function returns `True`. 69 """ 70 def __init__(self, func): 71 self.func = func 72 73 def check(self, protagonist): 74 return self.func(protagonist) 49 75 50 76 -
nagslang/tests/test_environment.py
r28 r32 89 89 self.assert_not_met(item, FakeProtagonist(item=False)) 90 90 91 def test_function_condition(self): 92 condition = environment.FunctionCondition(lambda p: p.startswith('x')) 93 self.assert_met(condition, 'xxx') 94 self.assert_not_met(condition, 'yyy') 95 91 96 92 97 class TestActions(TestCase):
Note:
See TracChangeset
for help on using the changeset viewer.