Beispiel #1
0
    def test_can_identify_special_items(self):
        self.assertTrue(
            ItemService.is_special_item(
                Item('Backstage passes to johny concert', 50, 30)))

        self.assertFalse(
            ItemService.is_special_item(Item('passes to john legend', 25, 50)))
Beispiel #2
0
    def test_attribute_is_defined(self):
        self.assertTrue(
            ItemService.item_has_given_attributte(Item('concert', 12, 30),
                                                  'name'))

        self.assertRaises(AttributeError,
                          ItemService.item_has_given_attributte,
                          Item('concert', 12, 30), 'price')
Beispiel #3
0
    def test_can_reduce_item_sell_in(self):
        item = Item("Sulfuras", 20, 80)
        item2 = Item("AgedBrie", "20", 50)

        expected_value = item.sell_in - 1

        self.assertTrue(
            ItemService.reduce_item_sell_in(item) == expected_value)

        self.assertRaises(TypeError, ItemService.reduce_item_sell_in, item2)
Beispiel #4
0
    def test_can_update_backstage(self):
        item = Item("Backstage passes to johny", 5, 35)
        expected_value = 38

        item2 = Item("Backstage passes to johny", 0, 50)
        expected_value2 = 0

        self.assertTrue(
            BackstageService.update_item_quality(item) == expected_value)

        self.assertTrue(
            BackstageService.update_item_quality(item2) == expected_value2)
 def test_can_update_item_quality(self):
     item = Item("passes to johnny", 25, 25)
     expected_quality = item.quality - 1
     expected_sell_in = item.sell_in - 1
     self.assertTrue(
         StandardItemService.update_item_quality(item) == (
             expected_quality, expected_sell_in))
Beispiel #6
0
    def __init__(self, x, y, char, name, color, blocks=False,\
        always_visible=False, fighter=None, ai=None, item=None, equipment=None):
        self.x = x
        self.y = y
        self.char = char
        self.name = name
        self.color = color
        self.blocks = blocks
        self.always_visible = always_visible

        self.fighter = fighter
        if self.fighter:  #let the fighter component know who owns it
            self.fighter.owner = self

        self.ai = ai
        if self.ai:  #let the AI component know who owns it
            self.ai.owner = self

        self.item = item
        if self.item:  #let the Item component know who owns it
            self.item.owner = self

        self.equipment = equipment
        if self.equipment:  # let the Equipment component know who owns it
            self.equipment.owner = self

            # there must be and Item component for the Equipment component to work properly
            self.item = Item()
            self.item.owner = self
    def test_can_update_conjured_items_quality(self):
        item = Item("Conjured", 25, 35)

        expected_quality = 33

        self.assertTrue(
            ConjuredService.update_quality(item) == expected_quality)
    def test_can_set_agedBrie_quality(self):
        item = Item("Aged Brie", 25, 30)
        q_value = -10

        self.assertTrue(AgedBrieService.set_item_quality(item, q_value) == 0)

        self.assertTrue(AgedBrieService.increase_item_quality(item, 100) < 50)
Beispiel #9
0
    def test_can_update_sulfura_item(self):
        item = Item("Sulfuras", 25, 50)
        sell_in_expected = item.sell_in - 1
        quality_expected = 80

        self.assertTrue(
            SulfuraService.update_item(item) == (quality_expected,
                                                 sell_in_expected))
Beispiel #10
0
    def test_canInstantiateItem(self):
        item = Item("Sulfuras", 50, 80)

        self.assertTrue(hasattr(item, "sell_in"))

        self.assertTrue(hasattr(item, "quality"))

        self.assertTrue(hasattr(item, "name"))
Beispiel #11
0
    def test_can_increase_backstage_item_quality(self):
        item = Item("Backstage passes to johny", 50, 50)
        value_to_add = 3
        expected_val = 50

        self.assertTrue(
            BackstageService.increase_item_quality(item, value_to_add) ==
            expected_val)
    def test_can_set_conjured_item_quality(self):
        item = Item("Conjured", 25, 35)
        q_value = 100

        expected_quality = 50

        self.assertTrue(
            ConjuredService.set_item_quality(item, q_value) ==
            expected_quality)
