This repository has been archived on 2022-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
zeropod/plugin/chess/__init__.py

36 lines
930 B
Python
Raw Normal View History

2022-04-24 10:07:39 -05:00
from cinput import ControlInput, Button
2022-04-24 13:32:14 -05:00
from enum import Enum, auto
2022-04-24 10:07:39 -05:00
from graphics import Graphics
from .draw import Draw
from .sunfish import initial
2022-04-24 13:32:14 -05:00
class GameState(Enum):
MAIN_MENU = auto()
THINKING = auto()
CHOOSE_ROW = auto()
CHOOSE_COL = auto()
GAME_OVER = auto()
2022-04-24 10:07:39 -05:00
def execute(cinput: ControlInput, graphics: Graphics, _):
2022-04-24 13:32:14 -05:00
graphics.clear()
2022-04-24 10:07:39 -05:00
draw = Draw(graphics)
2022-04-24 13:32:14 -05:00
draw.draw_board(initial)
state = GameState.MAIN_MENU
menu_index = 0
2022-04-24 10:07:39 -05:00
while True:
2022-04-24 13:32:14 -05:00
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