diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py index 53f0ccf..df96b29 100644 --- a/dungeonbattle/entities/player.py +++ b/dungeonbattle/entities/player.py @@ -5,14 +5,14 @@ class Player(FightingEntity): maxhealth = 20 strength = 5 - def move_up(self) -> None: - self.check_move(self.y - 1, self.x, True) + def move_up(self) -> bool: + return self.check_move(self.y - 1, self.x, True) - def move_down(self) -> None: - self.check_move(self.y + 1, self.x, True) + def move_down(self) -> bool: + return self.check_move(self.y + 1, self.x, True) - def move_left(self) -> None: - self.check_move(self.y, self.x - 1, True) + def move_left(self) -> bool: + return self.check_move(self.y, self.x - 1, True) - def move_right(self) -> None: - self.check_move(self.y, self.x + 1, True) + def move_right(self) -> bool: + return self.check_move(self.y, self.x + 1, True) diff --git a/dungeonbattle/tests/entities_test.py b/dungeonbattle/tests/entities_test.py index 043919a..7b7902b 100644 --- a/dungeonbattle/tests/entities_test.py +++ b/dungeonbattle/tests/entities_test.py @@ -76,6 +76,22 @@ class TestEntities(unittest.TestCase): Test some random stuff with players. """ player = Player() + self.map.add_entity(player) + player.move(1, 6) self.assertEqual(player.strength, 5) self.assertEqual(player.health, player.maxhealth) self.assertEqual(player.maxhealth, 20) + + # Test movements and ensure that collisions are working + self.assertFalse(player.move_up()) + self.assertTrue(player.move_left()) + self.assertFalse(player.move_left()) + for i in range(8): + self.assertTrue(player.move_down()) + self.assertFalse(player.move_down()) + self.assertTrue(player.move_right()) + self.assertTrue(player.move_right()) + self.assertTrue(player.move_right()) + self.assertFalse(player.move_right()) + self.assertTrue(player.move_down()) + self.assertTrue(player.move_down())