Ejemplo n.º 1
0
 def __init__(self):
     self.treasures = {
         'health_potion': [10, 20, 30, 50, 100],
         'mana_potion': [10, 20, 30, 50, 100],
         'weapon': [
             Weapon(name='Sword', damage=20),
             Weapon(name='Bradve', damage=50),
             Weapon(name='Dagger', damage=15)
         ],
         'spell': [
             Spell(name='Fireball', damage=20, mana_cost=40, cast_range=2),
             Spell(name='Ice', damage=30, mana_cost=50, cast_range=2),
             Spell(name='Lightning', damage=50, mana_cost=70, cast_range=1)
         ]
     }
 def setUp(self):
     self.dummy = Entity(name="Test", health=150, mana=70)
     self.weapon = Weapon(name="Gorehowl", damage=20)
     self.spell = Spell(name="Pyroblast",
                        damage=40,
                        manaCost=30,
                        castRange=1)
Ejemplo n.º 3
0
def test_weapon_instance():
    wep = Weapon(5, "Test Weapon")
    assert wep.getDamage() == 5
    assert wep.getName() == "Test Weapon"
    assert wep.identify() == "Test Weapon"
    assert wep.appraise() == 5
    assert wep.describe() != None
 def test_init_weapon(self):
     name = 'short_sword'
     sprite = 'imgs/dungeon_crawl/item/weapon/short_sword_2_old.png'
     description = 'A basic little sword, but one that can already prove very useful'
     price = 500
     equipped_sprite = ['imgs/dungeon_crawl/player/hand_right/short_sword.png']
     durability = 40
     reach = [1]
     power = 4
     kind = 'PHYSICAL'
     weight = 2
     restrictions = []
     possible_effects = []
     sword = Weapon(name, sprite, description, price, equipped_sprite, power, kind, weight, durability, reach,
                    restrictions, possible_effects)
     self.assertEqual(name, sword.name)
     self.assertEqual(description, sword.desc)
     self.assertEqual('Short Sword', str(sword))
     self.assertEqual(price, sword.price)
     self.assertEqual(price // 2, sword.resell_price)
     self.assertEqual(durability, sword.durability_max)
     self.assertEqual(durability, sword.durability)
     self.assertEqual(reach, sword.reach)
     self.assertEqual(power, sword.atk)
     self.assertEqual(DamageKind[kind], sword.attack_kind)
     self.assertEqual(weight, sword.weight)
     self.assertEqual(restrictions, sword.restrictions)
     self.assertEqual(possible_effects, sword.effects)
Ejemplo n.º 5
0
 def test_start_fight(self):
     h = self.hero
     e = self.enemy
     h.learn_spell(Spell())
     h.equip_weapon(Weapon())
     ft = Fight(h, e)
     ft.start_fight()
Ejemplo n.º 6
0
 def setUp(self):
     self.dummy = Arsenal()
     self.weapon = Weapon(name="Gorehowl", damage=20)
     self.spell = Spell(name="Pyroblast",
                        damage=40,
                        manaCost=30,
                        castRange=1)
Ejemplo n.º 7
0
    def __loot_treasure(self):
        item = self.__treasure.pick_one()

        if item is None:
            print('The chest was empty.')
            return

        print(f'You\'ve looted a {item[0]}.\n')

        if item[0] == 'potion':
            if (item[1]['name'] == 'Mana'):
                self.__hero.take_mana(item[1]['amount'])
            else:
                self.__hero.take_healing(item[1]['amount'])

        else:
            command = (self.__prompt_arsenal_update(item))
            if command:
                if item[0] == 'weapon':

                    weapon = Weapon(name=item[1]['name'],
                                    damage=item[1]['damage'])
                    self.__hero.equip(weapon)

                elif item[0] == 'spell':
                    spell = Spell(name=item[1]['name'],
                                  damage=item[1]['damage'],
                                  manaCost=item[1]['manaCost'],
                                  castRange=item[1]['range'])
                    self.__hero.learn(spell)
Ejemplo n.º 8
0
 def __init__(self, session, coords, owner):
     fprint = Footprint.square(2)
     heal_pts, armor = 500, 2
     weapon = Weapon()  # Placeholder
     super().__init__(session, coords, fprint, heal_pts, owner, armor,
                      weapon)
     self.objkey = 'wall'
Ejemplo n.º 9
0
 def setUp(self):
     self.test_hero = Hero(name='Ivan',
                           title='Dr',
                           health=100,
                           mana=50,
                           mana_regeneration_rate=2)
     self.test_weapon = Weapon()
     self.test_spell = Spell(mana_cost=20)
Ejemplo n.º 10
0
 def __init__(self, session, coords, owner):
     fprint = Footprint.square(7)
     heal_pts, armor = 1500, 2
     weapon = Weapon()  # Placeholder
     super().__init__(session, coords, fprint, heal_pts, owner, armor,
                      weapon)
     self.objkey = 'command'
     self.add_cmd('train_worker', self.session.cmds.train_worker, (0, 1))
     self.add_cmd('train_soldier', self.session.cmds.train_soldier, (1, 1))
Ejemplo n.º 11
0
 def __init__(self, session, coords, owner):
     fprint = Footprint.square(3)
     heal_pts, armor = 800, 2
     damage, rate, range = 5, 15, 5
     ignore_armor = False
     weapon = Weapon(damage, rate, range, ignore_armor)
     super().__init__(session, coords, fprint, heal_pts, owner, armor,
                      weapon)
     self.objkey = 'tower'
Ejemplo n.º 12
0
 def __init__(self, session, coords, owner):
     fprint = Footprint.round(1.3)
     heal_pts, armor = 50, 0
     damage, rate, range = 5, 10, 2
     ignore_armor = False
     weapon = Weapon(damage, rate, range, ignore_armor)
     speed = 6
     super().__init__(session, coords, fprint, heal_pts, owner, armor,
                      weapon, speed)
     self.objkey = 'worker'
Ejemplo n.º 13
0
 def __init__(self, session, coords, owner):
     fprint = Footprint.round(1.6)
     heal_pts, armor = 80, 0
     damage, rate, range = 7, 9, 4
     ignore_armor = False
     weapon = Weapon(damage, rate, range, ignore_armor)
     speed = 4
     super().__init__(session, coords, fprint, heal_pts, owner, armor,
                      weapon, speed)
     self.objkey = 'soldier'
Ejemplo n.º 14
0
    def test_attack(self):
        weapon = Weapon(name="bow", damage=10)
        spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)
        gun = Weapon(name="gun", damage=40)
        ice = Spell(name="Ice", damage=50, mana_cost=50, cast_range=1)
        self.hero.equip(weapon)
        self.hero.learn(spell)

        with self.subTest("Hero attack with spell.damage > weapon.damage"):
            self.assertEqual(self.hero.attack(), spell.damage)

        with self.subTest("Hero attack with weapon if hero dont know spell"):
            self.hero.weapon = None
            self.assertEqual(self.hero.attack(), spell.damage)

        with self.subTest("Enemy attack with only damage"):
            self.assertEqual(self.enemy.attack(), self.enemy.damage)

        with self.subTest("Enemy attack with weapon"):
            self.enemy.equip(gun)
            self.assertEqual(self.enemy.attack(), gun.damage)

        with self.subTest("Attack method by weapon"):
            self.hero.equip(weapon)
            self.assertEqual(self.hero.attack(by="weapon"), 10)

        with self.subTest("Attack method by spell"):
            self.assertEqual(self.hero.attack(by="spell"), 30)

        with self.subTest("Try to attack with non-existent weapon"):
            self.hero.weapon = None
            self.assertEqual(self.hero.attack(by="weapon"), 0)

        with self.subTest(
                "Try to attack with spell if hero's mana is lower than the Spell.mana_cost"
        ):
            with self.assertRaises(ValueError):
                self.hero.attack(by="spell")
