Example #1
0
    def __init__(self,
                 surface: pygame.Surface,
                 position: tuple,
                 size: tuple,
                 speed: int,
                 max_hp: int,
                 max_energy: int,
                 wall_sprites: pygame.sprite.Group,
                 rooms_survived: int = 0,
                 gold: int = 0,
                 image_file: str = IMAGE,
                 animated=False):

        super().__init__(surface,
                         position,
                         size,
                         speed,
                         max_hp,
                         wall_sprites,
                         image_file=image_file,
                         animated=animated)

        self.max_energy = max_energy
        self.energy = self.max_energy
        self.rooms_survived = rooms_survived
        self.gold = gold
        self.last_weapon_change = 0
        self.weapon2 = Weapon(self.surface, (self.x, self.y),
                              WEAPONS_DB['CAULE'])

        self.weapon = Weapon(self.surface, (self.x, self.y),
                             WEAPONS_DB['AK47'])
Example #2
0
    def testInit(self):
        from items.weapon import Weapon

        sword = Weapon("Sword", "A cheap sword", 1, 3, 1)

        #Tests for correct initialization
        self.assertEqual(sword.getName(), "Sword", "Name did not initialize correctly.")
        self.assertEqual(sword.getDescription(), "A cheap sword", "Description did not initialize correctly.")
        self.assertEqual(sword.getWeight(), 1, "Weight did not initialize correctly.")
        self.assertEqual(sword.getAttack(), 3, "Damage did not initialize correctly.")
Example #3
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))
Example #4
0
    def test_if_create_weapon_class_method_creates_a_Weapon_instance(self):
        w = Weapon.create_weapon('Spear')
        range_damage = range(1, 21)

        self.assertEqual(Weapon, type(w))
        self.assertEqual(w.name, 'Spear')
        self.assertTrue(w.damage in range_damage)
    def create_hero(cls):
        # add except
        name = input('Hero name: ')
        title = input('Hero title: ')

        weapon = Weapon.create_weapon(random.choice(WEAPON_NAMES))
        spell = Spell.create_spell(random.choice(SPELL_NAMES))

        return cls(name=name, title=title, weapon=weapon, spell=spell)
def genWeapon(quality, randWeaponType, randDesc):
    """
    Generates a single weapon object.

    @param quality:         The quality (1-20) of the weapon.
    @param randTypeWeapon:  Random number that determines the type of weapon generated.
    @param randDesc:        Random number that determines the description of the item.
    @return:                The randomly generated weapon.
    """
    #Generate prefix
    if quality < 5:
        prefix = "Light"
    elif 5 <= quality < 10:
        prefix = "Medium"
    elif 10 <= quality < 15:
        prefix = "Heavy"
    else:
        prefix = "Legendary"
    #Generate suffix
    if quality < 5:
        suffix = "of Travel"
    elif 5 <= quality < 10:
        suffix = "of Defense"
    elif 10 <= quality < 15:
        suffix = "of Hacking"
    else:
        suffix = "of Domination"
    #Generate weapon type
    if randWeaponType < .25:
        type = "Sword"
        weight = 2
        damage = 2
    elif .25 <= randWeaponType < .5:
        type = "Staff"
        weight = 3
        damage = 2
    elif .5 <= randWeaponType < .75:
        type = "Scepter"
        weight = 2
        damage = 3
    else:
        type = "Axe"
        weight = 4
        damage = 4

    #Concatenate name
    totalName = prefix + " " + type + " " + suffix

    #Generate weapon description
    description = genWeaponDescription(randDesc)

    #Generate cost
    cost = quality * constants.WEAPON_COST

    #Generate weapon
    weapon = Weapon(totalName, description, weight, damage, cost)
    return weapon
