コード例 #1
0
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.step = HandleContactStep(self.attack)

        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()

        self.user.getAbility().onContact = self.onContact
        self.target.getAbility().onContact = self.onContact

        self.hitPkmn = None
        self.calledOnContact = 0
        self.messages = ["My Test Message"]
コード例 #2
0
ファイル: attack.py プロジェクト: TimChau/Pokemon-Project
    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)
コード例 #3
0
class perform(unittest.TestCase):
    """ Test cases of perform """
    def setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.step = HandleContactStep(self.attack)

        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()

        self.user.getAbility().onContact = self.onContact
        self.target.getAbility().onContact = self.onContact

        self.hitPkmn = None
        self.calledOnContact = 0
        self.messages = ["My Test Message"]

    def makesContact(self):
        """ Test that when the attack makes contact the targets contact effect is used """
        self.attack.makes_contact = True

        messages = self.step.perform(self.user, self.target, None)

        self.assertIs(self.target, self.hitPkmn,
                      "Should have called onContact for the Target Pkmn")
        self.assertEquals(1, self.calledOnContact,
                          "Should have called onContact only once")
        self.assertEquals(self.messages, messages,
                          "Should receive messages from the onContact")

    def doesNotMakeContact(self):
        """ Test that when the attack does not make contact nothing happens """
        self.attack.makes_contact = False

        messages = self.step.perform(self.user, self.target, None)

        self.assertEquals(0, self.calledOnContact,
                          "Should not have called onContact")
        self.assertEquals([], messages, "Should receive no messages")

    def onContact(self, pkmnHit, pkmnWhoAttacked):
        self.hitPkmn = pkmnHit
        self.calledOnContact += 1
        return self.messages
コード例 #4
0
class perform(unittest.TestCase):
    """ Test cases of perform """
    
    def  setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.step = HandleContactStep(self.attack)
        
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
        self.user.getAbility().onContact = self.onContact
        self.target.getAbility().onContact = self.onContact
        
        self.hitPkmn = None
        self.calledOnContact = 0
        self.messages = ["My Test Message"]
        
    def makesContact(self):
        """ Test that when the attack makes contact the targets contact effect is used """
        self.attack.makes_contact = True
        
        messages = self.step.perform(self.user, self.target, None)
        
        self.assertIs(self.target, self.hitPkmn, "Should have called onContact for the Target Pkmn")
        self.assertEquals(1, self.calledOnContact, "Should have called onContact only once")
        self.assertEquals(self.messages, messages, "Should receive messages from the onContact")
        
    def doesNotMakeContact(self):
        """ Test that when the attack does not make contact nothing happens """
        self.attack.makes_contact = False
        
        messages = self.step.perform(self.user, self.target, None)
        
        self.assertEquals(0, self.calledOnContact, "Should not have called onContact")
        self.assertEquals([], messages, "Should receive no messages")
        
    def onContact(self, pkmnHit, pkmnWhoAttacked):
        self.hitPkmn = pkmnHit
        self.calledOnContact += 1
        return self.messages
コード例 #5
0
ファイル: attack.py プロジェクト: TimChau/Pokemon-Project
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)
コード例 #6
0
 def  setUp(self):
     """ Build the Step for the test """
     self.attack = Attack()
     self.step = HandleContactStep(self.attack)
     
     self.user = BuildPokemonBattleWrapper()
     self.target = BuildPokemonBattleWrapper()
     
     self.user.getAbility().onContact = self.onContact
     self.target.getAbility().onContact = self.onContact
     
     self.hitPkmn = None
     self.calledOnContact = 0
     self.messages = ["My Test Message"]
コード例 #7
0
ファイル: attack.py プロジェクト: cloew/Pokemon-Project
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)
コード例 #8
0
ファイル: attack.py プロジェクト: cloew/Pokemon-Project
 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)