コード例 #1
0
 def __init__(self, value_type, value, name=None):
     self.type = value_type
     if value_type == 'weapon':
         self.item = Weapon(name=name, damage=int(value))
     elif value_type == 'spell':
         self.item = Spell(name=name, damage=int(value))
     else:
         self.type = f'{value_type} potion'
         self.item = int(value)
コード例 #2
0
    def test_choose_fighting_tools_when_hero_has_not_got_weapon_and_enemy_is_at_same_position_return_weapon(
            self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy()
        weapon = Weapon("shodow", 100)
        hero.equip(weapon)
        create_fight = Fight(hero, enemy, "weapon")

        result = create_fight.choose_fighting_tools(hero, True)

        self.assertEqual(result, [100, weapon])
コード例 #3
0
    def test_round_fight_when_hero_hits_return_enemy_gone(self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy()
        weapon = Weapon("shodow", 100)
        hero.equip(weapon)
        create_fight = Fight(hero, enemy)

        hero_result = create_fight.choose_fighting_tools(hero, True)
        enemy_result = create_fight.choose_fighting_tools(enemy, True)

        result = create_fight.round_fight(hero_result, enemy_result)
        self.assertEqual(result, False)
コード例 #4
0
    def test_choose_fighting_tools_when_hero_has_spec_ability_but_enemy_is_not_in_range_return_zero(
            self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy()
        weapon = Weapon("shodow", 100)
        hero.equip(weapon)

        create_fight = Fight(hero, enemy)

        result = create_fight.choose_fighting_tools(hero, False)

        self.assertEqual(result, [0])
コード例 #5
0
    def test_choose_fighting_tools_when_hero_has_spec_ability_return_damage_from_weapon(
            self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy()
        weapon = Weapon("shodow", 100)
        hero.equip(weapon)

        create_fight = Fight(hero, enemy)

        result = create_fight.choose_fighting_tools(hero, True)

        self.assertEqual(result, [100, weapon])
コード例 #6
0
    def test_start_fight_when_hero_strike_from_distance_enemy_return_dead_hero(
            self):
        hero = Hero("Pesho", "Padawan", health=100)
        enemy = Enemy(health=200, damage=50)
        weapon = Weapon("shodow", 40)
        spell = Spell("Abraka", 40)
        hero.learn(spell)
        create_fight = Fight(hero, enemy)

        result = create_fight.start_fight(1)

        self.assertEqual(result, hero)
コード例 #7
0
    def test_start_fight_when_both_are_in_same_pas_return_loser_our_hero(self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy(health=200, damage=10)
        weapon = Weapon("shodow", 10)
        hero.equip(weapon)
        spell = Spell("Abraka", 10)
        hero.learn(spell)
        create_fight = Fight(hero, enemy, "weapon")

        result = create_fight.start_fight(0)

        self.assertEqual(result, hero)
コード例 #8
0
    def test_choose_fighting_tools_when_hero_has_spec_ability_weapon_and_spell_return_spell(
            self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy()
        weapon = Weapon("shodow", 100)
        spell = Spell("bla", 150)
        hero.equip(weapon)
        hero.learn(spell)
        create_fight = Fight(hero, enemy)

        result = create_fight.choose_fighting_tools(hero, False)

        self.assertEqual(result, [150, spell])
コード例 #9
0
    def test_start_fight_when_hero_strike_after_mana_is_gone_switch_to_weapon_return_dead_enemy(
            self):
        hero = Hero("Pesho", "Padawan", health=100)
        enemy = Enemy(health=200, damage=10)
        weapon = Weapon("shodow", 40)
        hero.equip(weapon)
        spell = Spell("Abraka", 40)
        hero.learn(spell)
        create_fight = Fight(hero, enemy)

        result = create_fight.start_fight(1)

        self.assertEqual(result, enemy)
コード例 #10
0
    def test_round_fight_when_hero_hits_and_enemy_is_not_gone_return_enemy_strike_back(
            self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy(health=200)
        weapon = Weapon("shodow", 100)
        hero.equip(weapon)
        create_fight = Fight(hero, enemy)

        hero_result = create_fight.choose_fighting_tools(hero, True)
        enemy_result = create_fight.choose_fighting_tools(enemy, True)

        result = create_fight.round_fight(hero_result, enemy_result)

        self.assertEqual(hero.get_health(), 80)
        self.assertEqual(enemy.get_health(), 100)
コード例 #11
0
    def test_start_fight_when_hero_strike_after_mana_is_he_take_items_mana_return_dead_enemy(
            self):
        hero = Hero("Pesho", "Padawan", health=100)
        enemy = Enemy(health=200, damage=10)
        weapon = Weapon("shodow", 40)
        hero.equip(weapon)
        treasure = Treasure(value_type="mana", value=50)
        spell = Spell("Abraka", 40)
        hero.learn(spell)
        hero.add_item(treasure)
        create_fight = Fight(hero, enemy)

        result = create_fight.start_fight(1)

        self.assertEqual(result, enemy)
コード例 #12
0
    def test_start_fight_when_hero_strike_from_distance_enemy_get_healing_return_dead_enemy(
            self):
        hero = Hero("Pesho", "Padawan", health=100, mana=100)
        enemy = Enemy(health=200, damage=10)
        weapon = Weapon("shodow", 40)
        treasure1 = Treasure(value_type="mana", value=100)
        treasure2 = Treasure(value_type="health", value=100)
        spell = Spell("Abraka", 40)
        hero.learn(spell)
        hero.add_item(treasure1)
        hero.add_item(treasure2)
        create_fight = Fight(hero, enemy)

        result = create_fight.start_fight(1)

        self.assertEqual(result, enemy)
コード例 #13
0
    def test_round_fight_when_hero_hits_and_with_spell_enemy_is_not_gone_return_enemy_move_to_hero(
            self):
        hero = Hero("Pesho", "Padawan")
        enemy = Enemy(health=200)
        weapon = Weapon("shodow", 100)
        hero.equip(weapon)
        spell = Spell("Abraka", 120)
        hero.learn(spell)
        create_fight = Fight(hero, enemy)

        hero_result = create_fight.choose_fighting_tools(hero, False)
        enemy_result = create_fight.choose_fighting_tools(enemy, True)

        result = create_fight.round_fight(hero_result, enemy_result, True)

        self.assertEqual(hero.get_health(), 100)
        self.assertEqual(enemy.get_health(), 80)
コード例 #14
0
    def test_hero_use_weapon(self):
        ivan = Hero('Ivan', 'Import Failure', 100, 100, 2)
        sword = Weapon('Trouble maker', 30)
        ivan.equip(sword)

        self.assertEqual(ivan.attack(by='weapon'), 30)
コード例 #15
0
    def test_enemy_use_weapon(self):
        sauron = Enemy(100, 100)
        sword = Weapon('Big fat sword', 30)
        sauron.equip(sword)

        self.assertEqual(sauron.attack(by='weapon'), 30)
コード例 #16
0
ファイル: main.py プロジェクト: AkaiBF/pyrpg
from classes.player import Player, bcolors
from classes.weapon import Weapon
from classes.spell import Spell
from classes.item import Item

pj1 = Player("Rhogar", 12, 45, 18, 16, 13, 14, 9, 7, 16)
pj2 = Player("Berto", 30, 30, 12, 12, 10, 18, 10, 10, 10)
sword = Weapon(6, "Sword", 1)
healingSpell = Spell(12, 7, 5)
fireball = Spell(6, 1, 12)
advantager = Item(1, 'common', 1)
advantager.use(pj1, pj2)


def menu():
    print("Acciones")
    print("1. Usar espada")
    print("2. Curar")
    print("3. Usar bola de fuego")
    print("Elije una acción:", end="")
    return input()


while (pj1.hp > 0 and pj2.hp > 0):
    '''Turno jugador'''
    action = menu()
    print(action)
    if (int(action) == 1):
        if (pj1.hit(pj2.armor)):
            dmg = sword.attack()
            pj2.hp -= dmg