Пример #1
0
 def __init__(self, playerTrainer, oppTrainer):
     """ Builds the two participating sides of the battle """
     self.playerSide = BattleSide(playerTrainer)
     self.oppSide = BattleSide(oppTrainer)
     self.environment = BattleEnvironment()
     self.over = False
     self.round = BattleRound(self.playerSide, self.oppSide,
                              self.environment)
     self.eventQueue = deque()
     self.introduce()
class clearWeather(unittest.TestCase):
    """ Test cases of clearWeather """
    def setUp(self):
        """ Build the *** for the test """
        self.environment = BattleEnvironment()
        self.environment.weather = None

    def weatherCleared(self):
        """ Test that clearWeather sets the Environment's weather to the base Weather class """
        assert self.environment.weather is None, "Environment should have no weather"
        self.environment.clearWeather()
        assert self.environment.weather.type is None, "Environment should have weather with No Type"
class clearWeather(unittest.TestCase):
    """ Test cases of clearWeather """
    
    def  setUp(self):
        """ Build the *** for the test """
        self.environment = BattleEnvironment()
        self.environment.weather = None
        
    def weatherCleared(self):
        """ Test that clearWeather sets the Environment's weather to the base Weather class """
        assert self.environment.weather is None, "Environment should have no weather"
        self.environment.clearWeather()
        assert self.environment.weather.type is None, "Environment should have weather with No Type"
Пример #4
0
def BuildAttackAction(user=BuildPokemonBattleWrapper(),
                      target=BuildPokemonBattleWrapper(),
                      attack="TACKLE"):
    """ Builds an Attack Action """
    attack = BuildAttack(attack=attack)
    environment = BattleEnvironment()
    return AttackAction(attack, user, target, environment)
Пример #5
0
 def  setUp(self):
     """ Build the Pkmn and Delegate for the test """
     self.user = BuildPokemonBattleWrapper()
     self.target = BuildPokemonBattleWrapper()
     self.environment = BattleEnvironment()
     
     self.delegate = NullDamageDelegate()
Пример #6
0
 def  setUp(self):
     """ Build the Pkmn and Precondition Checker for the test """
     self.user = BuildPokemonBattleWrapper()
     self.target = BuildPokemonBattleWrapper()
     self.environment = BattleEnvironment()
     
     attack = AttackFactory.getAttackAsNew("TACKLE")
     self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, attack)
Пример #7
0
 def __init__(self, playerTrainer, oppTrainer):
     """ Builds the two participating sides of the battle """
     self.playerSide = BattleSide(playerTrainer)
     self.oppSide = BattleSide(oppTrainer)
     self.environment = BattleEnvironment()
     self.over = False
     self.round = BattleRound(self.playerSide, self.oppSide, self.environment)
     self.eventQueue = deque()
     self.introduce()
Пример #8
0
 def  setUp(self):
     """ Build the Pkmn and Delegate for the test """
     self.attack = BuildAttack()
     self.user = BuildPokemonBattleWrapper()
     self.target = BuildPokemonBattleWrapper()
     self.environment = BattleEnvironment()
     
     self.toHit = 100.0
     self.delegate = HitDelegate(self.attack, self.toHit)
Пример #9
0
class isCharging(unittest.TestCase):
    """ Test cases of isCharging """
    
    def  setUp(self):
        """ Build the Effect, Environment, and Pokemon for the test """
        self.turnToAttack = 1
        self.effect = WeatherChargeDelegate(2, self.turnToAttack, "Some Message", Hail.type)
        self.environment = BattleEnvironment()
        self.user = BuildPokemonBattleWrapper()
        
    def weatherCharged(self):
        """ Test that the weather can make the Attack be fully charged """
        self.environment.setWeather(self.effect.weatherType)
        assert not self.effect.isCharging(self.user, self.environment), "Effect should not be charging when the weather is right"
        
    def isCharging(self):
        """ Tests if isCharging returns correctly when it is charging """
        self.effect.turnOn = self.turnToAttack - 1
        assert self.effect.isCharging(self.user, self.environment), "Should be charging"
        
    def isNotCharging(self):
        """ Tests if isCharging returns correctly when it is not charging """
        self.effect.turnOn = self.turnToAttack
        assert not self.effect.isCharging(self.user, self.environment), "Should not be charging"
 def  setUp(self):
     """ Build the *** for the test """
     self.environment = BattleEnvironment()
     self.environment.weather = None
