Exemplo n.º 1
0
def reset_hero_attributes(hero: Hero):
    from items.weapon import Weapon
    from items.spell import Spell
    hero.health = hero.MAX_HEALTH
    hero.mana = hero.MAX_MANA
    hero.weapon = Weapon.create_weapon(random.choice(WEAPON_NAMES))
    hero.spell = Spell.create_spell(random.choice(SPELL_NAMES))
    def test_if_reset_hero_attributes_works_correctly(self):
        hero = Hero()
        hero.MAX_MANA = 100
        hero.MAX_HEALTH = 100

        reset_hero_attributes(hero)
        self.assertEqual(hero.health, 100)
        self.assertEqual(hero.mana, 100)
    def test_if_attack_with_spell_range_works_when_cast_range_is_0(self):
        health = 1
        hero = Hero()
        hero.spell = Spell(cast_range=0)
        enemy = Enemy(health=health)

        attack_with_spell_range(hero, enemy)
        self.assertEqual(enemy.health, health)
    def test_if_attack_with_spell_range_works_when_enemy_is_killed_during_the_attack(self):
        health = 1
        hero = Hero()
        hero.spell = Spell(damage=1, cast_range=1)
        enemy = Enemy(health=health)

        exp = 0

        attack_with_spell_range(hero, enemy)
        self.assertEqual(enemy.health, exp)
    def test_if_regular_fight_works_when_enemy_is_killed_during_the_fight(self):
        health = 1
        hero = Hero(health=health)
        hero.weapon = Weapon(damage=1)
        enemy = Enemy(health=health)

        exp = 0

        regular_fight(hero, enemy)
        self.assertEqual(enemy.health, exp)
Exemplo n.º 6
0
def attack_with_spell_range(hero: Hero, enemy: Enemy):
    spell_attack_counter = 0

    while hero.can_cast() and spell_attack_counter < hero.spell.cast_range:

        enemy.take_damage(hero.attack_by_spell())
        spell_attack_counter += 1

        print_entity_name_and_health('Enemy', enemy.health)
        if not enemy.is_alive():
            print_has_been_slain('Enemy')
            break
        print(f'Enemy moves closer!')
Exemplo n.º 7
0
def regular_fight(hero: Hero, enemy: Enemy):
    while True:
        enemy.take_damage(hero.attack())
        print_entity_name_and_health('Enemy', enemy.health)

        if not enemy.is_alive():
            print_has_been_slain('Enemy')
            break

        hero.take_damage(enemy.attack())
        print_hero_takes_damage(hero, enemy)
        print_entity_name_and_health(hero.name, hero.health)

        if not hero.is_alive():
            print_has_been_slain(hero.known_as())
            break
    def test_if_spawn_hero_works_correctly(self):
        hero = Hero()
        dungeon = Dungeon('test_valid_map.txt')
        exp = [['.', '.', '.', '.', '.', '.', '.', '.', 'H'],
               ['#', '#', '#', '#', '.', '.', 'T', '.', 'E'],
               ['.', '.', '.', 'G', '.', '.', 'S', '.', 'T']]

        dungeon.spawn(hero)
        self.assertEqual(exp, dungeon.dungeon_map)
        self.assertIs(hero, dungeon.hero)
Exemplo n.º 9
0
def main():
    hero = Hero.create_hero()
    dungeon = Dungeon('dungeon_module/level1.txt')
    dungeon.spawn(hero)
    DisplayInfo.display_intro()
    clear_screen()

    while not end_game(dungeon) and dungeon.hero.is_alive():
        dungeon.print_map()
        print_ask_direction(hero)

        try:
            choice = get_key_input()
            check_choice(choice, dungeon)
        except Exception as e:
            print(e)
            input('\nPress Enter to continue...')

        clear_screen()
    clear_screen()
Exemplo n.º 10
0
# Liste de tout les sprites du jeux ( pour avoir un ensemble, utile pour le coté joueur en code)
all_sprites_list = pygame.sprite.Group()

# Liste des block (max appel là comme tu le sent juste un réfractoring fonctionnera avec moi)
monsterList = pygame.sprite.Group()

# Liste de chaque balle tiré
bullet_list = pygame.sprite.Group()

NbMonster = 25

# ICI ON INSTANCIE LES BLOCKS (chronologiquement pour que le code ne fasse pas d'erreur)

# On instancie le héro
hero = Hero()
all_sprites_list.add(hero)
Monster.containers = monsterList
imageLevel = ""

myfont = pygame.font.SysFont("Arial", 15)
title = myfont.render("Appuyez sur espace pour commencer",0, (0, 0, 0))

def displayMonster(nb, speed):
    column = 0
    line = 0
    for i in range(0, nb):
        if i % 9 == 0:
            column = column + 1
            line = 0
        else:
Exemplo n.º 11
0
def main():

    #Create's a hero with the chosen name
    name = input("What is the hero's name? : ")
    hero = Hero(name)

    #Creating boss
    boss = Creature(7)

    print("You start your glorious adventure! \n")

    #Create's a list of rooms for  the hero to move through
    roomList = generate_rooms()
    currentRoom = 0

    #Main gameplay loop
    while True:

        #If this is true, that means currentRoom has been incremented past the roomList index
        #And there aren't any rooms left to go through so the hero won
        if currentRoom == Room.numberOfRooms:
            break

        #Runs a function that prints the name of the room and gives a description
        roomList[currentRoom].room_description()

        #Makes a shorter reference to improve readability
        monsterList = roomList[currentRoom].monsterList

        #Sets the initiative for all the monsters
        roll_for_initiative(hero, monsterList)

        #Makes it so the monster with the highest initiative is in index 0
        monsterList.sort(reverse=True)

        #If the monster's initiative is higher, he gets to attack first
        if (monsterList[0].initiative > hero.initiative):
            print(monsterList[0].name + " got the jump on the hero!\n")
            monsterList[0].attack(hero)
        while True:

            #Prompts the user for what he wants to do
            use_menu(hero, roomList[currentRoom])

            #If the user has successfully completed the room, set the currentRoom index one higher
            #So the next loop uses the next room's information
            if roomList[currentRoom].movingRooms == True:
                currentRoom += 1
                break

            #Checks to see if there's monsters
            elif roomList[currentRoom].cleared == False:
                print("")
                monsterList[0].attack(hero)  #First monster attacks the player
                #Checks to see if the player died
                if hero.is_dead():
                    print("The hero is dead!")
                    exit()

    print(
        "You have succeeded in your quest to escape The Overlord's strong hold"
    )
    def test_if_attack_by_spell_returns_spell_damage(self):
        h = Hero()
        h.spell = Spell('Fireball', 10, 5, 1)

        self.assertEqual(h.attack(), 10)
    def test_if_attack_returns_weapon_damagae_if_it_is_stronger(self):
        h = Hero()
        h.spell = Spell('Fireball', 10, 5, 1)
        h.weapon = Weapon('Bat', 20)

        self.assertEqual(h.attack(), 20)
 def test_if_know_as_works_as_expected(self):
     h = Hero()
     exp = 'Hero the No title'
     self.assertEqual(h.known_as(), exp)