Example #7
0
    def testExecute(self):
        from player import Player
        from space import Space
        from items.item import Item
        from items.weapon import Weapon
        from commands.unequip_command import UnequipCommand

        #Attempting to unequip item not currently equipped
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        unequipCmd = UnequipCommand("unequip",
                                    "Unequips currently equipped item", player)

        item = Item("Charm", "Unknown effects", 1)
        weapon = Weapon("Dagger", "A trusty blade", 2, 2)

        rawInputMock = MagicMock(return_value="Dagger")
        with patch('commands.unequip_command.raw_input',
                   create=True,
                   new=rawInputMock):
            unequipCmd.execute()

        ###TODO: FIND SOME WAY TO MAKE SURE THAT PRINT STATEMENT PRINTED

        #Attempting to unequip item that may be unequipped
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        unequipCmd = UnequipCommand("unequip",
                                    "Unequips currently equipped item", player)

        weapon = Weapon("Dagger", "A trusty blade", 2, 2)

        player.equip(weapon)

        rawInputMock = MagicMock(return_value="Dagger")
        with patch('commands.unequip_command.raw_input',
                   create=True,
                   new=rawInputMock):
            unequipCmd.execute()

        equipped = player.getInventory()
        self.assertFalse(equipped.containsItem(weapon),
                         "Failed to unequip item that it should have.")
    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)
Example #9
0
    def __init__(self, health: int = 1, mana: int = 0):
        self.verify_health(health)
        self.health = health
        self.MAX_HEALTH = health

        self.verify_number_value(mana)
        self.mana = mana
        self.MAX_MANA = mana

        self.weapon = Weapon()
        self.spell = Spell()
def getStartingInventory():
    """
    Generate's player's starting inventory.

    @return:   A list of the items.
    """
    weapon = Weapon("Rock", "Really heavy", 2, 1000, 1)
    armor = Armor("Leather Tunic", "Travel cloak", 3, 1, 1)
    potion = Potion("Vodka", "Good for health", 1, 1, 1)

    startingInventory = [weapon, armor, potion]
    
    return startingInventory
Example #11
0
def generate_random_value_of_treasure(treasure: str):
    from items.weapon import Weapon
    from items.spell import Spell

    dict_treasure_values = {
        'health': random.randint(1, 20),
        'mana': random.randint(1, 20),
        'weapon': Weapon.create_weapon(random.choice(WEAPON_NAMES)),
        'spell': Spell.create_spell(random.choice(SPELL_NAMES))
    }

    treasure_value = dict_treasure_values[treasure]
    return treasure_value
    def __init__(self,
                 name: str = "Hero",
                 title: str = "No title",
                 health: int = 100,
                 mana: int = 100,
                 mana_regeneration_rate: int = 5,
                 weapon: Weapon = Weapon(),
                 spell: Spell = Spell()):
        super().__init__(health=health, mana=mana)
        self.verify_attributes(name, title, mana_regeneration_rate)

        self.name = name
        self.title = title
        self.mana_regeneration_rate = mana_regeneration_rate
        self.weapon = weapon
        self.spell = spell
Example #13
0
    def __init__(self,
                 surface: pygame.Surface,
                 position: tuple,
                 size: tuple,
                 wall_sprites,
                 args,
                 animated=False):

        super().__init__(surface, position, size, args["SPEED"], args["HP"],
                         wall_sprites,
                         'characters/enemies/' + args["IMAGE_FILE"], animated)

        self.weapon = Weapon(self.surface, (self.rect.left, self.rect.top),
                             args["WEAPON"])
        self.weapon.cost = 0
        self.inv_time = 0
