made menu for chess
This commit is contained in:
parent
1b778b1b97
commit
7e721e7940
3 changed files with 48 additions and 6 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in a new issue