diff --git a/__main__.py b/__main__.py index d5756ba..d6911dd 100644 --- a/__main__.py +++ b/__main__.py @@ -15,6 +15,10 @@ menu_config = [ MenuType.PLUGIN, {"plugin": "chess", "arg": None}), + MenuItem("Cube Timer", + MenuType.PLUGIN, + {"plugin": "cube", + "arg": None}), ]}), MenuItem("Information", MenuType.PLUGIN, diff --git a/plugin/chess/__init__.py b/plugin/chess/__init__.py index 45fe79c..dbb7812 100644 --- a/plugin/chess/__init__.py +++ b/plugin/chess/__init__.py @@ -1,13 +1,35 @@ from cinput import ControlInput, Button +from enum import Enum, auto from graphics import Graphics from .draw import Draw from .sunfish import initial +class GameState(Enum): + MAIN_MENU = auto() + THINKING = auto() + CHOOSE_ROW = auto() + CHOOSE_COL = auto() + GAME_OVER = auto() + def execute(cinput: ControlInput, graphics: Graphics, _): + graphics.clear() draw = Draw(graphics) - draw.draw(initial) + draw.draw_board(initial) + + state = GameState.MAIN_MENU + menu_index = 0 while True: - key = cinput.get_one_shot(5) - if key == Button.BTN_A: - return + if state == GameState.MAIN_MENU: + draw.draw_menu(menu_index) + + key = cinput.get_one_shot() + if state == GameState.MAIN_MENU: + if key == Button.DIR_U: + menu_index -= 1 + if menu_index < 0: + menu_index = 0 + elif key == Button.DIR_D: + menu_index += 1 + if menu_index > 2: + menu_index = 2 diff --git a/plugin/chess/draw.py b/plugin/chess/draw.py index c223ff5..70766a6 100644 --- a/plugin/chess/draw.py +++ b/plugin/chess/draw.py @@ -51,6 +51,11 @@ class Draw: " . ■ ■ ■ ■ . "], } + MENU = [ + "New (W)", + "New (B)", + "Quit"] + def __init__(self, graphics: Graphics): self._graphics = graphics @@ -68,10 +73,13 @@ class Draw: elif pixel =='-': self._graphics.pixel(x, y, c if filled else sqc) + def _clear_info(self): + self._graphics.fill_rect( + self.BOARD_SIZE, 0, self.BOARD_SIZE, self.BOARD_SIZE, 0) - def draw(self, board: str): + def draw_board(self, board: str): + self._graphics.fill_rect(0, 0, self.BOARD_SIZE, self.BOARD_SIZE, 0) nb = "".join(board.split()) - self._graphics.clear() c = True for row in range(8): c = not c @@ -86,3 +94,11 @@ class Draw: c = not c self._graphics.show() + + def draw_menu(self, menu_index: int): + self._clear_info() + self._graphics.text("Menu:", 12, 0, 1) + for i in range(len(self.MENU)): + marker = "> " if i == menu_index else " " + self._graphics.text(marker + self.MENU[i], 12, i + 2, 1) + self._graphics.show()