Ejemplo n.º 15
0
    def __init__(self, x, y, rotate, mirror, slide_dir, weapon_tup=None):
        self.position = sf.Vector2(x, y)

        # Rotation
        if rotate:
            self.rotation = 90
        else:
            self.rotation = 0

        # Mirror?
        self.scale = sf.Vector2(1, 1)
        if mirror:
            if rotate:
                self.scale.x = -1
            else:
                self.scale.y = -1

        # Handle direction
        self.slide_dir = slide_dir
        if slide_dir == "left":
            self.powered_offset = sf.Vector2(-15, 0)
        elif slide_dir == "right":
            self.powered_offset = sf.Vector2(15, 0)
        elif slide_dir == "up":
            self.powered_offset = sf.Vector2(0, -5)
        elif slide_dir == "down":
            self.powered_offset = sf.Vector2(0, 5)

        self.rotate = rotate
        self.mirror = mirror

        if weapon_tup:
            self.weapon = Weapon(*weapon_tup)
            self.weapon.slot = self
            self.weapon.position = self.position
        else:
            self.weapon = None
Ejemplo n.º 16
0
import unittest
from src.player import Player
from src.enemy import *
from src.weapon import Weapon
from src.consumable import *

e = Enemy("Brownie", 10, 2, ET.BROWNIE)
p = Player("sword gumby", 25, weapon=Weapon(5, "neat shiny sword"))
c = Consumable.create()
p.addItem(c)


def test_player_instantiate():
    assert (p.getName() == "sword gumby" and p.getHP() == 25)


def test_player_damage():
    p.takeDamage(5)
    assert p.getHP() == 20