Example #14
0
class Player(Character):
    def __init__(self,
                 surface: pygame.Surface,
                 position: tuple,
                 size: tuple,
                 speed: int,
                 max_hp: int,
                 max_energy: int,
                 wall_sprites: pygame.sprite.Group,
                 rooms_survived: int = 0,
                 gold: int = 0,
                 image_file: str = IMAGE,
                 animated=False):

        super().__init__(surface,
                         position,
                         size,
                         speed,
                         max_hp,
                         wall_sprites,
                         image_file=image_file,
                         animated=animated)

        self.max_energy = max_energy
        self.energy = self.max_energy
        self.rooms_survived = rooms_survived
        self.gold = gold
        self.last_weapon_change = 0
        self.weapon2 = Weapon(self.surface, (self.x, self.y),
                              WEAPONS_DB['CAULE'])

        self.weapon = Weapon(self.surface, (self.x, self.y),
                             WEAPONS_DB['AK47'])

    def attack(self, coordinates: tuple = None):
        if coordinates is not None and self.energy - self.weapon.cost >= 0:
            bullet = self.weapon.shoot(coordinates)
            if bullet is not None:
                self.bullets.add(bullet)
                self.energy -= self.weapon.cost
                return bullet

    def swap_weapons(self):
        current_tick = pygame.time.get_ticks()
        if current_tick - self.last_weapon_change > 300:
            self.last_weapon_change = current_tick
            self.weapon, self.weapon2 = self.weapon2, self.weapon
Example #15
0
    def testExecute(self):
        from space import Space
        from player import Player
        from items.weapon import Weapon
        from commands.drop_command import DropCommand

        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        dropCmd = DropCommand("drop",
                              "Drops an object from inventory to space",
                              player)

        weapon = Weapon("Dagger", "A trusty blade", 2, 2, 2)

        player.addToInventory(weapon)
        player.equip(weapon)

        #Asserts item in player inventory but not in space
        self.assertFalse(space.containsItem(weapon),
                         "Space should not have item but does.")

        inventory = player.getInventory()
        self.assertTrue(inventory.containsItem(weapon),
                        "Inventory should have item but does not.")

        #Assert item in space but not in player inventory and not in equipment
        rawInputMock = MagicMock(return_value="Dagger")

        with patch('commands.drop_command.raw_input',
                   create=True,
                   new=rawInputMock):
            dropCmd.execute()

        self.assertTrue(space.containsItemString("Dagger"),
                        "Space should have item but does not.")

        inventory = player.getInventory()
        self.assertFalse(inventory.containsItem(weapon),
                         "Inventory should not have item but does.")

        equipped = player.getEquipped()
        self.assertFalse(equipped.containsItem(weapon),
                         "Equipment should not have item but does.")
Example #16
0
    def testInit(self):
        from items.weapon import Weapon

        sword = Weapon("Sword", "A cheap sword", 1, 3)

        #Tests for correct initialization
        self.assertEqual(sword.getName(), "Sword",
                         "Name did not initialize correctly.")
        self.assertEqual(sword.getDescription(), "A cheap sword",
                         "Description did not initialize correctly.")
        self.assertEqual(sword.getWeight(), 1,
                         "Weight did not initialize correctly.")
        self.assertEqual(sword.getAttack(), 3,
                         "Damage did not initialize correctly.")
Example #17
0
    def testEquipUnequip(self):
        from player import Player
        from space import Space
        from items.item import Item
        from items.weapon import Weapon
        from items.armor import Armor

        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)

        newItem = Item("Chainik Reakettle", "Makes good tea", 1)
        newWeapon = Weapon("Gun of Hurlocker", "Oppressive, but friendly", 2,
                           3)
        newArmor = Armor("Cookies of Miles", "Defends against sadness", 2, 4)

        player.addToInventory(newItem)
        player.addToInventory(newWeapon)
        player.addToInventory(newArmor)

        #Attempt to equip new items
        player.equip(newItem)
        self.assertFalse(newItem in player.getEquipped(),
                         "Equipped %s and should not have." % newItem)
        player.equip(newWeapon)
        self.assertTrue(newWeapon in player.getEquipped(),
                        "Failed to equip %s" % newWeapon)
        player.equip(newArmor)
        self.assertTrue(newArmor in player.getEquipped(),
                        "Failed to equip %s" % newArmor)

        #Attempt to unequip items
        player.unequip(newWeapon)
        self.assertFalse(newWeapon in player.getEquipped(),
                         "Failed to unequip %s" % newWeapon)
        player.unequip(newArmor)
        self.assertFalse(newArmor in player.getEquipped(),
                         "Failed to unequip %s" % newArmor)
    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)