Beispiel #13
0
    def __init__(self, user):
        self.window = Tk()
        self.window.title('Add Items')
        self.window.geometry('500x500+0+0')

        self.item = Item()
        # self.user = user

        self.update_index = ""

        self.item_name = Label(self.window, text="Item Name")
        self.item_name.grid(row=0, column=0)

        self.entry_name = Entry(self.window)
        self.entry_name.grid(row=0, column=1)

        self.item_type = Label(self.window, text="Item Type")
        self.item_type.grid(row=1, column=0)

        self.entry_type = Entry(self.window)
        self.entry_type.grid(row=1, column=1)

        self.item_rate = Label(self.window, text="Item Rate")
        self.item_rate.grid(row=2, column=0)

        self.entry_rate = Entry(self.window)
        self.entry_rate.grid(row=2, column=1)

        self.item_add = Button(self.window,
                               text="Add Item",
                               command=self.add_item)
        self.item_add.grid(row=3, column=0)

        self.item_update = Button(self.window,
                                  text="Update Item",
                                  command=self.update_item)
        self.item_update.grid(row=3, column=1)

        self.item_tree = ttk.Treeview(self.window,
                                      columns=('name', 'type', 'rate'))
        self.item_tree.grid(row=4, column=0, columnspan=2)
        self.item_tree['show'] = 'headings'
        self.item_tree.column('name', width=100)
        self.item_tree.column('type', width=100)
        self.item_tree.column('rate', width=100)
        self.item_tree.heading('name', text="Name")
        self.item_tree.heading('type', text="Type")
        self.item_tree.heading('rate', text="Rate")

        self.item_type = Label(self.window, text="Welcome ")
        self.item_type.grid(row=5, column=0)

        self.show_item_tree()
        self.show_menu()

        self.window.mainloop()
    def test_can_reduce_conjured_item_quality(self):
        item = Item("Conjured", 25, 35)

        value_to_reduce = 2

        expected_quality = 33

        self.assertTrue(
            ConjuredService.reduce_item_quality(item, value_to_reduce) ==
            expected_quality)
Beispiel #15
0
def create_item(item_dict):
    name = item_dict["name"]
    description = item_dict["description"]
    mass = item_dict.get("mass",1)
    value = item_dict.get("value",0)
    droppable = item_dict.get("droppable",False)

    item_object = Item(name, description, mass, value, droppable)

    return item_object
Beispiel #16
0
    def test_identify_aged_brie_type(self):
        item = Item('Aged Brie', 25, 50)

        item2 = Item("sulfuras", 35, 50)

        item3 = Item("conjured", 35, 50)

        item4 = Item("Backstage passes to johny concert", 35, 50)

        item5 = Item('passes to john legend', 25, 50)

        self.assertTrue(ItemService.is_aged_brie, item)

        self.assertTrue(ItemService.is_item_sulfuras, item2)

        self.assertFalse(ItemService.is_aged_brie(item2))

        self.assertTrue(ItemService.is_item_conjured, item3)

        self.assertTrue(ItemService.is_item_back_stage(item4))

        self.assertFalse(ItemService.is_item_back_stage(item5))
Beispiel #17
0
    def makeSpells(self):
        cur = self.getCursor()
        query = "select name, attr, qt, setid from spells " + self.makeSQLWhere(
        )
        cur.execute(query)
        rows = cur.fetchall()

        spellsList = []

        for row in rows:
            item = Item()
            item.name = row["name"]
            item.attributes = row["attr"].split(", ")

            for i in range(0, row["qt"]):
                spellsList.append(item)

        return spellsList
    def test_can_update_items(self):
        current_time = "00:00:00"
        items = [
            Item("Sulfuras", 20, 40),
            Item("Conjured", 25, 60),
            Item("Backstage passes to johny", 2, 46)
        ]

        expected_first_item = Item("Sulfuras", 19, 80)
        expected_second_item = Item("Conjured", 24, 50)
        tirth_expeted_item = Item("Backstage passes to johny", 1, 49)

        new_items_list = GildedRose.update_items(items, current_time)

        self.assertTrue(
            ItemService.are_item_equal(new_items_list[0], expected_first_item))

        self.assertTrue(
            ItemService.are_item_equal(new_items_list[1],
                                       expected_second_item))

        self.assertTrue(
            ItemService.are_item_equal(new_items_list[2], tirth_expeted_item))