def test_player_heal():
    p.heal(3)
    assert p.getHP() == 23


def test_player_name_change():
    newName = "angry sword gumby"
    p.setName(newName)
    assert p.getName() == newName
Ejemplo n.º 17
0
    ship.add_weapon_slot(360, 80, True, True, "right")
    ship.add_weapon_slot(360, 120, True, False, "right")
    ship.add_weapon_slot(230, 29, True, True, "up")
    ship.add_weapon_slot(300, 294, True, False, "down")

    ship.add_room(const.room2x2, 0, 0)
    ship.add_room(const.room_engines2x2, 0, 2)
    ship.add_room(const.room2x2, 0, 4)
    ship.add_room(const.room2x1, 2, 3)
    ship.add_room(const.room2x1, 4, 3)
    ship.add_room(const.room2x1, 2, 5)
    ship.add_room(const.room_weapons2x2, 3, 1)
    ship.add_room(const.room_shields2x2, 4, 4)

    # Weapons!!!
    ship.add_weapon(Weapon(""))
    ship.add_weapon(Weapon(""))
    ship.add_weapon(Weapon(""))

    # Setup weapon IDs
    if ship.weapon_system:
        for i, weapon in enumerate(ship.weapon_system.weapons):
            weapon.id = client.client_id + ":weap" + str(i)

    # Send the server my badass ship
    ship_packet = net.Packet()
    ship.serialize(ship_packet)
    client.send(ship_packet)

    # Receive enemy ship
    ships = {client.client_id: ship}
Ejemplo n.º 18
0
 def test_get_damage_source_weapon_and_spell_wepaon_higher_damage(self):
     self.setUp()
     n = self.test_soldier
     n.equip_weapon(Weapon(name='asd', damage=50))
     n.learn_spell(self.default_spell)
     self.assertEqual(n.get_damage_source(), 'weapon')
def random_weapon(price=None, durability=None):
    attrs = random_weapon_attributes(price, durability)
    return Weapon(attrs['name'], attrs['sample_img'], attrs['desc'],
                  attrs['cost'], [attrs['sample_img']], attrs['power'],
                  attrs['attack_kind'], attrs['weight'], attrs['durability'],
                  attrs['reach'], attrs['restrictions'], attrs['effects'])
Ejemplo n.º 20
0
 def __init__(self, sess, coords, ftprint, heal_pts, armor):
     super().__init__(sess, coords, ftprint, heal_pts, None, armor, Weapon())
     self.otype = 'D'
Ejemplo n.º 21
0
def parse_item_file(name):
    # Retrieve data root for item
    it_tree_root = etree.parse('data/items.xml').getroot().find('.//' + name)

    sprite = 'imgs/dungeon_crawl/item/' + it_tree_root.find(
        'sprite').text.strip()
    info = it_tree_root.find('info').text.strip()
    price = it_tree_root.find('price')
    if price is not None:
        price = int(price.text.strip())
    else:
        price = 0
    category = it_tree_root.find('category').text.strip()

    if category == 'potion' or category == 'consumable':
        effects = []
        for eff in it_tree_root.findall('.//effect'):
            effect_name = eff.find('type').text.strip()
            pow_el = eff.find('power')
            power = int(pow_el.text.strip()) if pow_el is not None else 0
            duration_el = eff.find('duration')
            duration = int(
                duration_el.text.strip()) if duration_el is not None else 0
            effects.append(Effect(effect_name, power, duration))
        item = Potion(name, sprite, info, price, effects) if category == 'potion' else \
            Consumable(name, sprite, info, price, effects)
    elif category == 'armor':
        body_part = it_tree_root.find('bodypart').text.strip()
        defense_el = it_tree_root.find('def')
        defense = int(defense_el.text.strip()) if defense_el is not None else 0
        weight = int(it_tree_root.find('weight').text.strip())
        eq_sprites = it_tree_root.find('equipped_sprites')
        if eq_sprites is not None:
            equipped_sprites = []
            for eq_sprite in eq_sprites.findall('sprite'):
                equipped_sprites.append('imgs/dungeon_crawl/player/' +
                                        eq_sprite.text.strip())
        else:
            equipped_sprites = [
                'imgs/dungeon_crawl/player/' +
                it_tree_root.find('equipped_sprite').text.strip()
            ]
        restrictions = load_restrictions(it_tree_root.find('restrictions'))
        item = Equipment(name, sprite, info, price, equipped_sprites,
                         body_part, defense, 0, 0, weight, restrictions)
    elif category == 'shield':
        parry = int(float(it_tree_root.find('parry_rate').text.strip()) * 100)
        defense_el = it_tree_root.find('def')
        defense = int(defense_el.text.strip()) if defense_el is not None else 0
        fragility = int(it_tree_root.find('fragility').text.strip())
        weight = int(it_tree_root.find('weight').text.strip())
        equipped_sprite = [
            'imgs/dungeon_crawl/player/hand_left/' +
            it_tree_root.find('equipped_sprite').text.strip()
        ]
        restrictions = load_restrictions(it_tree_root.find('restrictions'))
        item = Shield(name, sprite, info, price, equipped_sprite, defense,
                      weight, parry, fragility, restrictions)
    elif category == 'weapon':
        power = int(it_tree_root.find('power').text.strip())
        attack_kind = it_tree_root.find('kind').text.strip()
        weight = int(it_tree_root.find('weight').text.strip())
        fragility = int(it_tree_root.find('fragility').text.strip())
        w_range = [
            int(reach)
            for reach in it_tree_root.find('range').text.strip().split(',')
        ]
        equipped_sprite = [
            'imgs/dungeon_crawl/player/hand_right/' +
            it_tree_root.find('equipped_sprite').text.strip()
        ]
        restrictions = load_restrictions(it_tree_root.find('restrictions'))
        effects = it_tree_root.find('effects')
        possible_effects = []
        if effects is not None:
            possible_effects = [
                load_weapon_effect(eff) for eff in effects.findall('effect')
            ]
        item = Weapon(name, sprite, info, price, equipped_sprite, power,
                      attack_kind, weight, fragility, w_range, restrictions,
                      possible_effects)
    elif category == 'key':
        for_chest = it_tree_root.find('open_chest') is not None
        for_door = it_tree_root.find('open_door') is not None
        item = Key(name, sprite, info, price, for_chest, for_door)
    elif category == 'spellbook':
        spell = it_tree_root.find('effect').text.strip()
        item = Spellbook(name, sprite, info, price, spell)
    else:
        # No special category
        item = Item(name, sprite, info, price)

    return item
