Cover settings
This commit is contained in:
parent
0c17e74d6a
commit
caef8dc9b2
|
@ -1,5 +1,5 @@
|
|||
from random import randint
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
from .entities.player import Player
|
||||
from .enums import GameMode, KeyValues
|
||||
|
@ -56,7 +56,8 @@ class Game:
|
|||
self.handle_key_pressed(
|
||||
*KeyValues.translate_key(key, self.settings))
|
||||
|
||||
def handle_key_pressed(self, key: KeyValues, raw_key: str = '') -> None:
|
||||
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\
|
||||
-> None:
|
||||
"""
|
||||
Indicates what should be done when the given key is pressed,
|
||||
according to the current game state.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
from .enums import GameMode, KeyValues
|
||||
from .settings import Settings
|
||||
|
@ -59,8 +59,8 @@ class SettingsMenu(Menu):
|
|||
s = settings.dumps_to_string()
|
||||
self.values = s[6:-2].replace("\"", "").split(",\n ")
|
||||
|
||||
def handle_key_pressed(self, key: KeyValues, raw_key: str, game: Any) \
|
||||
-> None:
|
||||
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str,
|
||||
game: Any) -> None:
|
||||
"""
|
||||
For now, in the settings mode, we can only go backwards.
|
||||
"""
|
||||
|
|
|
@ -138,6 +138,40 @@ class TestGame(unittest.TestCase):
|
|||
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
||||
|
||||
def test_settings_menu(self) -> None:
|
||||
"""
|
||||
Ensure that the settings menu is working properly.
|
||||
"""
|
||||
self.game.settings = Settings()
|
||||
|
||||
# Open settings menu
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||
self.assertEqual(self.game.state, GameMode.SETTINGS)
|
||||
|
||||
# Define the "move up" key to 'w'
|
||||
self.assertFalse(self.game.settings_menu.waiting_for_key)
|
||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||
self.assertTrue(self.game.settings_menu.waiting_for_key)
|
||||
self.game.handle_key_pressed(None, 'w')
|
||||
self.assertFalse(self.game.settings_menu.waiting_for_key)
|
||||
self.assertEqual(self.game.settings.KEY_UP_PRIMARY, 'w')
|
||||
|
||||
# Navigate to "move left"
|
||||
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.UP)
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
|
||||
# Define the "move up" key to 'a'
|
||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||
self.assertTrue(self.game.settings_menu.waiting_for_key)
|
||||
self.game.handle_key_pressed(None, 'a')
|
||||
self.assertFalse(self.game.settings_menu.waiting_for_key)
|
||||
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
||||
|
||||
def test_dead_screen(self) -> None:
|
||||
"""
|
||||
Kill player and render dead screen.
|
||||
|
|
Loading…
Reference in New Issue