Merge branch 'new_game' into 'master'
New game See merge request ynerant/dungeon-battle!14
This commit is contained in:
commit
4cdf90853a
|
@ -1,11 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from dungeonbattle.entities.player import Player
|
|
||||||
from dungeonbattle.interfaces import Map
|
from dungeonbattle.interfaces import Map
|
||||||
from .display import Display
|
from .display import Display
|
||||||
|
|
||||||
|
|
||||||
class MapDisplay(Display):
|
class MapDisplay(Display):
|
||||||
player: Player
|
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
super().__init__(*args)
|
super().__init__(*args)
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Game:
|
||||||
"""
|
"""
|
||||||
map: Map
|
map: Map
|
||||||
player: Player
|
player: Player
|
||||||
|
# display_actions is a display interface set by the bootstrapper
|
||||||
display_actions: Callable[[DisplayActions], None]
|
display_actions: Callable[[DisplayActions], None]
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
@ -101,6 +102,10 @@ class Game:
|
||||||
if key == KeyValues.ENTER:
|
if key == KeyValues.ENTER:
|
||||||
option = self.main_menu.validate()
|
option = self.main_menu.validate()
|
||||||
if option == menus.MainMenuValues.START:
|
if option == menus.MainMenuValues.START:
|
||||||
|
self.new_game()
|
||||||
|
self.display_actions(DisplayActions.UPDATE)
|
||||||
|
self.state = GameMode.PLAY
|
||||||
|
if option == menus.MainMenuValues.RESUME:
|
||||||
self.state = GameMode.PLAY
|
self.state = GameMode.PLAY
|
||||||
elif option == menus.MainMenuValues.SAVE:
|
elif option == menus.MainMenuValues.SAVE:
|
||||||
self.save_game()
|
self.save_game()
|
||||||
|
|
|
@ -38,7 +38,8 @@ class MainMenuValues(Enum):
|
||||||
"""
|
"""
|
||||||
Values of the main menu
|
Values of the main menu
|
||||||
"""
|
"""
|
||||||
START = 'Jouer'
|
START = 'Nouvelle partie'
|
||||||
|
RESUME = 'Continuer'
|
||||||
SAVE = 'Sauvegarder'
|
SAVE = 'Sauvegarder'
|
||||||
LOAD = 'Charger'
|
LOAD = 'Charger'
|
||||||
SETTINGS = 'Paramètres'
|
SETTINGS = 'Paramètres'
|
||||||
|
|
|
@ -26,6 +26,7 @@ class TestGame(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
old_state = self.game.save_state()
|
old_state = self.game.save_state()
|
||||||
|
|
||||||
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.assertEqual(self.game.main_menu.validate(), MainMenuValues.SAVE)
|
self.assertEqual(self.game.main_menu.validate(), MainMenuValues.SAVE)
|
||||||
self.game.handle_key_pressed(KeyValues.ENTER) # Save game
|
self.game.handle_key_pressed(KeyValues.ENTER) # Save game
|
||||||
|
@ -94,6 +95,9 @@ class TestGame(unittest.TestCase):
|
||||||
self.assertEqual(self.game.main_menu.validate(),
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
MainMenuValues.START)
|
MainMenuValues.START)
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
|
MainMenuValues.RESUME)
|
||||||
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.assertEqual(self.game.main_menu.validate(),
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
MainMenuValues.SAVE)
|
MainMenuValues.SAVE)
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
|
@ -124,6 +128,9 @@ class TestGame(unittest.TestCase):
|
||||||
self.assertEqual(self.game.main_menu.validate(),
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
MainMenuValues.SAVE)
|
MainMenuValues.SAVE)
|
||||||
self.game.handle_key_pressed(KeyValues.UP)
|
self.game.handle_key_pressed(KeyValues.UP)
|
||||||
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
|
MainMenuValues.RESUME)
|
||||||
|
self.game.handle_key_pressed(KeyValues.UP)
|
||||||
self.assertEqual(self.game.main_menu.validate(),
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
MainMenuValues.START)
|
MainMenuValues.START)
|
||||||
|
|
||||||
|
@ -162,6 +169,29 @@ 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_new_game(self) -> None:
|
||||||
|
"""
|
||||||
|
Ensure that the start button starts a new game.
|
||||||
|
"""
|
||||||
|
old_map = self.game.map
|
||||||
|
old_player = self.game.player
|
||||||
|
self.game.handle_key_pressed(KeyValues.ENTER) # Start new game
|
||||||
|
new_map = self.game.map
|
||||||
|
new_player = self.game.player
|
||||||
|
# Ensure that
|
||||||
|
self.assertNotEqual(old_map, new_map)
|
||||||
|
self.assertNotEqual(old_player, new_player)
|
||||||
|
|
||||||
|
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||||
|
old_map = new_map
|
||||||
|
old_player = new_player
|
||||||
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
|
self.game.handle_key_pressed(KeyValues.ENTER) # Resume game
|
||||||
|
new_map = self.game.map
|
||||||
|
new_player = self.game.player
|
||||||
|
self.assertEqual(old_map, new_map)
|
||||||
|
self.assertEqual(old_player, new_player)
|
||||||
|
|
||||||
def test_settings_menu(self) -> None:
|
def test_settings_menu(self) -> None:
|
||||||
"""
|
"""
|
||||||
Ensure that the settings menu is working properly.
|
Ensure that the settings menu is working properly.
|
||||||
|
@ -172,6 +202,7 @@ class TestGame(unittest.TestCase):
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||||
self.assertEqual(self.game.state, GameMode.SETTINGS)
|
self.assertEqual(self.game.state, GameMode.SETTINGS)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue