class getMessageSlice(unittest.TestCase): """ Test cases of getMessageSlice """ MESSAGE_STR = "1234567890" def setUp(self): """ Build the BattleMessage for the test """ self.message = BattleMessage(self.MESSAGE_STR) def slice(self): """ Test that a slice of the Battle Message is returned properly """ sliceIndex = 2 originalSlice = self.MESSAGE_STR[:sliceIndex] messageSlice = self.message.getMessageSlice(sliceIndex) assert originalSlice == messageSlice, "Message slice does not match the slice from the original string" assert not self.message.fullyDisplayed, "Message should not have fullyDisplayed" def fullMessage(self): """ Test that a slice of the Battle Message is returned properly """ sliceIndex = len(self.MESSAGE_STR) originalSlice = self.MESSAGE_STR[:sliceIndex] messageSlice = self.message.getMessageSlice(sliceIndex) assert originalSlice == messageSlice, "Message slice should be the original string" assert self.message.fullyDisplayed, "Message should have fullyDisplayed"
def setAction(self, entry): """ Set the Chosen Action """ if self.pokemon.isPokemon(entry.getPokemon()): self.runController(MessageBoxController(BattleMessage("{0} is already out.".format(self.pokemon.name)), self.screen)) elif entry.getPokemon().fainted(): self.runController(MessageBoxController(BattleMessage("{0} has no will to fight.".format(entry.getPokemon().name)), self.screen)) else: self.action = SwitchAction(self.pokemon, entry.getPokemon()) self.stopRunning()
def __init__(self, battle, screen): """ Initialize the Battle Message Controller """ self.battle = battle self.messageBox = MessageBox(BattleMessage("")) screen.messageBox = self.messageBox cmds = {ENDL:self.battle.removeMessageFromQueue} ConsoleController.__init__(self, screen, commands=cmds)
def setAction(self, entry): """ Set the Chosen Action """ if entry.getAttack().currPowerPoints == 0: self.runController( MessageBoxController( BattleMessage("No PP left for this attack."), self.screen)) else: self.action = AttackAction(entry.getAttack(), self.pokemon, self.targets[0], self.environment) self.stopRunning()
def PerformEvent(event, controller): """ Perform the given event """ eventController = None if isinstance(event, str): eventController = MessageBoxController(BattleMessage(event), controller.screen) elif isinstance(event, LearnAttackEvent): eventController = LearnAttackController(event, controller.screen) if eventController is not None: controller.runController(eventController)
def setUp(self): """ Build the BattleMessage for the test """ self.message = BattleMessage(self.MESSAGE_STR)
def buildMessageBox(self): """ Builds a Message Box """ battleMessage = BattleMessage("{0}'s first Pkmn is {1}.".format(self.entries[self.selectedIndex].entry.trainer.name, self.entries[self.selectedIndex].entry.trainer.beltPokemon[0].name)) self.messageBox = MessageBox(battleMessage)
def presentMessages(self, messages): """ Present the given messages """ for message in messages: self.runController( MessageBoxController(BattleMessage(message), self.screen))
def getYesNoResponse(self, message): """ Return the Yes/No Response """ yesNoController = YesNoController(BattleMessage(message), self.screen) self.runController(yesNoController) return yesNoController.answer