def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.name = "Test Attack"
        self.step = AnnouncementStep(self.attack)

        self.header = "Header"
        self.calledGetHeader = False
class perform(unittest.TestCase):
    """ Test cases of perform """
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.attack.name = "Test Attack"
        self.step = AnnouncementStep(self.attack)

        self.header = "Header"
        self.calledGetHeader = False

    def announcementCreated(self):
        """ Test that the announcement message was created """
        messages = self.step.perform(self, None, None)

        self.assertEquals(1, len(messages), "Should have a single message")
        self.assertTrue(self.calledGetHeader,
                        "Should have used the user getHeader function")
        self.assertIn(self.header, messages[0],
                      "Should contain the user header")
        self.assertIn(self.attack.name, messages[0],
                      "Should contain the attack name")

    def getHeader(self):
        self.calledGetHeader = True
        return self.header
 def  setUp(self):
     """ Build the Step for the test """
     self.attack = Attack()
     self.attack.name = "Test Attack"
     self.step = AnnouncementStep(self.attack)
     
     self.header = "Header"
     self.calledGetHeader = False
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 7
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.name = "Test Attack"
        self.step = AnnouncementStep(self.attack)
        
        self.header = "Header"
        self.calledGetHeader = False
        
    def announcementCreated(self):
        """ Test that the announcement message was created """
        messages = self.step.perform(self, None, None)
        
        self.assertEquals(1, len(messages), "Should have a single message")
        self.assertTrue(self.calledGetHeader, "Should have used the user getHeader function")
        self.assertIn(self.header, messages[0], "Should contain the user header")
        self.assertIn(self.attack.name, messages[0], "Should contain the attack name")
        
    def getHeader(self):
        self.calledGetHeader = True
        return self.header