Пример #11
0
class Battle:
    """ Represents a Battle between two Trainers """
    
    def __init__(self, playerTrainer, oppTrainer):
        """ Builds the two participating sides of the battle """
        self.playerSide = BattleSide(playerTrainer)
        self.oppSide = BattleSide(oppTrainer)
        self.environment = BattleEnvironment()
        self.over = False
        self.round = BattleRound(self.playerSide, self.oppSide, self.environment)
        self.eventQueue = deque()
        self.introduce()
        
    def introduce(self):
        """ Introduces the battle """
        events = ["%s challenges you to a Pokemon Battle!" % self.getOppTrainer().getFullName()]
        events += self.sendOutPkmnToStart()
        self.addEvents(events)
        
    def sendOutPkmnToStart(self):
        """ Sends out Pkmn on both sides """
        events = []
        events += self.oppSide.sendOutPkmnAtStart()
        events += self.playerSide.sendOutPkmnAtStart()
        return events
        
    def removeEventFromQueue(self, event=None):
        """ Pops a message from the message queue if it has been fully displayed """
        if len(self.eventQueue) > 0:
            if self.eventQueue[0].fullyDisplayed:
                self.eventQueue.popleft()

    def update(self):
        """ Update the Battle object """
        
    def performRound(self, alreadySelectedActions):
        """  Performs a single round """
        self.round.run(alreadySelectedActions)
        self.addEvents(self.round.events)
        self.addEvents(self.betweenRounds())
        
    def betweenRounds(self):
        """ Perform between rounds """
        self.playerSide.betweenRounds()
        self.oppSide.betweenRounds()
        return self.environment.betweenRounds(self.playerSide, self.oppSide)
        
    def refillSides(self, pokemonReplacements):
        """ Refills fainted Pkmn on each side """
        self.checkOver()
        if not self.over:
            events = self.playerSide.refill(pokemonReplacements)
            events += self.oppSide.refill(pokemonReplacements)
            self.addEvents(events)
        
    def checkOver(self):
        """ Checks if the game is Over """
        self.checkOverForSide(self.playerSide)
        if not self.over:
            self.checkOverForSide(self.oppSide)
        
    def checkOverForSide(self, side):
        """ Checks if the game is over because the side has no Pkmn """
        if not side.hasPokemon():
            self.over = True
            self.addEvents([side.trainer.getBeatenMessage()])
        
    def addEvents(self, events):
        """ Adds the given events to the event queue """
        battleEvents = []
        for event in events:
            battleEvents.append(event)
        
        self.eventQueue += deque(battleEvents)
        
    def noEvents(self):
        """ Returns if there are no events in the event queue """
        return len(self.eventQueue) == 0
        
    def getPlayerTrainer(self):
        """ Returns the Player Trainer """
        return self.playerSide.trainer
        
    def getOppTrainer(self):
        """ Returns the Opposing Trainer """
        return self.oppSide.trainer
        
    def getPlayerPkmn(self):
        """ Returns the Pokemon currently out """
        return self.playerSide.pkmnInPlay
        
    def getOppPkmn(self):
        """ Returns the Pokemon currently out """
        return self.oppSide.pkmnInPlay
Пример #12
0
 def  setUp(self):
     """ Build the Effect, Environment, and Pokemon for the test """
     self.turnToAttack = 1
     self.effect = WeatherChargeDelegate(2, self.turnToAttack, "Some Message", Hail.type)
     self.environment = BattleEnvironment()
     self.user = BuildPokemonBattleWrapper()