Ejemplo n.º 22
0
 def setUp(self):
     self.test_soldier = Unit(health=200, mana=100)
     self.default_weapon = Weapon()
     self.default_spell = Spell()
Ejemplo n.º 23
0
 def __init__(self, *, weapon=Weapon(), spell=None):
     self.__weapon = weapon
     self.__spell = spell
Ejemplo n.º 24
0
 def equip_weapon(self, *, weapon=Weapon()):
     self.__weapon = weapon
Ejemplo n.º 25
0
'''this is going to be a manual test'''

from src.hero import Hero
from src.enemy import Enemy
from src.spell import Spell
from src.weapon import Weapon
from src.fight import Fight
from src.fight_status_bar import FightStatusBar

h = Hero(name="Genadi", title="Gopnik")

s = Spell(name="Kwass Molotov", damage=5, manaCost=10, castRange=7)
s1 = Spell(name="Magic spit", damage=10, manaCost=25, castRange=2)

w = Weapon(name="Beer Bottle", damage=25)
w1 = Weapon(name="Bat", damage=22)

h.equip(w)
h.learn(s)
h.coordinates = (0, 7)

e = Enemy()

e.learn(s1)
e.equip(w1)
e.coordinates = (0, 0)
"""
f = Fight(h, e,)
f.initialize_fight() """
Ejemplo n.º 26
0
    def generate_objects_from_tiles(self, data):
        """Creates objects from the game tiles data
        
        Args:
            data: The whole json data
        
        Returns:
            generated_objects: All objects with associated symbols
            rooms: All rooms with associated symbols
            weapons: All weapons with associated symbols
            players: All players with associated symbols
            player_cards: All player_cards with associated symbols
        """

        # Cerates the simple tile dictionary with the character and associated object
        generated_objects = {
            tile['char']: tile['obj']
            for tile in data['simple tiles']
        }

        # Create empty dictionary
        rooms = {}
        weapons = {}
        players = {}
        player_cards = {}

        player_count = 0

        # Loops through the data
        for obj_id, tile in enumerate(data['game tiles']):
            name = tile['name']
            symbol = tile['char']

            # Make objects from the object names
            if tile['obj'].lower() == 'room':
                r = Room(name, obj_id, symbol)
                generated_objects[symbol] = r
                rooms[symbol] = r

            elif tile['obj'].lower() == 'weapon':
                w = Weapon(name, obj_id, symbol)
                generated_objects[symbol] = w
                weapons[symbol] = w

            elif tile['obj'].lower() == 'human' or tile['obj'].lower() == 'ai':
                if tile['obj'].lower() == 'human':
                    player = Human(name, player_count, symbol)
                else:
                    player = Ai(name, player_count, symbol)

                players[symbol] = player

                pc = PlayerCard(name, obj_id, symbol, player)
                generated_objects[symbol] = pc
                player_cards[symbol] = pc

                player_count += 1

            else:
                return False, False, False, False, False

        return generated_objects, rooms, weapons, players, player_cards