def combat_round(index: int) -> None: """Round of combat to the death. PRECONDITION: index must be an int representing an existing index in imperial_forces POSTCONDITION: Fight member of imperial force corresponding to index""" print("\n" + line + "\n%s: Prepare to die, rebel scum!!\n" % imperial.get_name(index)) while rebel.get_hp() > 0 and imperial.get_hp(index) > 0: attack(index) if imperial.get_hp(index) <= 0: break else: defend(index) if rebel.get_hp() > 0: print("Your HP is %d.\n\n" % rebel.get_hp() + line) # reset imperial force's HP to 5 for next encounter imperial.set_hp(index, 5)
def attack(index: int) -> None: """Attack the enemy. PRECONDITION: index must be an int representing an existing index in imperial_forces POSTCONDITION: Attack member of imperial force corresponding to index""" print("You strike!") # determine if hit was effective if randint(1, 15) > imperial.get_dexterity(index): damage = randint(1, 6) imperial.set_hp(index, imperial.get_hp(index) - damage) print("The %s has taken a %d point hit!" % (imperial.get_name(index), damage)) if imperial.get_hp(index) <= 0: print("\nYou have defeated the %s.\n" "We are one step closer to peace in the galaxy!\n" % imperial.get_name(index)) else: print("Their HP has dropped to %d.\n" % imperial.get_hp(index)) else: print("The %s evaded the attack!\n" % imperial.get_name(index))
def test_set_hp_with_positive_int(self): for i in range(len(imperial_forces)): set_hp(i, 8) self.assertIs(imperial_forces[i]["HP"], 8)
def test_set_hp_changed_from_original(self): for i in range(len(imperial_forces)): original = imperial.get_hp(i) set_hp(i, 3) self.assertIsNot(original, imperial_forces[i]["HP"])
def test_set_hp_with_0(self): for i in range(len(imperial_forces)): set_hp(i, 0) self.assertIs(imperial_forces[i]["HP"], 0)