Test logs
This commit is contained in:
parent
589f825765
commit
1e5bb26f57
|
@ -17,6 +17,7 @@ class LogsDisplay(Display):
|
||||||
messages = messages[::-1]
|
messages = messages[::-1]
|
||||||
self.pad.clear()
|
self.pad.clear()
|
||||||
for i in range(min(self.height, len(messages))):
|
for i in range(min(self.height, len(messages))):
|
||||||
self.pad.addstr(self.height - i - 1, self.x, messages[i][:self.width])
|
self.pad.addstr(self.height - i - 1, self.x,
|
||||||
|
messages[i][:self.width])
|
||||||
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height,
|
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height,
|
||||||
self.x + self.width)
|
self.x + self.width)
|
||||||
|
|
|
@ -52,6 +52,7 @@ class Map:
|
||||||
self.start_x = start_x
|
self.start_x = start_x
|
||||||
self.tiles = tiles
|
self.tiles = tiles
|
||||||
self.entities = []
|
self.entities = []
|
||||||
|
self.logs = Logs()
|
||||||
|
|
||||||
def add_entity(self, entity: "Entity") -> None:
|
def add_entity(self, entity: "Entity") -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -42,9 +42,11 @@ class TestEntities(unittest.TestCase):
|
||||||
self.assertEqual(entity.maxhealth, entity.health)
|
self.assertEqual(entity.maxhealth, entity.health)
|
||||||
self.assertEqual(entity.strength, 2)
|
self.assertEqual(entity.strength, 2)
|
||||||
for _ in range(9):
|
for _ in range(9):
|
||||||
self.assertIsNone(entity.hit(entity))
|
self.assertEqual(entity.hit(entity),
|
||||||
|
"beaver hits beaver. beaver takes 2 damage.")
|
||||||
self.assertFalse(entity.dead)
|
self.assertFalse(entity.dead)
|
||||||
self.assertIsNone(entity.hit(entity))
|
self.assertEqual(entity.hit(entity), "beaver hits beaver. "
|
||||||
|
+ "beaver takes 2 damage. beaver dies.")
|
||||||
self.assertTrue(entity.dead)
|
self.assertTrue(entity.dead)
|
||||||
|
|
||||||
entity = Rabbit()
|
entity = Rabbit()
|
||||||
|
@ -64,6 +66,9 @@ class TestEntities(unittest.TestCase):
|
||||||
self.map.tick()
|
self.map.tick()
|
||||||
self.assertTrue(entity.y == 2 and entity.x == 6)
|
self.assertTrue(entity.y == 2 and entity.x == 6)
|
||||||
self.assertEqual(old_health - entity.strength, self.player.health)
|
self.assertEqual(old_health - entity.strength, self.player.health)
|
||||||
|
self.assertEqual(self.map.logs.messages[-1],
|
||||||
|
f"{entity.name} hits {self.player.name}. \
|
||||||
|
{self.player.name} takes {entity.strength} damage.")
|
||||||
|
|
||||||
# Fight the rabbit
|
# Fight the rabbit
|
||||||
old_health = entity.health
|
old_health = entity.health
|
||||||
|
|
|
@ -256,6 +256,18 @@ class TestGame(unittest.TestCase):
|
||||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||||
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
||||||
|
|
||||||
|
def test_logs(self) -> None:
|
||||||
|
"""
|
||||||
|
Tests the use of logs
|
||||||
|
"""
|
||||||
|
self.game.logs.add_message("Hello World !")
|
||||||
|
self.assertEqual(self.game.logs.messages, ["Hello World !"])
|
||||||
|
self.game.logs.add_messages(["Hello", "World"])
|
||||||
|
self.assertEqual(self.game.logs.messages, ["Hello World !",
|
||||||
|
"Hello", "World"])
|
||||||
|
self.game.logs.clear()
|
||||||
|
self.assertEqual(self.game.logs.messages, [])
|
||||||
|
|
||||||
def test_dead_screen(self) -> None:
|
def test_dead_screen(self) -> None:
|
||||||
"""
|
"""
|
||||||
Kill player and render dead screen.
|
Kill player and render dead screen.
|
||||||
|
|
Loading…
Reference in New Issue