Example #1
0
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.step = PreconditionStep(self.attack)
        self.preconditionMessages = ["My Precondition Messages"]
        self.attackMessages = ["My Attack Messages"]

        self.calledCheckPreConditions = False
Example #2
0
class perform(unittest.TestCase):
    """ Test cases of perform """
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.step = PreconditionStep(self.attack)
        self.preconditionMessages = ["My Precondition Messages"]
        self.attackMessages = ["My Attack Messages"]

        self.calledCheckPreConditions = False

    def preconditions_Failing(self):
        """ Test that failing precodnitions prevents the attack from being done """
        self.failPreconditions = False
        self.step.perform(None,
                          None,
                          None,
                          PreconditionChecker=self.buildPreconditionChecker)

        self.assertTrue(self.calledCheckPreConditions,
                        "Should have called checkPreconditions")

    def preconditions_Passing(self):
        """ Test that passing precodnitions allows the attack to be used """
        self.failPreconditions = True
        self.step.perform(None,
                          None,
                          None,
                          PreconditionChecker=self.buildPreconditionChecker)

        self.assertTrue(self.calledCheckPreConditions,
                        "Should have called checkPreconditions")

    def messagesReturned(self):
        """ Test that messages from the Preconditions Checker are returned """
        self.failPreconditions = False
        messages = self.step.perform(
            None,
            None,
            None,
            PreconditionChecker=self.buildPreconditionChecker)

        self.assertEquals(
            self.preconditionMessages, messages,
            "Should have returned the messages from the Preconditions check")

    def buildPreconditionChecker(self, user, target, environment, attack):
        return self

    def checkPreConditions(self):
        self.calledCheckPreConditions = True
        return self.failPreconditions, self.preconditionMessages
 def  setUp(self):
     """ Build the Step for the test """
     self.attack = Attack()
     self.step = PreconditionStep(self.attack)
     self.preconditionMessages = ["My Precondition Messages"]
     self.attackMessages = ["My Attack Messages"]
     
     self.calledCheckPreConditions = False
Example #4
0
    def __init__(self):
        self.hitDelegate = None
        self.damageDelegate = None
        self.speedDelegate = None

        self.effectDelegates = []
        self.makes_contact = False
        self.powerPoints = 0
        self.currPowerPoints = 0

        self.preconditionsStep = PreconditionStep(self)
        self.announcementStep = AnnouncementStep(self)
        self.removePPStep = RemovePPStep(self)
        self.hitStep = HitStep(self)
        self.damageStep = DamageStep(self)
        self.effectsStep = EffectsStep(self)
        self.handleContactStep = HandleContactStep(self)
        self.handleMissEffectsStep = HandleMissEffectsStep(self)
Example #5
0
class Attack:
    """ Represents an Attack """
    def __init__(self):
        self.hitDelegate = None
        self.damageDelegate = None
        self.speedDelegate = None

        self.effectDelegates = []
        self.makes_contact = False
        self.powerPoints = 0
        self.currPowerPoints = 0

        self.preconditionsStep = PreconditionStep(self)
        self.announcementStep = AnnouncementStep(self)
        self.removePPStep = RemovePPStep(self)
        self.hitStep = HitStep(self)
        self.damageStep = DamageStep(self)
        self.effectsStep = EffectsStep(self)
        self.handleContactStep = HandleContactStep(self)
        self.handleMissEffectsStep = HandleMissEffectsStep(self)

    def use(self, user, target, environment):
        """ Uses the current attack Object in a Battle """
        messages = []
        messages += self.preconditionsStep.perform(user, target, environment)
        if self.preconditionsStep.passed:
            messages += self.announcementStep.perform(user, target,
                                                      environment)
            messages += self.removePPStep.perform(user, target, environment)
            messages += self.hitStep.perform(user, target, environment)
            if self.hitStep.hit:
                messages += self.damageStep.perform(user, target, environment)
                messages += self.effectsStep.perform(user, target, environment)
                messages += self.handleContactStep.perform(
                    user, target, environment)
            else:
                messages += self.handleMissEffectsStep.perform(
                    user, target, environment)

        return messages

    # Helper Methods
    def addDelegate(self, delegateCategory, delegate):
        """ Adds a delegate to an Attack Object """
        if delegateCategory == Tags.effectDelegateTag:
            self.effectDelegates.append(delegate)
            return
        setattr(self, delegateCategory, delegate)

    def isStatus(self):
        """ Returns if the Attack is a status attack """
        return isinstance(self.damageDelegate, NullDamageDelegate)
