예제 #1
0
def play_game():
    print(
        'Controls:\n-Move up - w\n-Move down - s\n-Move left - a\n-Move right - d\n-Cast a spell out of fight - j\n'
    )

    hero_name = input('What\'s your name? ')
    hero = Hero(name=hero_name,
                title='Vagabond',
                health=100,
                mana=100,
                mana_regeneration_rate=2)
    weapon = Weapon(name='Wooden sword', damage=10)
    hero.equip(weapon)

    quit = False

    for i in range(1, 4):
        file_name = f'levels_and_treasures/level{i}.txt'
        dungeon = Dungeon(file_name)
        dungeon.create_treasures('levels_and_treasures/treasures.txt')
        dungeon.spawn(hero)

        print(f'{hero.known_as()} entered dungeon {i}')

        dungeon.print_map()
        while hero.is_alive() and not dungeon.hero_is_at_gateway():
            if get_player_move(dungeon):
                dungeon.print_map()

        if not hero.is_alive():
            print('GAME OVER')
            quit = True
            break
        hero.level_up()

        if i != 3 and not ask_to_continue():
            quit = True
            break

    if not quit:
        print('Congratulations, you won the game! :)')
예제 #2
0
 def test_is_alive(self):
     h = Hero(name="Pesho", title="The Great One", health=100, mana=10, mana_regeneration_rate=30)
     h.take_damage(120)
     self.assertEqual(False, h.is_alive())