def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.hitDelegate = self
        self.step = HitStep(self.attack)

        self.messages = ["My Test Messages"]
        self.calledHit = False
Beispiel #2
0
 def  setUp(self):
     """ Build the Step for the test """
     self.attack = Attack()
     self.attack.hitDelegate = self
     self.step = HitStep(self.attack)
     
     self.messages = ["My Test Messages"]
     self.calledHit = False
Beispiel #3
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)
Beispiel #4
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)
Beispiel #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)
Beispiel #6
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)
class perform(unittest.TestCase):
    """ Test cases of perform """
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.hitDelegate = self
        self.step = HitStep(self.attack)

        self.messages = ["My Test Messages"]
        self.calledHit = False

    def hit_Failing(self):
        """ Test that failing hit is handled """
        self.shouldHit = False
        self.step.perform(None, None, None)

        self.assertTrue(self.calledHit,
                        "Should have called hit delegate's hit function")
        self.assertFalse(self.step.hit, "Should not have successfully hit")

    def hit_Passing(self):
        """ Test that passing hit ais handled """
        self.shouldHit = True
        self.step.perform(None, None, None)

        self.assertTrue(self.calledHit,
                        "Should have called hit delegate's hit function")
        self.assertTrue(self.step.hit, "Should have successfully hit")

    def messagesReturned_Missed(self):
        """ Test that messages from a missed hit attempt are returned """
        self.shouldHit = False
        messages = self.step.perform(None, None, None)

        self.assertEquals(self.messages, messages,
                          "Should have returned the hit messages")

    def messagesReturned_Hit(self):
        """ Test that messages from a successful hit attempt are returned """
        self.shouldHit = True
        messages = self.step.perform(None, None, None)

        self.assertEquals([], messages,
                          "Should have returned the hit messages")

    def hit(self, user, target, environment):
        self.calledHit = True
        return self.shouldHit, self.messages
Beispiel #8
0
class perform(unittest.TestCase):
    """ Test cases of perform """
    
    def  setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.hitDelegate = self
        self.step = HitStep(self.attack)
        
        self.messages = ["My Test Messages"]
        self.calledHit = False
        
    def hit_Failing(self):
        """ Test that failing hit is handled """
        self.shouldHit = False
        self.step.perform(None, None, None)
        
        self.assertTrue(self.calledHit, "Should have called hit delegate's hit function")
        self.assertFalse(self.step.hit, "Should not have successfully hit")
        
    def hit_Passing(self):
        """ Test that passing hit ais handled """
        self.shouldHit = True
        self.step.perform(None, None, None)
        
        self.assertTrue(self.calledHit, "Should have called hit delegate's hit function")
        self.assertTrue(self.step.hit, "Should have successfully hit")
    
    def messagesReturned_Missed(self):
        """ Test that messages from a missed hit attempt are returned """
        self.shouldHit = False
        messages = self.step.perform(None, None, None)
        
        self.assertEquals(self.messages, messages, "Should have returned the hit messages")
        
    def messagesReturned_Hit(self):
        """ Test that messages from a successful hit attempt are returned """
        self.shouldHit = True
        messages = self.step.perform(None, None, None)
        
        self.assertEquals([], messages, "Should have returned the hit messages")
        
    def hit(self, user, target, environment):
        self.calledHit = True
        return self.shouldHit, self.messages