diff options
| author | Zoltan Szabatin <[email protected]> | 2025-03-02 18:38:27 -0800 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-03-02 18:38:29 -0800 |
| commit | 225f4a227013443b09a205cabe73886facab4d2b (patch) | |
| tree | 939ef33031bb2c31cfc3eec96fbc7982ce585784 /src/splitscreen_duo/__init__.py | |
| parent | refactor: Move games to proper game enumeration (diff) | |
| download | splitscreen-duo-225f4a227013443b09a205cabe73886facab4d2b.tar.xz splitscreen-duo-225f4a227013443b09a205cabe73886facab4d2b.zip | |
feat: Add snake and benchmark games
Diffstat (limited to 'src/splitscreen_duo/__init__.py')
| -rw-r--r-- | src/splitscreen_duo/__init__.py | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/splitscreen_duo/__init__.py b/src/splitscreen_duo/__init__.py index e47c7cb..8233caf 100644 --- a/src/splitscreen_duo/__init__.py +++ b/src/splitscreen_duo/__init__.py @@ -1,3 +1,4 @@ +from .game import Game from . import menu from .command import Command import os @@ -5,6 +6,8 @@ import logging import pygame from .serial import Serial import json +from .games import benchmark, snake + def main() -> int: logger = logging.getLogger(__name__) @@ -19,9 +22,9 @@ def main() -> int: level=(logging.DEBUG if os.getenv("DEVELOPMENT", "").lower() else logging.INFO) ) print("The Dual Screen Console") - logger.info(f"running as {os.getenv("INSTANCE", "unknown")}") + logger.info(f"running as {os.getenv('INSTANCE', 'unknown')}") menu.init_display() - + is_running = True while is_running: @@ -38,6 +41,31 @@ def main() -> int: pygame.quit() return 0 + elif message.get("command") == Command.SELECT_GAME.value: + if message.get("value") == Game.BENCHMARK.value: + logger.info("received benchmark game selection from primary") + + game_result = benchmark.main_loop(menu.screen, serial) + + if ( + game_result + and game_result.get("command") == Command.QUIT.value + ): + pygame.quit() + + return 0 + elif message.get("value") == Game.SNAKE.value: + logger.info("received snake game selection from primary") + + game_result = snake.main_loop(menu.screen, serial, INSTANCE) + + if ( + game_result + and game_result.get("command") == Command.QUIT.value + ): + pygame.quit() + + return 0 except json.JSONDecodeError: logger.error("failed to decode serial message") @@ -55,6 +83,25 @@ def main() -> int: pygame.quit() return 0 + elif serial_command.get("command") == Command.SELECT_GAME.value: + if serial_command.get("value") == Game.BENCHMARK.value: + logger.info("starting benchmark game") + + game_result = benchmark.main_loop(menu.screen, serial) + + if game_result and game_result.get("command") == Command.QUIT.value: + pygame.quit() + + return 0 + elif serial_command.get("value") == Game.SNAKE.value: + logger.info("starting snake game") + + game_result = snake.main_loop(menu.screen, serial, INSTANCE) + + if game_result and game_result.get("command") == Command.QUIT.value: + pygame.quit() + + return 0 menu.draw_menu() |