def test_attack_print_output_when_hit_and_enemy_dies(self, mock_randint, mock_stdout): expected_output = "You strike!\n" \ "The Imperial Officer has taken a 5 point hit!\n\n" \ "You have defeated the Imperial Officer.\n" \ "We are one step closer to peace in the galaxy!\n\n" attack(2) self.assertEqual(expected_output, mock_stdout.getvalue())
def move_monster(self, monster, coordinates): dx, dy = coordinates if self.can_walk_at(monster.x + dx, monster.y + dy): monster.x += dx monster.y += dy elif monster.player is not None: destination_monster = self.get_monster_at(monster.x + dx, monster.y + dy) if destination_monster is not None: attack(monster, destination_monster) return True return False
def runTest(): global a global b a = pb.make(50) b = pb.make(50) c = battle.attack(a,a["moves"][1],b) d = battle.EAttack(a,a["moves"][1],b) print(a["name"]," attacked ",b["name"]," with ", a["moves"][1]["name"], " for ",c, " damage. We expected ",d," damage." ) ct =0 for i in range(1000): ct += battle.attack(a,a["moves"][1],b)/1000 print(a["name"]," attacked ",b["name"]," with ", a["moves"][1]["name"], " for average",ct, " damage. We expected ",d," damage." )
def check(coordinates): # Calls attack if there're monsters in the room, Calls coinCount if there're treasures; else: room empty x = coordinates[0] y = coordinates[1] if ds.dungeon[x][y].monsters: # True if sequence/list contains values print(f"Monsters: {ds.dungeon[x][y].monsters}\n{ds.dungeon[x][y].treasure}") choice = input("1. Attack\n2. Escape") if choice == '1': battle.attack(hero, sort(ds.dungeon[x][y].monsters)) elif choice == '2': battle.escape(hero, sort(ds.dungeon[x][y].monsters)) if ds.dungeon[x][y].treasure: # True if sequence/list contains values print(f"There're treasures!\n{ds.dungeon[x][y].treasure}") coinCount(ds.dungeon[x][y].treasure) else: print("Room empty!")
def show_attack(attacker, defender, current_move): a = attacker d = defender battle_over = False temp_HP = defender.stats["HP"] battle_text_message = [] battle_text = [] battle.attack(attacker, defender, current_move) if temp_HP != defender.stats["HP"]: battle_text_message += ["", attacker.name + " used " +\ current_move + "!", ""] else: battle_text_message = [""] battle_text_message += [attacker.name + " used " +\ current_move] battle_text_message[1] += "... but it had no effect!" battle_text_message += [""] #print(attacker.name + " used " + current_move + "!") #print(defender.name + "'s HP fell from " + \ # str(temp_HP) + \ # " to " + str(defender.stats["HP"])) #print() if attacker.stats["HP"] == 0: battle_text_message += [ attacker.name + " fainted... " + defender.name + " wins!" ] battle_over = True return battle_over, battle_text if defender.stats["HP"] == 0: battle_text_message += [ defender.name + " fainted... " + attacker.name + " wins!" ] battle_over = True for i in range(len(battle_text_message)): battle_text += [ res["font"].render(battle_text_message[i], True, (0, 0, 0)) ] return battle_over, battle_text
def test_attack_when_miss_hp_unchanged(self, mock_randint): hp_before_attack = imperial_forces[4]["HP"] attack(4) self.assertEqual(imperial_forces[4]["HP"], hp_before_attack)
def test_attack_when_hit_damage_is_reflected_in_new_hp(self, mock_randint): hp_before_attack = imperial_forces[3]["HP"] attack(3) self.assertEqual(imperial_forces[3]["HP"], hp_before_attack - 3)
def test_attack_print_output_when_hit_and_enemy_survives(self, mock_randint, mock_stdout): expected_output = "You strike!\n" \ "The Shocktrooper has taken a 2 point hit!\n" \ "Their HP has dropped to 3.\n\n" attack(1) self.assertEqual(expected_output, mock_stdout.getvalue())
def test_attack_print_output_when_miss(self, mock_randint, mock_stdout): expected_output = "You strike!\n" \ "The Stormtrooper evaded the attack!\n\n" attack(0) self.assertEqual(expected_output, mock_stdout.getvalue())
def use_ability(cls, monster): attack(monster, monster.target) cls.reset_turn(monster)