Testing + linting (yes there remains two linting errors, i don't know what to do.
This commit is contained in:
parent
afaa12d86b
commit
93e51d9240
|
@ -3,7 +3,7 @@
|
|||
|
||||
from random import choice, shuffle
|
||||
|
||||
from .items import Item, Bomb
|
||||
from .items import Bomb, Item
|
||||
from .monsters import Monster
|
||||
from .player import Player
|
||||
from ..interfaces import Entity, FightingEntity, FriendlyEntity, \
|
||||
|
@ -48,11 +48,14 @@ class Chest(InventoryHolder, FriendlyEntity):
|
|||
"""
|
||||
A class of chest inanimate entities which contain objects.
|
||||
"""
|
||||
annihilated: bool
|
||||
|
||||
def __init__(self, name: str = "chest", inventory: list = None,
|
||||
hazel: int = 0, *args, **kwargs):
|
||||
super().__init__(name=name, *args, **kwargs)
|
||||
self.hazel = hazel
|
||||
self.inventory = self.translate_inventory(inventory or [])
|
||||
self.annihilated = False
|
||||
if not self.inventory:
|
||||
for i in range(3):
|
||||
self.inventory.append(choice(Item.get_all_items())())
|
||||
|
@ -70,6 +73,7 @@ class Chest(InventoryHolder, FriendlyEntity):
|
|||
"""
|
||||
if isinstance(attacker, Bomb):
|
||||
self.die()
|
||||
self.annihilated = True
|
||||
return _("The chest exploded")
|
||||
return _("It's not really effective")
|
||||
|
||||
|
@ -78,7 +82,7 @@ class Chest(InventoryHolder, FriendlyEntity):
|
|||
"""
|
||||
Chest can not die
|
||||
"""
|
||||
return False
|
||||
return self.annihilated
|
||||
|
||||
|
||||
class Sunflower(FriendlyEntity):
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from math import log
|
||||
from random import randint
|
||||
from typing import Dict, Optional, Tuple
|
||||
from math import log
|
||||
|
||||
from .items import Item
|
||||
from ..interfaces import FightingEntity, InventoryHolder
|
||||
from ..translations import gettext as _, Translator
|
||||
from ..translations import gettext as _
|
||||
|
||||
|
||||
class Player(InventoryHolder, FightingEntity):
|
||||
|
@ -88,7 +88,6 @@ class Player(InventoryHolder, FightingEntity):
|
|||
self.map.logs.add_message(
|
||||
_("The dance was not effective..."))
|
||||
|
||||
|
||||
def level_up(self) -> None:
|
||||
"""
|
||||
Add as many levels as possible to the player.
|
||||
|
|
|
@ -294,7 +294,6 @@ class Game:
|
|||
if self.player.equipped_main:
|
||||
self.player.equipped_main.throw(direction)
|
||||
|
||||
|
||||
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
|
||||
"""
|
||||
In the inventory menu, we can interact with items or close the menu.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import random
|
||||
import unittest
|
||||
|
||||
from ..entities.friendly import Trumpet
|
||||
from ..entities.friendly import Chest, Trumpet
|
||||
from ..entities.items import BodySnatchPotion, Bomb, Explosion, Heart, Item
|
||||
from ..entities.monsters import GiantSeaEagle, Hedgehog, Rabbit, \
|
||||
TeddyBear, Tiger
|
||||
|
@ -45,18 +45,19 @@ class TestEntities(unittest.TestCase):
|
|||
"""
|
||||
entity = Tiger()
|
||||
self.map.add_entity(entity)
|
||||
self.assertEqual(entity.maxhealth, 20)
|
||||
self.assertEqual(entity.maxhealth, 30)
|
||||
self.assertEqual(entity.maxhealth, entity.health)
|
||||
self.assertEqual(entity.strength, 2)
|
||||
for _ in range(9):
|
||||
self.assertEqual(entity.strength, 5)
|
||||
for _ in range(5):
|
||||
self.assertEqual(entity.hit(entity),
|
||||
"Tiger hits tiger. Tiger takes 2 damage.")
|
||||
"Tiger hits tiger. Tiger takes 5 damage.")
|
||||
self.assertFalse(entity.dead)
|
||||
self.assertEqual(entity.hit(entity), "Tiger hits tiger. "
|
||||
+ "Tiger takes 2 damage. Tiger dies.")
|
||||
+ "Tiger takes 5 damage. Tiger dies.")
|
||||
self.assertTrue(entity.dead)
|
||||
|
||||
entity = Rabbit()
|
||||
entity.health = 15
|
||||
entity.critical = 0
|
||||
self.map.add_entity(entity)
|
||||
entity.move(15, 44)
|
||||
|
@ -94,7 +95,20 @@ class TestEntities(unittest.TestCase):
|
|||
self.assertTrue(entity.dead)
|
||||
self.assertGreaterEqual(self.player.current_xp, 3)
|
||||
|
||||
# Test the familiars
|
||||
# Test that a chest is destroyed by a bomb
|
||||
bomb = Bomb()
|
||||
bomb.owner = self.player
|
||||
bomb.move(3, 6)
|
||||
self.map.add_entity(bomb)
|
||||
chest = Chest()
|
||||
chest.move(4, 6)
|
||||
self.map.add_entity(chest)
|
||||
bomb.exploding = True
|
||||
for _ in range(5):
|
||||
self.map.tick(self.player)
|
||||
self.assertTrue(chest.annihilated)
|
||||
|
||||
def test_familiar(self) -> None:
|
||||
fam = Trumpet()
|
||||
entity = Rabbit()
|
||||
self.map.add_entity(entity)
|
||||
|
@ -266,6 +280,15 @@ class TestEntities(unittest.TestCase):
|
|||
player_state = player.save_state()
|
||||
self.assertEqual(player_state["current_xp"], 10)
|
||||
|
||||
player = Player()
|
||||
player.map = self.map
|
||||
player.add_xp(700)
|
||||
for _ in range(13):
|
||||
player.level_up()
|
||||
self.assertEqual(player.level, 12)
|
||||
self.assertEqual(player.critical, 5 + 95 // 30)
|
||||
self.assertEqual(player.charisma, 3)
|
||||
|
||||
def test_critical_hit(self) -> None:
|
||||
"""
|
||||
Ensure that critical hits are working.
|
||||
|
|
|
@ -160,6 +160,9 @@ class TestGame(unittest.TestCase):
|
|||
KeyValues.SPACE)
|
||||
self.assertEqual(KeyValues.translate_key('plop', self.game.settings),
|
||||
None)
|
||||
self.assertEqual(KeyValues.translate_key(
|
||||
self.game.settings.KEY_DANCE, self.game.settings),
|
||||
KeyValues.DANCE)
|
||||
|
||||
def test_key_press(self) -> None:
|
||||
"""
|
||||
|
@ -249,6 +252,30 @@ class TestGame(unittest.TestCase):
|
|||
self.game.handle_key_pressed(KeyValues.WAIT)
|
||||
self.assertNotIn(explosion, self.game.map.entities)
|
||||
|
||||
rabbit = Rabbit()
|
||||
self.game.map.add_entity(rabbit)
|
||||
self.game.player.move(1, 6)
|
||||
rabbit.move(3, 6)
|
||||
self.game.player.charisma = 11
|
||||
self.game.handle_key_pressed(KeyValues.DANCE)
|
||||
self.assertEqual(rabbit.confused, 1)
|
||||
string = rabbit.hit(self.game.player)
|
||||
self.assertEqual(string,
|
||||
"{name} is confused, it can not hit {opponent}."
|
||||
.format(name=_(rabbit.translated_name.capitalize()
|
||||
), opponent=_(
|
||||
self.game.player.translated_name
|
||||
)))
|
||||
rabbit.confused = 0
|
||||
self.game.player.charisma = 0
|
||||
self.game.handle_key_pressed(KeyValues.DANCE)
|
||||
self.assertEqual(rabbit.confused, 0)
|
||||
rabbit.die()
|
||||
|
||||
self.game.player.charisma = 11
|
||||
self.game.handle_key_pressed(KeyValues.DANCE)
|
||||
self.game.player.charisma = 1
|
||||
|
||||
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
||||
|
||||
|
@ -350,7 +377,7 @@ class TestGame(unittest.TestCase):
|
|||
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
||||
|
||||
# Navigate to "texture pack"
|
||||
for ignored in range(13):
|
||||
for ignored in range(14):
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
|
||||
# Change texture pack
|
||||
|
|
Loading…
Reference in New Issue