Fix broken game test
This commit is contained in:
		@@ -10,7 +10,7 @@ class Monster(FightingEntity):
 | 
			
		||||
        And if a player is close to the monster, the monster run on the player.
 | 
			
		||||
        """
 | 
			
		||||
        # TODO If a player is close, move to the player
 | 
			
		||||
        while True:
 | 
			
		||||
        for _ in range(100):
 | 
			
		||||
            if choice([self.move_up, self.move_down,
 | 
			
		||||
                      self.move_left, self.move_right])():
 | 
			
		||||
                break
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,12 @@ class Map:
 | 
			
		||||
        self.entities.append(entity)
 | 
			
		||||
        entity.map = self
 | 
			
		||||
 | 
			
		||||
    def remove_entity(self, entity: "Entity") -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Unregister an entity from the map.
 | 
			
		||||
        """
 | 
			
		||||
        self.entities.remove(entity)
 | 
			
		||||
 | 
			
		||||
    def is_free(self, y: int, x: int) -> bool:
 | 
			
		||||
        """
 | 
			
		||||
        Indicates that the case at the coordinates (y, x) is empty.
 | 
			
		||||
@@ -138,9 +144,10 @@ class Entity:
 | 
			
		||||
            self.move(y, x)
 | 
			
		||||
        return free
 | 
			
		||||
 | 
			
		||||
    def move(self, y: int, x: int) -> None:
 | 
			
		||||
    def move(self, y: int, x: int) -> bool:
 | 
			
		||||
        self.y = y
 | 
			
		||||
        self.x = x
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    def move_up(self, force: bool = False) -> bool:
 | 
			
		||||
        return self.move(self.y - 1, self.x) if force else \
 | 
			
		||||
@@ -192,3 +199,4 @@ class FightingEntity(Entity):
 | 
			
		||||
 | 
			
		||||
    def die(self) -> None:
 | 
			
		||||
        self.dead = True
 | 
			
		||||
        self.map.remove_entity(self)
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ class TestEntities(unittest.TestCase):
 | 
			
		||||
        Test some random stuff with fighting entities.
 | 
			
		||||
        """
 | 
			
		||||
        entity = Hedgehog()
 | 
			
		||||
        self.assertIsNone(entity.act(self.map))
 | 
			
		||||
        self.map.add_entity(entity)
 | 
			
		||||
        self.assertEqual(entity.maxhealth, 10)
 | 
			
		||||
        self.assertEqual(entity.maxhealth, entity.health)
 | 
			
		||||
        self.assertEqual(entity.strength, 3)
 | 
			
		||||
@@ -41,6 +41,12 @@ class TestEntities(unittest.TestCase):
 | 
			
		||||
        self.assertIsNone(entity.hit(entity))
 | 
			
		||||
        self.assertTrue(entity.dead)
 | 
			
		||||
 | 
			
		||||
        entity = Hedgehog()
 | 
			
		||||
        self.map.add_entity(entity)
 | 
			
		||||
        entity.move(2, 6)
 | 
			
		||||
        self.map.tick()
 | 
			
		||||
        self.assertFalse(entity.y == 2 and entity.x == 6)
 | 
			
		||||
 | 
			
		||||
    def test_items(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Test some random stuff with items.
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import unittest
 | 
			
		||||
from dungeonbattle.bootstrap import Bootstrap
 | 
			
		||||
from dungeonbattle.display.display import Display
 | 
			
		||||
from dungeonbattle.display.display_manager import DisplayManager
 | 
			
		||||
from dungeonbattle.entities.player import Player
 | 
			
		||||
from dungeonbattle.game import Game, KeyValues, GameMode
 | 
			
		||||
from dungeonbattle.menus import MainMenuValues
 | 
			
		||||
 | 
			
		||||
@@ -90,6 +91,11 @@ class TestGame(unittest.TestCase):
 | 
			
		||||
        self.game.handle_key_pressed(KeyValues.ENTER)
 | 
			
		||||
        self.assertEqual(self.game.state, GameMode.PLAY)
 | 
			
		||||
 | 
			
		||||
        # Kill entities
 | 
			
		||||
        for entity in self.game.map.entities.copy():
 | 
			
		||||
            if not isinstance(entity, Player):
 | 
			
		||||
                self.game.map.remove_entity(entity)
 | 
			
		||||
 | 
			
		||||
        y, x = self.game.player.y, self.game.player.x
 | 
			
		||||
        self.game.handle_key_pressed(KeyValues.DOWN)
 | 
			
		||||
        new_y, new_x = self.game.player.y, self.game.player.x
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user