class TestBattle(unittest.TestCase): def setUp(self) -> None: self.first_army = Army(Side.Monsters) self.first_army.add(DragonSquad(self.first_army.side, 4)) self.battle = Battle(self.first_army) def test_Winner(self): self.assertEqual(self.battle.battle(), 0)
def attack(self, battle_element): at, df, wp, map, pos = battle_element battle = Battle(at, df, wp, df.item[0], map, pos) res = battle.battle() del battle obj = self.person[at.pid] action = self._sequential_move(self.select, self.dst) obj.do(action + CallFunc(self._battle_scene, res) + CallFunc(self.clear_map) + CallFunc(self.take_turn))
def main(): # obtener los datos de los pokemons pokemon_1_name = input("Indica el nombre del primer pokemon: ") pokemon_1_attack = get_correct_attack_value( "Indica la potencia de ataque del primer pokemon. Valor de 1 a 100. :") pokemon_2_name = input("Indica el nombre del segundo pokemon :") pokemon_2_attack = get_correct_attack_value( "Indica la potencia de ataque del segundo pokemon. Valor de 1 a 100. :" ) # generar aleatoriamente un valor 0 o 1 r_turn = random.randint(0, 1) # asignar al primer pokemon el valor de turno aleatorio y al segundo el contrario pokemon_1 = Pokemon(pokemon_1_name, pokemon_1_attack, r_turn) pokemon_2 = Pokemon(pokemon_2_name, pokemon_2_attack, int(not r_turn)) b = Battle(pokemon_1, pokemon_2) b.battle()
def main(): player = Player() printIntro() choice = 'yes' no = ['no', 'n'] yes = ['yes', 'y', 'ye'] while player.getPurse() > 0 and choice not in no: print "You have", player.getPurse(), "in your pouch.\n" battle = Battle() print "\nThe next battle is between %s and %s.\n" % ( battle.warrior1.getName(), battle.warrior2.getName()) announceWarriors(battle.warrior1, battle.odds1, battle.warrior2, battle.odds2) print "\nDo you want to bet?\n\n" player.getChoice(battle.warrior1, battle.warrior2) winner, odds = battle.battle() if winner == player.getPick(): player.updatePurse("win", player.getBet(), odds) else: player.updatePurse("lose", player.getBet(), odds) print "\nWould you like to bet on the next battle?\n" while True: try: choice = string.lower(str(raw_input(">> "))) if choice in yes: break elif choice in no: choice = 'no' break else: print "\nPlease choose yes or no.\n" continue except ValueError: print "\nPlease choose yes or no.\n" continue print "\nThank you so much for playing!\n" if player.getPurse() > 1: print "\nYou leave the Colosseum with %d coins in your purse.\n" % player.getPurse( ) elif player.getPurse() == 1: print "\nYou leave the Colosseum with one coin, not even another to rub it against.\n" else: print "\nYou're leaving dead broke!\n"
def main(): player = Player() printIntro() choice = 'yes' no = ['no','n'] yes = ['yes','y','ye'] while player.getPurse() > 0 and choice not in no: print "You have", player.getPurse(),"in your pouch.\n" battle = Battle() print "\nThe next battle is between %s and %s.\n" % (battle.warrior1.getName(),battle.warrior2.getName()) announceWarriors(battle.warrior1,battle.odds1,battle.warrior2,battle.odds2) print "\nDo you want to bet?\n\n" player.getChoice(battle.warrior1,battle.warrior2) winner, odds = battle.battle() if winner == player.getPick(): player.updatePurse("win",player.getBet(),odds) else: player.updatePurse("lose",player.getBet(),odds) print "\nWould you like to bet on the next battle?\n" while True: try: choice = string.lower(str(raw_input(">> "))) if choice in yes: break elif choice in no: choice = 'no' break else: print "\nPlease choose yes or no.\n" continue except ValueError: print "\nPlease choose yes or no.\n" continue print "\nThank you so much for playing!\n" if player.getPurse() > 1: print "\nYou leave the Colosseum with %d coins in your purse.\n" % player.getPurse() elif player.getPurse() == 1: print "\nYou leave the Colosseum with one coin, not even another to rub it against.\n" else: print "\nYou're leaving dead broke!\n"
def step(self, text): if self.player is not None: if self.player.state == "BATTLE": battle = Battle(self.player.userId) reply = battle.battle() if battle.isFinish == True: world = World(self.player.userId) imageURI = world.getInitMap() reply['battlefinished'] = imageURI return reply elif self.player.state == "WORLD": world = World(self.player.userId) imageURI = world.move(text) encount, enemyInfo = world.randomEncount() if encount: self.player.state = "BATTLE" return { "img": [imageURI, enemyInfo["img"]], "text": [enemyInfo["text"]] } return {"worldImg": [imageURI]} else: return {"text": ["still not implemented"]}
def main(): A = Battle() A.battle()