Пример #13
0
 def setUp(self):
     """ Build the Pkmn and Delegate for the test """
     self.delegate = AlwaysHitDelegate("")
     self.environment = BattleEnvironment()
 def setUp(self):
     """ Build the *** for the test """
     self.environment = BattleEnvironment()
     self.environment.weather = None
Пример #15
0
 def setUp(self):
     """ Grabs the message dictionary from StatModDelegate """
     self.environment = BattleEnvironment()
     self.pkmn = BuildPokemonBattleWrapper()
     self.delegate = ChargeDelegate(2, 0, "")
Пример #16
0
class Battle:
    """ Represents a Battle between two Trainers """
    def __init__(self, playerTrainer, oppTrainer):
        """ Builds the two participating sides of the battle """
        self.playerSide = BattleSide(playerTrainer)
        self.oppSide = BattleSide(oppTrainer)
        self.environment = BattleEnvironment()
        self.over = False
        self.round = BattleRound(self.playerSide, self.oppSide,
                                 self.environment)
        self.eventQueue = deque()
        self.introduce()

    def introduce(self):
        """ Introduces the battle """
        events = [
            "%s challenges you to a Pokemon Battle!" %
            self.getOppTrainer().getFullName()
        ]
        events += self.sendOutPkmnToStart()
        self.addEvents(events)

    def sendOutPkmnToStart(self):
        """ Sends out Pkmn on both sides """
        events = []
        events += self.oppSide.sendOutPkmnAtStart()
        events += self.playerSide.sendOutPkmnAtStart()
        return events

    def removeEventFromQueue(self, event=None):
        """ Pops a message from the message queue if it has been fully displayed """
        if len(self.eventQueue) > 0:
            if self.eventQueue[0].fullyDisplayed:
                self.eventQueue.popleft()

    def update(self):
        """ Update the Battle object """

    def performRound(self, alreadySelectedActions):
        """  Performs a single round """
        self.round.run(alreadySelectedActions)
        self.addEvents(self.round.events)
        self.addEvents(self.betweenRounds())

    def betweenRounds(self):
        """ Perform between rounds """
        self.playerSide.betweenRounds()
        self.oppSide.betweenRounds()
        return self.environment.betweenRounds(self.playerSide, self.oppSide)

    def refillSides(self, pokemonReplacements):
        """ Refills fainted Pkmn on each side """
        self.checkOver()
        if not self.over:
            events = self.playerSide.refill(pokemonReplacements)
            events += self.oppSide.refill(pokemonReplacements)
            self.addEvents(events)

    def checkOver(self):
        """ Checks if the game is Over """
        self.checkOverForSide(self.playerSide)
        if not self.over:
            self.checkOverForSide(self.oppSide)

    def checkOverForSide(self, side):
        """ Checks if the game is over because the side has no Pkmn """
        if not side.hasPokemon():
            self.over = True
            self.addEvents([side.trainer.getBeatenMessage()])

    def addEvents(self, events):
        """ Adds the given events to the event queue """
        battleEvents = []
        for event in events:
            battleEvents.append(event)

        self.eventQueue += deque(battleEvents)

    def noEvents(self):
        """ Returns if there are no events in the event queue """
        return len(self.eventQueue) == 0

    def getPlayerTrainer(self):
        """ Returns the Player Trainer """
        return self.playerSide.trainer

    def getOppTrainer(self):
        """ Returns the Opposing Trainer """
        return self.oppSide.trainer

    def getPlayerPkmn(self):
        """ Returns the Pokemon currently out """
        return self.playerSide.pkmnInPlay

    def getOppPkmn(self):
        """ Returns the Pokemon currently out """
        return self.oppSide.pkmnInPlay
Пример #17
0
 def  setUp(self):
     """ Build the Effect, Environment, and Pokemon for the test """
     self.turnToAttack = 1
     self.effect = WeatherChargeDelegate(2, self.turnToAttack, "Some Message", Hail.type)
     self.environment = BattleEnvironment()
     self.user = BuildPokemonBattleWrapper()