Beispiel #19
0
def place_objects(room):
    """choose random number of monsters"""

    # maximum number of monsters per room
    max_monsters = from_dungeon_level([[2, 1], [3, 4], [5, 6]])
    num_monsters = libtcod.random_get_int(0, 0, max_monsters)

    # chance of each monster
    monster_chances = {}
    monster_chances[
        'orc'] = 80  # orc always shows up, even if all other monsters have 0 chance
    monster_chances['troll'] = from_dungeon_level([[15, 3], [30, 5], [60, 7]])
    monster_chances['feral orc'] = from_dungeon_level([[15, 8], [30, 10],
                                                       [60, 12]])
    monster_chances['feral troll'] = from_dungeon_level([[15, 10], [30, 12],
                                                         [60, 14]])
    monster_chances['dragon'] = from_dungeon_level([[15, 12], [20, 15]])

    # maximum number of items per room
    max_items = from_dungeon_level([[1, 1], [2, 4]])
    num_items = libtcod.random_get_int(0, 0, max_items)

    # chance of each item (by default they have a chance of 0 at level 1, which then goes up)
    item_chances = {}
    item_chances[
        'heal'] = 35  # healing potion always shows up, even if all other items have 0 chance
    item_chances['lightning'] = from_dungeon_level([[25, 4]])
    item_chances['fireball'] = from_dungeon_level([[25, 6]])
    item_chances['confuse'] = from_dungeon_level([[10, 2]])
    item_chances['sword'] = from_dungeon_level([[5, 4]])
    item_chances['sword of awesomeness'] = from_dungeon_level([[5, 10]])
    item_chances['shield'] = from_dungeon_level([[15, 8]])
    item_chances['shield of awesomeness'] = from_dungeon_level([[5, 10]])

    for _ in range(num_monsters):
        #choose random spot for this monster
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            choice = random_choice(monster_chances)
            if choice == 'orc':
                #create an orc
                fighter_component = Fighter(\
                    hp=20, defense=0, power=4, xp=35, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(x, y, var.ORC_TILE, 'orc', libtcod.desaturated_green,\
                    blocks=True, fighter=fighter_component, ai=ai_component)
            elif choice == 'troll':
                #create a troll
                fighter_component = Fighter(\
                    hp=30, defense=2, power=8, xp=100, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(x, y, var.TROLL_TILE, 'troll', libtcod.darker_green,\
                    blocks=True, fighter=fighter_component, ai=ai_component)
            elif choice == 'feral orc':
                #create a feral orc
                fighter_component = Fighter(\
                    hp=25, defense=1, power=6, xp=65, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(x, y, var.ORC_TILE, 'feral orc', libtcod.crimson,\
                    blocks=True, fighter=fighter_component, ai=ai_component)
            elif choice == 'feral troll':
                #create a feral troll
                fighter_component = Fighter(\
                    hp=40, defense=3, power=10, xp=150, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(x, y, var.TROLL_TILE, 'feral troll', libtcod.crimson,\
                    blocks=True, fighter=fighter_component, ai=ai_component)
            elif choice == 'dragon':
                #create a dragon
                fighter_component = Fighter(\
                    hp=100, defense=4, power=15, xp=500, death_function=monster_death)
                ai_component = BasicMonster()

                monster = Object(x, y, '$', 'dragon', libtcod.dark_red,\
                    blocks=True, fighter=fighter_component, ai=ai_component)

            var.game_objects.append(monster)

    for _ in range(num_items):
        #choose random spot for this item
        x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1)
        y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1)

        #only place it if the tile is not blocked
        if not is_blocked(x, y):
            choice = random_choice(item_chances)
            if choice == 'heal':
                #create a healing potion (70% chance)
                item_component = Item(use_function=cast_heal)

                item = Object(x, y, var.HEALINGPOTION_TILE, 'healing potion', libtcod.violet,\
                    item=item_component, always_visible=True)
            elif choice == 'lightning':
                #create a lightning bolt scroll (10% chance)
                item_component = Item(use_function=cast_lightning)

                item = Object(x, y, '#', 'scroll of lightning bolt', libtcod.light_yellow,\
                    item=item_component, always_visible=True)
            elif choice == 'fireball':
                #create a fireball scroll (10% chance)
                item_component = Item(use_function=cast_fireball)

                item = Object(x, y, '#', 'scroll of fireball', libtcod.light_yellow,\
                    item=item_component, always_visible=True)
            elif choice == 'confuse':
                #create a confuse scroll (10% chance)
                item_component = Item(use_function=cast_confuse)

                item = Object(x, y, '#', 'scroll of confusion', libtcod.light_yellow,\
                    item=item_component, always_visible=True)
            elif choice == 'sword':
                # create a sword
                equipment_component = Equipment(slot='right hand',
                                                power_bonus=3)
                item = Object(x,
                              y,
                              var.SWORD_TILE,
                              'sword',
                              libtcod.sky,
                              equipment=equipment_component)
            elif choice == 'shield':
                # create a shield
                equipment_component = Equipment(slot='left hand',
                                                defense_bonus=1)
                item = Object(x, y, var.SHIELD_TILE, 'shield', libtcod.dark_orange,\
                    equipment=equipment_component)
            elif choice == 'sword of awesomeness':
                # create a sword of awesomeness
                equipment_component = Equipment(slot='right hand',
                                                power_bonus=10)
                item = Object(x,
                              y,
                              var.SWORD_TILE,
                              'sword of awesomeness',
                              libtcod.dark_sky,
                              equipment=equipment_component)
            elif choice == 'shield of awesomeness':
                # create a shield of awesomeness
                equipment_component = Equipment(slot='left hand',
                                                defense_bonus=5)
                item = Object(x, y, var.SHIELD_TILE, 'shield of awesomeness', libtcod.dark_amber,\
                    equipment=equipment_component)

            var.game_objects.append(item)
            item.send_to_back()  #items appear below other objects
            item.always_visible = True  # items are visible even out-of-FOV, if in an explored area
Beispiel #20
0
    @staticmethod
    def is_end_of_the_day(my_time):
        return GildedRose.time_in_right_format(
            my_time) and my_time == "00:00:00"

    @staticmethod
    def update_items(items, current_time):
        if GildedRose.is_end_of_the_day(current_time):
            for item in items:
                if ItemService.is_item_conjured(item):
                    ConjuredService.update_quality(item)
                elif ItemService.is_item_back_stage(item):
                    BackstageService.update_item_quality(item)
                elif ItemService.is_item_sulfuras(item):
                    SulfuraService.update_item(item)
                elif ItemService.is_aged_brie(item):
                    AgedBrieService.update_item(item)
                elif not ItemService.is_special_item(item):
                    StandardItemService.update_item_quality(item)
            return items


if __name__ == '__main__':
    while True:
        items = [
            Item("Sulfuras", 20, 40),
            Item("Conjured", 25, 60),
            Item("Backstage passes to johny", 2, 46)
        ]
        GildedRose.update_items(items, datetime.now().strftime('%H:%M:%S'))
Beispiel #21
0
    def test_can_set_sulfuras_item_quality(self):
        item = Item("Sulfuras", 25, 50)

        self.assertTrue(SulfuraService.set_item_quality(item) == 80)
Beispiel #22
0
    def test_can_detect_items_of_valid_type(self):
        self.assertRaises(TypeError, ItemService.is_item_valid, 'item')

        self.assertTrue(ItemService.is_item_valid, Item('Sulfuras', 20, 80))
Beispiel #23
0
print("                    _________________________             __________")
print("Valos:    1200/1200|█████████████████████████|      65/65|██████████|")

#Create Black Magic
fire = Magic("Fire", 10, 100, "Black")
thunder = Magic("Thunder", 12, 124, "Black")
blizzard = Magic("Blizzard", 10, 100, "Black")
meteor = Magic("Meteor", 20, 200, "Black")
quake = Magic("Quake", 14, 140, "Black")

#Create White Magic
cure = Magic("Cure", 12, 120, "White")
cura = Magic("Cura", 18, 200, "White")

#Create Item
potion = Item("Potion", "potion", "Heals 50 hp", 50)
hiPotion = Item("Hi - Potion", "potion", "Heals 100 hp", 100)
superPotion = Item("Super Potion", "potion", "Heals 500 hp", 500)
elixer = Item("Elixer", "elixer", "Fully restores hp/mp of one party member",
              9999)
hiElixier = Item("Hi - Elixer", "elixer", "Fully restores party's hp/mp", 9999)

grenade = Item("Grenade", "attack", "Deals 500 damage", 500)

playerSpells = [fire, thunder, blizzard, meteor, cure, cura]
playerItems = [{
    "item": potion,
    "quantity": 5
}, {
    "item": hiPotion,
    "quantity": 5
Beispiel #24
0
    def can_back_stage_item_quality(self):
        item = Item("Backstage passes to johny", 25, 30)
        q_value = 100

        self.assertTrue(BackstageService.set_item_quality(item, q_value) == 50)
Beispiel #25
0
    def test_can_compare_two_items(self):
        item = Item('Aged Brie', 25, 50)

        item2 = Item('Aged Brie', 25, 50)

        self.assertTrue(ItemService.are_item_equal(item, item2))
 def test_can_set_item_quality(self):
     item = Item("passes to johnny", 25, 25)
     q_value = 60
     self.assertTrue(
         StandardItemService.set_item_quality(item, q_value) < 50)
Beispiel #27
0
def test_new_item():
    item = Item("Coke")
    assert item.type == "Coke"
 def test_can_reduce_item_quality(self):
     item = Item("passes to johnny", 25, 25)
     value = 1
     self.assertTrue(
         StandardItemService.reduce_item_quality_by(item, value) == 24)
 def test_can_update_agedBrie_items(self):
     item = Item("Aged Brie", 20, 30)
     expected_quality = item.quality + 1
     sell_in_expected = item.sell_in - 1
     self.assertTrue(AgedBrieService.update_item(item) == (expected_quality, sell_in_expected))