Exemplo n.º 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())
Exemplo n.º 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!")
Exemplo n.º 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")
Exemplo n.º 4
0
 def test_set_hp_changed_from_original(self):
     original = rebel["HP"]
     set_hp(4)
     self.assertNotEqual(original, rebel["HP"])
Exemplo n.º 5
0
 def test_set_hp_with_positive_int(self):
     set_hp(8)
     self.assertEqual(rebel["HP"], 8)
Exemplo n.º 6
0
 def test_set_hp_with_0(self):
     set_hp(0)
     self.assertEqual(rebel["HP"], 0)
Exemplo n.º 7
0
def reset_game() -> None:
    """Reset character HP and position."""
    rebel.set_hp(10)
    rebel.set_row(5)
    rebel.set_column(5)
Exemplo n.º 8
0
 def test_get_hp_after_modified_hp(self):
     rebel.set_hp(5)
     self.assertIs(get_hp(), rebel.rebel["HP"])