Example #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()
Example #2
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()
Example #3
0
def BuildPokemonBattleWrapper(pkmn="BULBASAUR", trainer=Trainer()):
    """  Builds a Pokemon Battle Wrapper """
    pokemon = BuildPokemon(pkmn=pkmn)
    trainer.beltPokemon = [pokemon]

    side = BattleSide(trainer)
    wrapper = PkmnBattleWrapper(side)
    wrapper.setPkmn(pokemon)

    return wrapper
Example #4
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
Example #5
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
Example #6
0
def BuildBattleSide():
    """ Builds a Battle Side """
    trainer = BuildTrainer()
    side = BattleSide(trainer)
    side.sendOutPkmnAtStart()
    return side
Example #7
0
def BuildBattleSide():
    """ Builds a Battle Side """
    trainer = BuildTrainer()
    side = BattleSide(trainer)
    side.sendOutPkmnAtStart()
    return side