Test clicking on the screen
This commit is contained in:
parent
d9912cacad
commit
f453b82a58
|
@ -28,7 +28,7 @@ class Item(Entity):
|
||||||
"""
|
"""
|
||||||
if self.held:
|
if self.held:
|
||||||
self.held_by.inventory.remove(self)
|
self.held_by.inventory.remove(self)
|
||||||
self.map.add_entity(self)
|
self.held_by.map.add_entity(self)
|
||||||
self.move(self.held_by.y, self.held_by.x)
|
self.move(self.held_by.y, self.held_by.x)
|
||||||
self.held = False
|
self.held = False
|
||||||
self.held_by = None
|
self.held_by = None
|
||||||
|
@ -49,7 +49,7 @@ class Item(Entity):
|
||||||
"""
|
"""
|
||||||
self.held = True
|
self.held = True
|
||||||
self.held_by = player
|
self.held_by = player
|
||||||
self.map.remove_entity(self)
|
self.held_by.map.remove_entity(self)
|
||||||
player.inventory.append(self)
|
player.inventory.append(self)
|
||||||
|
|
||||||
def save_state(self) -> dict:
|
def save_state(self) -> dict:
|
||||||
|
|
|
@ -68,6 +68,7 @@ class Map:
|
||||||
"""
|
"""
|
||||||
Unregister an entity from the map.
|
Unregister an entity from the map.
|
||||||
"""
|
"""
|
||||||
|
if entity in self.entities:
|
||||||
self.entities.remove(entity)
|
self.entities.remove(entity)
|
||||||
|
|
||||||
def find_entities(self, entity_class: type) -> list:
|
def find_entities(self, entity_class: type) -> list:
|
||||||
|
|
|
@ -216,6 +216,33 @@ class TestGame(unittest.TestCase):
|
||||||
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)
|
||||||
|
|
||||||
|
def test_mouse_click(self) -> None:
|
||||||
|
"""
|
||||||
|
Simulate mouse clicks.
|
||||||
|
"""
|
||||||
|
self.game.state = GameMode.MAINMENU
|
||||||
|
|
||||||
|
# Settings menu
|
||||||
|
self.game.display_actions(DisplayActions.MOUSE, 25, 21)
|
||||||
|
self.assertEqual(self.game.main_menu.position, 4)
|
||||||
|
self.assertEqual(self.game.state, GameMode.SETTINGS)
|
||||||
|
|
||||||
|
bomb = Bomb()
|
||||||
|
bomb.hold(self.game.player)
|
||||||
|
bomb2 = Bomb()
|
||||||
|
bomb2.hold(self.game.player)
|
||||||
|
|
||||||
|
self.game.state = GameMode.INVENTORY
|
||||||
|
|
||||||
|
# Click nowhere
|
||||||
|
self.game.display_actions(DisplayActions.MOUSE, 0, 0)
|
||||||
|
self.assertEqual(self.game.state, GameMode.INVENTORY)
|
||||||
|
|
||||||
|
# Click on the second item
|
||||||
|
self.game.display_actions(DisplayActions.MOUSE, 8, 25)
|
||||||
|
self.assertEqual(self.game.state, GameMode.INVENTORY)
|
||||||
|
self.assertEqual(self.game.inventory_menu.position, 1)
|
||||||
|
|
||||||
def test_new_game(self) -> None:
|
def test_new_game(self) -> None:
|
||||||
"""
|
"""
|
||||||
Ensure that the start button starts a new game.
|
Ensure that the start button starts a new game.
|
||||||
|
|
Loading…
Reference in New Issue