class perform(unittest.TestCase):
    """ Test cases of perform """
    
    def  setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.step = PreconditionStep(self.attack)
        self.preconditionMessages = ["My Precondition Messages"]
        self.attackMessages = ["My Attack Messages"]
        
        self.calledCheckPreConditions = False
        
    def preconditions_Failing(self):
        """ Test that failing precodnitions prevents the attack from being done """
        self.failPreconditions = False
        self.step.perform(None, None, None, PreconditionChecker=self.buildPreconditionChecker)
        
        self.assertTrue(self.calledCheckPreConditions, "Should have called checkPreconditions")
        
    def preconditions_Passing(self):
        """ Test that passing precodnitions allows the attack to be used """
        self.failPreconditions = True
        self.step.perform(None, None, None, PreconditionChecker=self.buildPreconditionChecker)
        
        self.assertTrue(self.calledCheckPreConditions, "Should have called checkPreconditions")
    
    def messagesReturned(self):
        """ Test that messages from the Preconditions Checker are returned """
        self.failPreconditions = False
        messages = self.step.perform(None, None, None, PreconditionChecker=self.buildPreconditionChecker)
        
        self.assertEquals(self.preconditionMessages, messages, "Should have returned the messages from the Preconditions check")
        
    def buildPreconditionChecker(self, user, target, environment, attack):
        return self
        
    def checkPreConditions(self):
        self.calledCheckPreConditions = True
        return self.failPreconditions, self.preconditionMessages
Example #7
0
class Attack:
    """ Represents an Attack """
    
    def __init__(self):
        self.hitDelegate = None
        self.damageDelegate = None
        self.speedDelegate = None
        
        self.effectDelegates = []
        self.makes_contact = False
        self.powerPoints = 0
        self.currPowerPoints = 0
        
        self.preconditionsStep = PreconditionStep(self)
        self.announcementStep = AnnouncementStep(self)
        self.removePPStep = RemovePPStep(self)
        self.hitStep = HitStep(self)
        self.damageStep = DamageStep(self)
        self.effectsStep = EffectsStep(self)
        self.handleContactStep = HandleContactStep(self)
        self.handleMissEffectsStep = HandleMissEffectsStep(self)
        
    def use(self, user, target, environment):
        """ Uses the current attack Object in a Battle """
        messages = []
        messages += self.preconditionsStep.perform(user, target, environment)
        if self.preconditionsStep.passed:
            messages += self.announcementStep.perform(user, target, environment)
            messages += self.removePPStep.perform(user, target, environment)
            messages += self.hitStep.perform(user, target, environment)
            if self.hitStep.hit:
                messages += self.damageStep.perform(user, target, environment)
                messages += self.effectsStep.perform(user, target, environment)
                messages += self.handleContactStep.perform(user, target, environment)
            else:
                messages += self.handleMissEffectsStep.perform(user, target, environment)
        
        return messages
        
    # Helper Methods
    def addDelegate(self, delegateCategory, delegate):
        """ Adds a delegate to an Attack Object """
        if delegateCategory == Tags.effectDelegateTag:
            self.effectDelegates.append(delegate)
            return
        setattr(self, delegateCategory, delegate)
        
    def isStatus(self):
        """ Returns if the Attack is a status attack """
        return isinstance(self.damageDelegate, NullDamageDelegate)
Example #8
0
 def __init__(self):
     self.hitDelegate = None
     self.damageDelegate = None
     self.speedDelegate = None
     
     self.effectDelegates = []
     self.makes_contact = False
     self.powerPoints = 0
     self.currPowerPoints = 0
     
     self.preconditionsStep = PreconditionStep(self)
     self.announcementStep = AnnouncementStep(self)
     self.removePPStep = RemovePPStep(self)
     self.hitStep = HitStep(self)
     self.damageStep = DamageStep(self)
     self.effectsStep = EffectsStep(self)
     self.handleContactStep = HandleContactStep(self)
     self.handleMissEffectsStep = HandleMissEffectsStep(self)