Example #1
0
class perform(unittest.TestCase):
    """ Test cases of perform """
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.damageDelegate = self
        self.step = DamageStep(self.attack)

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

    def usedDamageDelegate(self):
        """ Test that failing hit is handled """
        self.step.perform(None, None, None)

        self.assertTrue(
            self.calledDoDamage,
            "Should have called damage delegate's damage function")

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

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

    def doDamage(self, user, target, environment):
        self.calledDoDamage = True
        return self.messages
class perform(unittest.TestCase):
    """ Test cases of perform """
    
    def  setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.damageDelegate = self
        self.step = DamageStep(self.attack)
        
        self.messages = ["My Test Messages"]
        self.calledDoDamage = False
        
    def usedDamageDelegate(self):
        """ Test that failing hit is handled """
        self.step.perform(None, None, None)
        
        self.assertTrue(self.calledDoDamage, "Should have called damage delegate's damage function")
    
    def messagesReturned(self):
        """ Test that messages from a missed hit attempt are returned """
        messages = self.step.perform(None, None, None)
        
        self.assertEquals(self.messages, messages, "Should have returned the damage messages")
        
    def doDamage(self, user, target, environment):
        self.calledDoDamage = True
        return self.messages
Example #3
0
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.damageDelegate = self
        self.step = DamageStep(self.attack)

        self.messages = ["My Test Messages"]
        self.calledDoDamage = False
 def  setUp(self):
     """ Build the Step for the test """
     self.attack = Attack()
     self.attack.damageDelegate = self
     self.step = DamageStep(self.attack)
     
     self.messages = ["My Test Messages"]
     self.calledDoDamage = False
Example #5
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 #6
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 #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)