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 random import choice, shuffle
|
||||||
|
|
||||||
from .items import Item, Bomb
|
from .items import Bomb, Item
|
||||||
from .monsters import Monster
|
from .monsters import Monster
|
||||||
from .player import Player
|
from .player import Player
|
||||||
from ..interfaces import Entity, FightingEntity, FriendlyEntity, \
|
from ..interfaces import Entity, FightingEntity, FriendlyEntity, \
|
||||||
|
@ -48,11 +48,14 @@ class Chest(InventoryHolder, FriendlyEntity):
|
||||||
"""
|
"""
|
||||||
A class of chest inanimate entities which contain objects.
|
A class of chest inanimate entities which contain objects.
|
||||||
"""
|
"""
|
||||||
|
annihilated: bool
|
||||||
|
|
||||||
def __init__(self, name: str = "chest", inventory: list = None,
|
def __init__(self, name: str = "chest", inventory: list = None,
|
||||||
hazel: int = 0, *args, **kwargs):
|
hazel: int = 0, *args, **kwargs):
|
||||||
super().__init__(name=name, *args, **kwargs)
|
super().__init__(name=name, *args, **kwargs)
|
||||||
self.hazel = hazel
|
self.hazel = hazel
|
||||||
self.inventory = self.translate_inventory(inventory or [])
|
self.inventory = self.translate_inventory(inventory or [])
|
||||||
|
self.annihilated = False
|
||||||
if not self.inventory:
|
if not self.inventory:
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
self.inventory.append(choice(Item.get_all_items())())
|
self.inventory.append(choice(Item.get_all_items())())
|
||||||
|
@ -68,8 +71,9 @@ class Chest(InventoryHolder, FriendlyEntity):
|
||||||
"""
|
"""
|
||||||
A chest is not living, it can not take damage
|
A chest is not living, it can not take damage
|
||||||
"""
|
"""
|
||||||
if isinstance(attacker, Bomb) :
|
if isinstance(attacker, Bomb):
|
||||||
self.die()
|
self.die()
|
||||||
|
self.annihilated = True
|
||||||
return _("The chest exploded")
|
return _("The chest exploded")
|
||||||
return _("It's not really effective")
|
return _("It's not really effective")
|
||||||
|
|
||||||
|
@ -78,7 +82,7 @@ class Chest(InventoryHolder, FriendlyEntity):
|
||||||
"""
|
"""
|
||||||
Chest can not die
|
Chest can not die
|
||||||
"""
|
"""
|
||||||
return False
|
return self.annihilated
|
||||||
|
|
||||||
|
|
||||||
class Sunflower(FriendlyEntity):
|
class Sunflower(FriendlyEntity):
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from math import log
|
||||||
from random import randint
|
from random import randint
|
||||||
from typing import Dict, Optional, Tuple
|
from typing import Dict, Optional, Tuple
|
||||||
from math import log
|
|
||||||
|
|
||||||
from .items import Item
|
from .items import Item
|
||||||
from ..interfaces import FightingEntity, InventoryHolder
|
from ..interfaces import FightingEntity, InventoryHolder
|
||||||
from ..translations import gettext as _, Translator
|
from ..translations import gettext as _
|
||||||
|
|
||||||
|
|
||||||
class Player(InventoryHolder, FightingEntity):
|
class Player(InventoryHolder, FightingEntity):
|
||||||
|
@ -74,10 +74,10 @@ class Player(InventoryHolder, FightingEntity):
|
||||||
if diceroll <= self.charisma:
|
if diceroll <= self.charisma:
|
||||||
for entity in self.map.entities:
|
for entity in self.map.entities:
|
||||||
if entity.is_fighting_entity() and not entity == self \
|
if entity.is_fighting_entity() and not entity == self \
|
||||||
and entity.distance(self)<=3:
|
and entity.distance(self) <= 3:
|
||||||
found = True
|
found = True
|
||||||
entity.confused = 1
|
entity.confused = 1
|
||||||
entity.effects.append(["confused", 1, 3])
|
entity.effects.append(["confused", 1, 3])
|
||||||
if found:
|
if found:
|
||||||
self.map.logs.add_message(_(
|
self.map.logs.add_message(_(
|
||||||
"It worked! Nearby ennemies will be confused for 3 turns."))
|
"It worked! Nearby ennemies will be confused for 3 turns."))
|
||||||
|
@ -88,7 +88,6 @@ class Player(InventoryHolder, FightingEntity):
|
||||||
self.map.logs.add_message(
|
self.map.logs.add_message(
|
||||||
_("The dance was not effective..."))
|
_("The dance was not effective..."))
|
||||||
|
|
||||||
|
|
||||||
def level_up(self) -> None:
|
def level_up(self) -> None:
|
||||||
"""
|
"""
|
||||||
Add as many levels as possible to the player.
|
Add as many levels as possible to the player.
|
||||||
|
@ -97,18 +96,18 @@ class Player(InventoryHolder, FightingEntity):
|
||||||
self.level += 1
|
self.level += 1
|
||||||
self.current_xp -= self.max_xp
|
self.current_xp -= self.max_xp
|
||||||
self.max_xp = self.level * 10
|
self.max_xp = self.level * 10
|
||||||
self.maxhealth += int(2*log(self.level)/log(2))
|
self.maxhealth += int(2 * log(self.level) / log(2))
|
||||||
self.health = self.maxhealth
|
self.health = self.maxhealth
|
||||||
self.strength = self.strength + 1
|
self.strength = self.strength + 1
|
||||||
if self.level % 3 == 0 :
|
if self.level % 3 == 0:
|
||||||
self.dexterity += 1
|
self.dexterity += 1
|
||||||
self.constitution += 1
|
self.constitution += 1
|
||||||
if self.level % 4 == 0 :
|
if self.level % 4 == 0:
|
||||||
self.intelligence += 1
|
self.intelligence += 1
|
||||||
if self.level % 6 == 0 :
|
if self.level % 6 == 0:
|
||||||
self.charisma += 1
|
self.charisma += 1
|
||||||
if self.level % 10 == 0 and self.critical < 95:
|
if self.level % 10 == 0 and self.critical < 95:
|
||||||
self.critical += (100-self.charisma)//30
|
self.critical += (100 - self.charisma) // 30
|
||||||
# TODO Remove it, that's only for fun
|
# TODO Remove it, that's only for fun
|
||||||
self.map.spawn_random_entities(randint(3 * self.level,
|
self.map.spawn_random_entities(randint(3 * self.level,
|
||||||
10 * self.level))
|
10 * self.level))
|
||||||
|
|
|
@ -294,7 +294,6 @@ class Game:
|
||||||
if self.player.equipped_main:
|
if self.player.equipped_main:
|
||||||
self.player.equipped_main.throw(direction)
|
self.player.equipped_main.throw(direction)
|
||||||
|
|
||||||
|
|
||||||
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
|
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
|
||||||
"""
|
"""
|
||||||
In the inventory menu, we can interact with items or close the menu.
|
In the inventory menu, we can interact with items or close the menu.
|
||||||
|
|
|
@ -629,7 +629,7 @@ class Entity:
|
||||||
from squirrelbattle.entities.friendly import Merchant, Sunflower, \
|
from squirrelbattle.entities.friendly import Merchant, Sunflower, \
|
||||||
Trumpet, Chest
|
Trumpet, Chest
|
||||||
return [BodySnatchPotion, Bomb, Chest, GiantSeaEagle, Heart,
|
return [BodySnatchPotion, Bomb, Chest, GiantSeaEagle, Heart,
|
||||||
Hedgehog, Merchant, Rabbit, Sunflower, TeddyBear, Tiger,
|
Hedgehog, Merchant, Rabbit, Sunflower, TeddyBear, Tiger,
|
||||||
Trumpet]
|
Trumpet]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -754,8 +754,8 @@ class FightingEntity(Entity):
|
||||||
"""
|
"""
|
||||||
if self.confused:
|
if self.confused:
|
||||||
return _("{name} is confused, it can not hit {opponent}.")\
|
return _("{name} is confused, it can not hit {opponent}.")\
|
||||||
.format(name=_(self.translated_name.capitalize()),
|
.format(name=_(self.translated_name.capitalize()),
|
||||||
opponent=_(opponent.translated_name))
|
opponent=_(opponent.translated_name))
|
||||||
diceroll = randint(1, 100)
|
diceroll = randint(1, 100)
|
||||||
damage = max(0, self.strength)
|
damage = max(0, self.strength)
|
||||||
string = " "
|
string = " "
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import random
|
import random
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ..entities.friendly import Trumpet
|
from ..entities.friendly import Chest, Trumpet
|
||||||
from ..entities.items import BodySnatchPotion, Bomb, Explosion, Heart, Item
|
from ..entities.items import BodySnatchPotion, Bomb, Explosion, Heart, Item
|
||||||
from ..entities.monsters import GiantSeaEagle, Hedgehog, Rabbit, \
|
from ..entities.monsters import GiantSeaEagle, Hedgehog, Rabbit, \
|
||||||
TeddyBear, Tiger
|
TeddyBear, Tiger
|
||||||
|
@ -45,18 +45,19 @@ class TestEntities(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
entity = Tiger()
|
entity = Tiger()
|
||||||
self.map.add_entity(entity)
|
self.map.add_entity(entity)
|
||||||
self.assertEqual(entity.maxhealth, 20)
|
self.assertEqual(entity.maxhealth, 30)
|
||||||
self.assertEqual(entity.maxhealth, entity.health)
|
self.assertEqual(entity.maxhealth, entity.health)
|
||||||
self.assertEqual(entity.strength, 2)
|
self.assertEqual(entity.strength, 5)
|
||||||
for _ in range(9):
|
for _ in range(5):
|
||||||
self.assertEqual(entity.hit(entity),
|
self.assertEqual(entity.hit(entity),
|
||||||
"Tiger hits tiger. Tiger takes 2 damage.")
|
"Tiger hits tiger. Tiger takes 5 damage.")
|
||||||
self.assertFalse(entity.dead)
|
self.assertFalse(entity.dead)
|
||||||
self.assertEqual(entity.hit(entity), "Tiger hits tiger. "
|
self.assertEqual(entity.hit(entity), "Tiger hits tiger. "
|
||||||
+ "Tiger takes 2 damage. Tiger dies.")
|
+ "Tiger takes 5 damage. Tiger dies.")
|
||||||
self.assertTrue(entity.dead)
|
self.assertTrue(entity.dead)
|
||||||
|
|
||||||
entity = Rabbit()
|
entity = Rabbit()
|
||||||
|
entity.health = 15
|
||||||
entity.critical = 0
|
entity.critical = 0
|
||||||
self.map.add_entity(entity)
|
self.map.add_entity(entity)
|
||||||
entity.move(15, 44)
|
entity.move(15, 44)
|
||||||
|
@ -94,7 +95,20 @@ class TestEntities(unittest.TestCase):
|
||||||
self.assertTrue(entity.dead)
|
self.assertTrue(entity.dead)
|
||||||
self.assertGreaterEqual(self.player.current_xp, 3)
|
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()
|
fam = Trumpet()
|
||||||
entity = Rabbit()
|
entity = Rabbit()
|
||||||
self.map.add_entity(entity)
|
self.map.add_entity(entity)
|
||||||
|
@ -266,6 +280,15 @@ class TestEntities(unittest.TestCase):
|
||||||
player_state = player.save_state()
|
player_state = player.save_state()
|
||||||
self.assertEqual(player_state["current_xp"], 10)
|
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:
|
def test_critical_hit(self) -> None:
|
||||||
"""
|
"""
|
||||||
Ensure that critical hits are working.
|
Ensure that critical hits are working.
|
||||||
|
|
|
@ -160,6 +160,9 @@ class TestGame(unittest.TestCase):
|
||||||
KeyValues.SPACE)
|
KeyValues.SPACE)
|
||||||
self.assertEqual(KeyValues.translate_key('plop', self.game.settings),
|
self.assertEqual(KeyValues.translate_key('plop', self.game.settings),
|
||||||
None)
|
None)
|
||||||
|
self.assertEqual(KeyValues.translate_key(
|
||||||
|
self.game.settings.KEY_DANCE, self.game.settings),
|
||||||
|
KeyValues.DANCE)
|
||||||
|
|
||||||
def test_key_press(self) -> None:
|
def test_key_press(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -249,6 +252,30 @@ class TestGame(unittest.TestCase):
|
||||||
self.game.handle_key_pressed(KeyValues.WAIT)
|
self.game.handle_key_pressed(KeyValues.WAIT)
|
||||||
self.assertNotIn(explosion, self.game.map.entities)
|
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.game.handle_key_pressed(KeyValues.SPACE)
|
||||||
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
||||||
|
|
||||||
|
@ -350,7 +377,7 @@ class TestGame(unittest.TestCase):
|
||||||
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
||||||
|
|
||||||
# Navigate to "texture pack"
|
# Navigate to "texture pack"
|
||||||
for ignored in range(13):
|
for ignored in range(14):
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
|
|
||||||
# Change texture pack
|
# Change texture pack
|
||||||
|
|
Loading…
Reference in New Issue