Esempio n. 1
0
def testItemCreation():
    items = []
    for _ in range(100):
        swordItem = ItemFactory(ItemList.Sword)
        items.append(swordItem)
        with pytest.raises(Exception):
            swordItem.getTimeLimit()
        assert swordItem.getName() == 'Sword'
Esempio n. 2
0
def testBagCreationAndFailureInAddingItems():
    potion = ItemFactory(ItemList.Potion)
    b = Bag(16,[potion])
    assert b.getCurrentWeight() == potion.getWeight()
    newPotion = ItemFactory(ItemList.Potion)
    assert b.addItem(newPotion)== False 
    assert b.getCurrentWeight() == potion.getWeight()
    assert b.getAllItems()== [potion]
Esempio n. 3
0
def testChooseItemAndRemoveIt():
    potion = ItemFactory(ItemList.Potion)
    coin = ItemFactory(ItemList.Coin)
    items = [potion, coin]
    b = Bag(100, items)
    potionItems =  b.getItemsFromType(ItemList.Potion)
    assert b.getAllItems() == items
    b.removeItem(potionItems[0])
    assert b.getAllItems() == [coin]
Esempio n. 4
0
 def randomItem(self):
     """
     @return random sword or armor for fighter level up
     """
     randType = randrange(2)  # 0:Sword  1:Armor
     if randType == 0:
         newItem = ItemFactory(ItemList.Sword)
     else:
         newItem = ItemFactory(ItemList.Armor)
     return newItem
Esempio n. 5
0
def testBalanceInBag():
    items = []
    coins = []
    potion = ItemFactory(ItemList.Potion)
    items.append(potion)
    for _ in range(3):
        coin = ItemFactory(ItemList.Coin)
        coins.append(coin)
        items.append(coin)

    b = Bag(100, items)
    assert b.getBalance() == sum([coin.getValue() for coin in coins])
Esempio n. 6
0
def testItemUsed():
    potionItem = ItemFactory(ItemList.Potion)
    numberOfUsesInCreationTime = potionItem.getRemainingUses()
    potionItem.useItem()
    assert potionItem.isUsed() == True
    assert potionItem.getRemainingUses() == numberOfUsesInCreationTime - 1
    sleep(2)
    assert potionItem.getTimeRemaining() < 148
Esempio n. 7
0
def testBagCreationAndAddingItems():
    potion = ItemFactory(ItemList.Potion)
    b = Bag(100, [potion])
    assert b.getCurrentWeight() == potion.getWeight()
    newPotion = ItemFactory(ItemList.Potion)
    b.addItem(newPotion)
    assert b.getCurrentWeight() == potion.getWeight() + newPotion.getWeight()
Esempio n. 8
0
def testItemConsumed():
    swordItem = ItemFactory(ItemList.Sword)
    numberOfUsesInCreationTime = swordItem.getRemainingUses()
    for _ in range(numberOfUsesInCreationTime):
        assert swordItem.isconsumed() == False
        swordItem.useItem()
    assert swordItem.isconsumed() == True
Esempio n. 9
0
def testGetPlayerBag():
    potion = ItemFactory(ItemList.Potion)
    bag = game.inventorywindow.bag
    player = Player(game, (0, 0), PlayerEnum.Rogue, actionPoint, lineOfSight,
                    defaultStats)
    player1 = Player(game, (1, 5), PlayerEnum.Fighter, actionPoint,
                     lineOfSight, defaultStats)
    assert player.getBag() == bag
    assert player1.getBag() == bag
Esempio n. 10
0
def test_Player_sellItem():
    potion = ItemFactory(ItemList.Potion)
    player = Player(game, (0, 0),
                    PlayerEnum.Rogue,
                    actionPoint,
                    skills=defaultSkills,
                    stats=defaultStats,
                    lineOfSightRadius=5)
    npc = NPC(game, (1, 2))
    playerBag = player.getBag()
    playerBag.flush()
    playerBag.addItem(potion)
    npcBag = npc.getBag()

    collectionOfCoins = [ItemFactory(ItemList.Coin) for _ in range(20)]
    for coin in collectionOfCoins:
        npcBag.addItem(coin)

    player.sellItem(ItemList.Potion, npc)
