예제 #1
0
def heal_character() -> None:
    """Heal character if they are not already at full health.

    >>> rebel.rebel["HP"] = 5
    >>> heal_character()
    You're healing! Your HP is 6.
    """
    if rebel.get_hp() < 10:
        rebel.set_hp(rebel.get_hp() + 1)
        print("You're healing! Your HP is %d." % rebel.get_hp())
예제 #2
0
def run_away(index: int) -> None:
    """Run away from enemy.

    PRECONDITION: index must be an int representing an existing index in imperial_forces
    POSTCONDITION: Run away from member of imperial force corresponding to index"""

    # determine if character was struck while running
    if randint(1, 5) == 1:
        damage = randint(1, 4)
        rebel.set_hp(rebel.get_hp() - damage)
        print(
            "\n" + line +
            "\nThe %s struck you as you fled!\n\nYou have taken a %d point hit, your HP is %d."
            % (imperial.get_name(index), damage, rebel.get_hp()))
    else:
        print("\n" + line + "\nYou fled the scene unharmed!")
예제 #3
0
def defend(index: int) -> None:
    """Character on defence against enemy attack.

    PRECONDITION: index must be an int representing an existing index in imperial_forces
    POSTCONDITION: Defend against member of imperial force corresponding to index"""

    print("The %s strikes!" % imperial.get_name(index))
    # determine if hit was effective
    if randint(1, 15) > rebel.get_dexterity():
        damage = randint(1, 6)
        rebel.set_hp(rebel.get_hp() - damage)
        print("You have taken a %d point hit!" % damage)
        if rebel.get_hp() <= 0:
            print(
                "You have been defeated.\n\n%s: Never underestimate the power of the Dark Side.\n"
                % imperial.get_name(index))
        else:
            print("Your HP has dropped to %d.\n" % rebel.get_hp())
    else:
        print("You evaded the attack!\n")
예제 #4
0
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)
예제 #5
0
def restart_or_exit() -> None:
    """Restart or exit game if player is defeated."""
    if rebel.get_hp() <= 0:
        play_again = ""
        while play_again != "n" and play_again != "y":
            play_again = input(
                line +
                "\nYou have been defeated by the Galactic Empire. Play again? (y/n): "
            )
            if play_again == "n":
                user_quit("quit")
            elif play_again == "y":
                reset_game()
    game_map()
예제 #6
0
def encounter_enemy(index: int) -> None:
    """Encounter member of imperial force.

    PRECONDITION: index must be an int representing an existing index in imperial_forces
    POSTCONDITION: Encounters member of imperial force corresponding to index"""

    fight_or_run = ""
    while fight_or_run != "f" and fight_or_run != "r":
        fight_or_run = input(
            "\nYou have encountered a(n) %s!\n\nYour current have %dHP. 'f' to fight"
            ", 'r' to run away: " %
            (imperial.get_name(index), rebel.get_hp())).strip().lower()
        if fight_or_run == "f":
            combat_round(index)
        elif fight_or_run == "r":
            run_away(index)
예제 #7
0
 def test_get_hp_after_modified_hp(self):
     rebel.set_hp(5)
     self.assertIs(get_hp(), rebel.rebel["HP"])
예제 #8
0
 def test_get_hp_before_game_play(self):
     self.assertIs(get_hp(), rebel.rebel["HP"])
예제 #9
0
 def test_get_hp_return_type(self):
     self.assertIsInstance(get_hp(), int)