Example #19
0
    def testExecute(self):
        from player import Player
        from space import Space
        from items.item import Item
        from items.weapon import Weapon
        from commands.equip_command import EquipCommand

        #Tests default states
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)

        #Trying to equip item not in inventory
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        equipCmd = EquipCommand("Equip", "Equips item in inventory to player",
                                player)

        item = Item("Charm", "Unknown effects", 1)
        weapon = Weapon("Dagger", "A trusty blade", 2, 2)

        rawInputMock = MagicMock(return_value="Dagger")
        with patch('commands.equip_command.raw_input',
                   create=True,
                   new=rawInputMock):
            equipCmd.execute()

        equipped = player.getEquipped()
        self.assertFalse(equipped.containsItem(weapon),
                         "Player equipped item not in inventory.")

        #Trying to equip item that cannot be equipped (e.g. item is not instance of Armor or Weapon)
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        equipCmd = EquipCommand("Equip", "Equips item in inventory to player",
                                player)

        item = Item("Charm", "Unknown effects", 1)

        inventory = player.getInventory()
        inventory.addItem(item)

        rawInputMock = MagicMock(return_value="Charm")
        with patch('commands.equip_command.raw_input',
                   create=True,
                   new=rawInputMock):
            equipCmd.execute()

        equipped = player.getEquipped()
        self.assertFalse(equipped.containsItem(item),
                         "Player equipped item of Item class.")

        #Equipping item that can be equipped
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        equipCmd = EquipCommand("Equip", "Equips item in inventory to player",
                                player)

        weapon = Weapon("Dagger", "A trusty blade", 2, 2)

        inventory = player.getInventory()
        inventory.addItem(weapon)

        rawInputMock = MagicMock(return_value="Dagger")
        with patch('commands.equip_command.raw_input',
                   create=True,
                   new=rawInputMock):
            equipCmd.execute()

        equipped = player.getEquipped()

        self.assertTrue(equipped.containsItem(weapon),
                        "Player failed to equip equipable item.")

        #Equipping an item that is already equipped
        space = Space("Shire", "Home of the Hobbits.")
        player = Player("Frodo", space)
        equipCmd = EquipCommand("Equip", "Equips item in inventory to player",
                                player)

        weapon = Weapon("Dagger", "A trusty blade", 2, 2)

        inventory = player.getInventory()
        inventory.addItem(weapon)

        equipped = player.getEquipped()
        equipped.addItem(weapon)

        rawInputMock = MagicMock(return_value="Dagger")
        with patch('commands.equip_command.raw_input',
                   create=True,
                   new=rawInputMock):
            equipCmd.execute()

        numberInInventory = 0
        numberInEquipped = 0
        for item in inventory._items:
            if item == weapon:
                numberInInventory += 1
        for item in equipped._items:
            if item == weapon:
                numberInEquipped += 1

        self.assertEqual(
            inventory.count(), 1,
            "Equipping an item that is already equipped failed -- inventory problem."
        )
        self.assertEqual(
            equipped.count(), 1,
            "Equipping an item that is already equipped failed -- equipment problem."
        )
Example #20
0
    def test_if_constructor_sets_attributes_correctly(self):
        w = Weapon('Spear', 20)

        self.assertEqual(w.name, 'Spear')
        self.assertEqual(w.damage, 20)
Example #21
0
from items.treasure import Treasure
from items.weapon import Weapon

quantum_microscope = Treasure('quantum microscope', 'A labelled microscope with odd inscriptions decorating its exterior.', value=100)
intellicorium_microscope = Treasure('intellicorium microscope', "A labelled microscope with so many inscriptions covering it that it's impossible to use.", value=75)
splitting_microscope = Treasure('splitting microscope', "A labelled microscope with a few inscriptions. Its view seems to split with eight different lenses, which doesn't lend well to its usage.", value=50)

pitchfork = Weapon('pitchfork', 'A stylish, devilish pitchfork with engravings covering its handle.', damage=100, droppable=False)
sword = Weapon('sword', 'A plain old sword.', damage=50)