Esempio n. 11
0
def test_NPC_sellItem():
    player = Player(game, (0, 0),
                    PlayerEnum.Rogue,
                    actionPoint,
                    skills=defaultSkills,
                    stats=defaultStats,
                    lineOfSightRadius=5)
    potion = ItemFactory(ItemList.Potion)
    npc = NPC(game, (1, 2), [potion])

    playerBag = player.getBag()
    playerBag.flush()
    npcBag = npc.getBag()

    collectionOfCoins = [ItemFactory(ItemList.Coin) for _ in range(20)]
    for coin in collectionOfCoins:
        playerBag.addItem(coin)

    npc.sellItem(ItemList.Potion, player)
    assert len(playerBag.getAllItems()) == len(collectionOfCoins) + 1
Esempio n. 12
0
def testPlayerEquip():
    sword = ItemFactory(ItemList.Sword)
    armor = ItemFactory(ItemList.Armor)
    ringL = ItemFactory(ItemList.Ring)
    ringR2 = ItemFactory(ItemList.Ring)
    ringR = ItemFactory(ItemList.Ring)
    necklace = ItemFactory(ItemList.Necklace)
    potion = ItemFactory(ItemList.Potion)
    player = Player(game, (0, 0),
                    PlayerEnum.Rogue,
                    actionPoint,
                    skills=defaultSkills,
                    stats=defaultStats,
                    lineOfSightRadius=5)
    currentStats = dict(player.listStat)

    player.equip(potion)
    assert player.listStat == currentStats
    assert player.equipment == [None, None, None, None, None]

    player.getBag().flush()
    player.getBag().addItem(sword)
    player.getBag().addItem(necklace)
    player.getBag().addItem(ringR)
    player.getBag().addItem(ringL)
    player.getBag().addItem(ringR2)
    player.getBag().addItem(armor)
    player.equip(sword)
    player.equip(ringL)
    player.equip(necklace)
    player.equip(armor)
    player.equip(ringR)
    assert player.listStat != currentStats
    assert all(
        player.equipment[i] == item
        for i, item in enumerate([sword, armor, necklace, ringL, ringR]))
    items = player.getBag().getAllItems()
    assert all(i not in items for i in [sword, armor, necklace, ringL, ringR])

    player.equip(ringR2)
    assert all(
        player.equipment[i] == item
        for i, item in enumerate([sword, armor, necklace, ringL, ringR2]))
    assert ringR in player.getBag().getAllItems()
Esempio n. 13
0
def testItemNotFound():
    with pytest.raises(Exception):
        item = ItemFactory(ItemList.fakeItem)
Esempio n. 14
0
def testCoin():
    smallCoin = ItemFactory(ItemList.Coin)
    assert smallCoin.getRemainingUses() == 1
    smallCoin.useItem()
    assert smallCoin.isconsumed() == True
Esempio n. 15
0
def testItemNotUsed():
    swordItem = ItemFactory(ItemList.Sword)
    with pytest.raises(Exception):
        swordItem.getTimeLimit()
    assert swordItem.isUsed() == False
Esempio n. 16
0
def testRemoveNonexistantItemInBag():
    potion = ItemFactory(ItemList.Potion)
    b = Bag(16,[potion])
    newPotion = ItemFactory(ItemList.Potion)
    assert b.removeItem(newPotion)==False 
Esempio n. 17
0
hp = 100
armor = 7
strength = 2
dex = 3
con = 4
intell = 5
wis = 6
cha = 7
skillsPoint = 0

actionPoint = 10
defaultStats = (hp, armor, strength, dex, con, intell, wis, cha
                )  #( HP, armor, strength, dex, con, intell, wis, cha )
lineOfSight = 9

defaultPotions = ItemFactory(ItemList.Potion)


def testCharacterCreation():
    Character.ID = 50
    character = Character(game, defaultPosition, actionPoint, *defaultStats)
    assert character.getID() == 50
    assert character.getHP(
    ) == 100  # Cette méthode est redondante avec character.getAttribute(Attributes.HP), il faudrait l'enlever ou alors enlever HP des attributs
    assert character.getPosition() == defaultPosition
    assert character.getActionPoint() == 10
    for i, attribute in enumerate(Attributes):
        assert character.getAttribute(attribute) == defaultStats[i]
    print(defaultStats)
    fighter = Fighter(game,
                      defaultPosition,
Esempio n. 18
0
def testMaxWeightReached():
    b = Bag(10, [ItemFactory(ItemList.Armor) for _ in range(10)])
    assert b.getAllItems()== []