1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2006 Alexander Levin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 GUI part of reversi. Code is inspired by sudoku code by Dave Chapman
24 which is copyright (c) 2005 Dave Chapman and is released under the
25 GNU General Public License.
31 Use the arrow keys to move cursor, and press TOGGLE to place a stone.
33 At any time during the game, press MENU to bring up the game menu with
42 #include "reversi-game.h"
43 #include "reversi-strategy.h"
44 #include "reversi-gui.h"
46 #include "lib/playback_control.h"
50 /* This is initialized at the start of the plugin and used to determine the
51 * Appropriate game board size/legend spacing if the font is larger than a cell
54 static int font_width
;
55 static int font_height
;
57 /* Where the board begins */
61 #if LCD_HEIGHT > LCD_WIDTH
62 #define MARGIN_W (XOFS*2+1)
63 #define MARGIN_H (YOFS*2+1)
67 #define MARGIN_W (XOFS*2 + 16)
68 #define MARGIN_H (YOFS*2+1)
73 #if ( (LCD_WIDTH - MARGIN_W) / (BOARD_SIZE+MARGIN_C_W)) < \
74 ( (LCD_HEIGHT - MARGIN_H) / (BOARD_SIZE+MARGIN_C_H))
76 #define CELL_PRE ( ( (LCD_WIDTH * LCD_PIXEL_ASPECT_WIDTH / \
77 LCD_PIXEL_ASPECT_HEIGHT) - MARGIN_W) / \
78 (BOARD_SIZE+MARGIN_C_W) )
80 #define CELL_WIDTH (CELL_PRE*LCD_PIXEL_ASPECT_HEIGHT / LCD_PIXEL_ASPECT_WIDTH)
81 #define CELL_HEIGHT (CELL_PRE)
83 #define CELL_PRE ( ( (LCD_HEIGHT * LCD_PIXEL_ASPECT_HEIGHT / \
84 LCD_PIXEL_ASPECT_WIDTH) - MARGIN_H) / \
85 (BOARD_SIZE+MARGIN_C_H) )
87 #define CELL_WIDTH (CELL_PRE)
88 #define CELL_HEIGHT (CELL_PRE*LCD_PIXEL_ASPECT_WIDTH / LCD_PIXEL_ASPECT_HEIGHT)
91 /* Total width and height of the board without enclosing box */
92 #define BOARD_WIDTH (CELL_WIDTH*BOARD_SIZE)
93 #define BOARD_HEIGHT (CELL_HEIGHT*BOARD_SIZE)
95 /* Thickness of the white cells' lines */
96 #if (CELL_WIDTH >= 10) && (CELL_HEIGHT >= 10)
97 #define CELL_LINE_THICKNESS CELL_WIDTH/5
99 #define CELL_LINE_THICKNESS 1
102 /* Margins within a cell */
103 #define STONE_MARGIN 2
105 #define CURSOR_MARGIN 1
107 /* Upper left corner of a cell */
108 #define CELL_X(c) (XOFS + (c)*CELL_WIDTH)
109 #define CELL_Y(r) (YOFS + (r)*CELL_HEIGHT)
111 /* Used for touchscreen to convert an X/Y location to a cell location */
112 #define CELL_C(x) (((x)-XOFS)/CELL_WIDTH)
113 #define CELL_R(y) (((y)-YOFS)/CELL_HEIGHT)
115 #if LCD_HEIGHT > LCD_WIDTH
116 #define LEGEND_X(lc) (CELL_X(lc))
117 #define LEGEND_Y(lr) ((CELL_HEIGHT > font_height) ? \
118 CELL_Y(BOARD_SIZE+lr) + YOFS + 1 : \
119 BOARD_HEIGHT + 2*YOFS + font_height*(lr-BOARD_SIZE))
121 #define LEGEND_X(lc) (CELL_X(BOARD_SIZE+lc) + XOFS + 1)
122 #define LEGEND_Y(lr) (CELL_HEIGHT > font_height ? \
123 CELL_Y(lr) : font_height*(lr)+YOFS)
128 static reversi_board_t game
;
130 /* --- Setting values --- */
132 /* Playing strategies used by white and black players */
133 const game_strategy_t
*white_strategy
;
134 const game_strategy_t
*black_strategy
;
136 /* Cursor position */
137 static int cur_row
, cur_col
;
139 /* Color for the next move (BLACK/WHITE) */
140 static int cur_player
;
142 /* Active cursor wrapping mode */
143 static cursor_wrap_mode_t cursor_wrap_mode
;
145 static bool quit_plugin
;
146 static bool game_finished
;
148 #ifdef HAVE_TOUCHSCREEN
149 #include "lib/pluginlib_touchscreen.h"
150 /* This uses the touchscreen library functions/structures. */
152 /* This defines the number of buttons used; only used in this C file. */
153 #define TOUCHBUTTON_COUNT 3
155 /* Define the button locations, widths and heights */
157 #if LCD_HEIGHT < LCD_WIDTH
158 /* Define Menu button x, y, width, height */
159 #define B_MENU_X LEGEND_X(0)
160 #define B_MENU_Y (LCD_HEIGHT-LCD_HEIGHT/2)
161 #define B_MENU_W (LCD_WIDTH-LEGEND_X(0))
162 #define B_MENU_H (LCD_HEIGHT/4)
163 /* Define Quit Button x, y, width, height */
164 #define B_QUIT_X LEGEND_X(0)
165 #define B_QUIT_Y (LCD_HEIGHT-LCD_HEIGHT/4)
166 #define B_QUIT_W (LCD_WIDTH-LEGEND_X(0))
167 #define B_QUIT_H (LCD_HEIGHT/4)
169 /* Define Menu button x, y, width, height */
170 #define B_MENU_X (LCD_WIDTH/2 - XOFS)
171 #define B_MENU_Y (CELL_HEIGHT*BOARD_SIZE+YOFS*2)
172 #define B_MENU_W (LCD_WIDTH/4 - XOFS)
173 #define B_MENU_H (2*CELL_HEIGHT)
174 /* Define Quit Button x, y, width, height */
175 #define B_QUIT_X (B_MENU_X + B_MENU_W + 1)
176 #define B_QUIT_Y (CELL_HEIGHT*BOARD_SIZE+YOFS*2)
177 #define B_QUIT_W (LCD_WIDTH/4 - XOFS)
178 #define B_QUIT_H (2*CELL_HEIGHT)
181 /* This is the button initialization/definition. The first element is the
182 * Viewport. This is defined in lcd.h, but the elements are:
183 * int x - X location of button/viewport
184 * int y - Y location of button/viewport
185 * int width - Width of button/viewport
186 * int height - Height of button/viewport
187 * int font - Font to be used on button/viewport
188 * int drawmode- Modes defined in lcd.h
189 * unsigned fg_pattern - foreground color
190 * unsigned bg_pattern - backbround color
191 * unsigned lss_pattern - Selector colors (currently unused)
192 * unsigned lse_pattern - |
193 * unsigned lst_pattern - \/
195 * The rest of the touch button elements are:
196 * bool repeat - requires the area be held for the action
197 * int action - action this button will return
198 * bool invisible - Is this an invisible button?
199 * char *title - Specify a title
200 * fb_data *pixmap- Currently unused, but will allow for a graphic
202 struct touchbutton reversi_buttons
[TOUCHBUTTON_COUNT
] =
204 { {B_MENU_X
, B_MENU_Y
, B_MENU_W
, B_MENU_H
, 0, FONT_UI
,
205 -1, STYLE_DEFAULT
, 0, 0xFFFF, 0, 0, 0},
206 false, REVERSI_BUTTON_MENU
, false, "Menu", NULL
},
208 { {B_QUIT_X
, B_QUIT_Y
, B_QUIT_W
, B_QUIT_H
, 0, FONT_UI
,
209 -1, STYLE_DEFAULT
, 0, 0xFFFF, 0, 0, 0},
210 false, REVERSI_BUTTON_QUIT
, false, "Quit", NULL
},
212 { {0, 0, XOFS
+BOARD_WIDTH
, YOFS
+BOARD_HEIGHT
, 0, 0,
213 -1, STYLE_DEFAULT
, 0, 0xFFFF, 0, 0, 0},
214 false, REVERSI_BUTTON_MAKE_MOVE
, true, NULL
, NULL
}
218 /* Initialises the state of the game (starts a new game) */
219 static void reversi_gui_init(void) {
220 reversi_init_game(&game
);
221 game_finished
= false;
224 /* Place the cursor so that WHITE can make a move */
230 /* Draws the cursor in the specified cell. Cursor is drawn in the complement
231 * mode, i.e. drawing it twice will result in no changes on the screen.
233 static void reversi_gui_display_cursor(int row
, int col
) {
235 old_mode
= rb
->lcd_get_drawmode();
239 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
240 rb
->lcd_drawline(x
+CURSOR_MARGIN
, y
+CURSOR_MARGIN
,
241 x
+CELL_WIDTH
-CURSOR_MARGIN
, y
+CELL_HEIGHT
-CURSOR_MARGIN
);
242 rb
->lcd_drawline(x
+CURSOR_MARGIN
, y
+CELL_HEIGHT
-CURSOR_MARGIN
,
243 x
+CELL_WIDTH
-CURSOR_MARGIN
, y
+CURSOR_MARGIN
);
245 /* Draw the shadows */
246 rb
->lcd_hline(x
, x
+CELL_WIDTH
-1, YOFS
-3);
247 rb
->lcd_hline(x
, x
+CELL_WIDTH
-1, YOFS
+BOARD_HEIGHT
+3);
248 rb
->lcd_vline(XOFS
-3, y
, y
+CELL_HEIGHT
-1);
249 rb
->lcd_vline(XOFS
+BOARD_WIDTH
+3, y
, y
+CELL_HEIGHT
-1);
251 rb
->lcd_set_drawmode(old_mode
);
256 /* Draws the cell of the specified color (WHITE/BLACK) assuming that
257 * the upper left corner of the cell is at (x, y) */
258 static void reversi_gui_draw_cell(int x
, int y
, int color
) {
260 if (color
== WHITE
) {
261 for (i
= 0; i
< CELL_LINE_THICKNESS
; i
++) {
265 CELL_WIDTH
+1-2*(STONE_MARGIN
+i
),
266 CELL_HEIGHT
+1-2*(STONE_MARGIN
+i
)
269 } else if (color
== BLACK
) {
270 rb
->lcd_fillrect(x
+STONE_MARGIN
, y
+STONE_MARGIN
,
271 CELL_WIDTH
-STONE_MARGIN
-1, CELL_HEIGHT
-1-STONE_MARGIN
);
273 /* Cell is free -> nothing to do */
278 /* Draws the complete screen */
279 static void reversi_gui_display_board(void) {
280 int x
, y
, r
, c
, x_width
, x_height
;
281 /* This viewport is used to draw a scrolling score */
282 struct viewport tempvp
;
285 /* Clear the display buffer */
286 rb
->lcd_clear_display();
287 rb
->lcd_set_drawmode(DRMODE_FG
);
289 /* Thicker board box */
290 rb
->lcd_drawrect(XOFS
-1, YOFS
-1, BOARD_WIDTH
+3, BOARD_HEIGHT
+3);
292 /* Draw the gridlines */
293 for (r
=0, x
=XOFS
, y
=YOFS
; r
<=BOARD_SIZE
;
294 r
++, x
+=CELL_WIDTH
, y
+=CELL_HEIGHT
) {
295 rb
->lcd_hline(XOFS
, XOFS
+BOARD_WIDTH
, y
);
296 rb
->lcd_vline(x
, YOFS
, YOFS
+BOARD_HEIGHT
);
299 /* Draw the stones. This is not the most efficient way but more readable */
300 for (r
=0; r
<BOARD_SIZE
; r
++) {
302 for (c
=0; c
<BOARD_SIZE
; c
++) {
304 reversi_gui_draw_cell(x
, y
, game
.board
[r
][c
]);
308 /* Draw the cursor */
309 reversi_gui_display_cursor(cur_row
, cur_col
);
311 /* Draw the current score */
312 reversi_count_occupied_cells(&game
, &r
, &c
);
313 rb
->lcd_getstringsize("x", &x_width
, &x_height
);
317 reversi_gui_draw_cell(x
, y
+(LEGEND_Y(1)-LEGEND_Y(0))/2-CELL_WIDTH
/2, BLACK
);
318 rb
->snprintf(buf
, sizeof(buf
), "%01d", c
);
320 rb
->viewport_set_defaults(&tempvp
, SCREEN_MAIN
);
322 tempvp
.x
=x
+CELL_WIDTH
+2;
324 tempvp
.width
=LCD_WIDTH
-tempvp
.x
;
325 tempvp
.height
=LEGEND_Y(1);
327 tempvp
.fg_pattern
= LCD_BLACK
;
328 tempvp
.bg_pattern
= LCD_WHITE
;
331 rb
->screens
[SCREEN_MAIN
]->set_viewport(&tempvp
);
332 rb
->lcd_puts_scroll(0, 0, buf
);
333 rb
->screens
[SCREEN_MAIN
]->set_viewport(NULL
);
337 reversi_gui_draw_cell(x
, y
+(LEGEND_Y(1)-LEGEND_Y(0))/2-CELL_WIDTH
/2, WHITE
);
338 rb
->snprintf(buf
, sizeof(buf
), "%01d", r
);
341 rb
->screens
[SCREEN_MAIN
]->set_viewport(&tempvp
);
342 rb
->lcd_puts_scroll(0, 0, buf
);
343 rb
->screens
[SCREEN_MAIN
]->set_viewport(NULL
);
345 /* Draw the box around the current player */
346 r
= (cur_player
== BLACK
? 0 : 1);
347 y
= LEGEND_Y(r
)+(LEGEND_Y(1)-LEGEND_Y(0))/2-CELL_WIDTH
/2;
348 rb
->lcd_drawrect(x
, y
, CELL_WIDTH
+1, CELL_HEIGHT
+1);
350 #if defined(HAVE_TOUCHSCREEN)
351 touchbutton_draw(reversi_buttons
, TOUCHBUTTON_COUNT
);
354 /* Update the screen */
363 /* Menu entries and the corresponding values for cursor wrap mode */
364 #define MENU_TEXT_WRAP_MODE "Cursor wrap mode"
365 static const struct opt_items cursor_wrap_mode_settings
[] = {
366 { "Flat board", -1 },
370 static const cursor_wrap_mode_t cursor_wrap_mode_values
[3] = {
371 WRAP_FLAT
, WRAP_SPHERE
, WRAP_TORUS
};
374 /* Menu entries and the corresponding values for available strategies */
375 #define MENU_TEXT_STRAT_WHITE "Strategy for white"
376 #define MENU_TEXT_STRAT_BLACK "Strategy for black"
378 static struct opt_items strategy_settings
[] = {
380 { "Naive robot", -1 },
381 { "Simple robot", -1 },
382 //{ "AB robot", -1 },
384 static const game_strategy_t
* const strategy_values
[] = {
385 &strategy_human
, &strategy_naive
, &strategy_simple
, /*&strategy_ab*/ };
388 /* Sets the strategy for the specified player. 'player' is the
389 pointer to the player to set the strategy for (actually,
390 either white_strategy or black_strategy). propmpt is the
391 text to show as the prompt in the menu */
392 static bool reversi_gui_choose_strategy(
393 const game_strategy_t
**player
, const char *prompt
) {
395 int num_items
= sizeof(strategy_settings
)/sizeof(strategy_settings
[0]);
398 for (i
= 0; i
< num_items
; i
++) {
399 if ((*player
) == strategy_values
[i
]) {
406 rb
->set_option(prompt
, &index
, INT
, strategy_settings
, num_items
, NULL
);
408 (*player
) = strategy_values
[index
];
410 if((*player
)->init_func
)
411 (*player
)->init_func(&game
);
417 /* Returns true iff USB ws connected while in the menu */
418 static bool reversi_gui_menu(void) {
419 int index
, num_items
, i
;
422 MENUITEM_STRINGLIST(menu
, "Reversi Menu", NULL
,
423 "Start new game", "Pass the move",
424 MENU_TEXT_STRAT_BLACK
, MENU_TEXT_STRAT_WHITE
,
425 MENU_TEXT_WRAP_MODE
, "Playback Control", "Quit");
427 result
= rb
->do_menu(&menu
, NULL
, NULL
, false);
430 case 0: /* Start a new game */
434 case 1: /* Pass the move to the partner */
435 cur_player
= reversi_flipped_color(cur_player
);
438 case 2: /* Strategy for black */
439 reversi_gui_choose_strategy(&black_strategy
, MENU_TEXT_STRAT_BLACK
);
442 case 3: /* Strategy for white */
443 reversi_gui_choose_strategy(&white_strategy
, MENU_TEXT_STRAT_WHITE
);
446 case 4: /* Cursor wrap mode */
447 num_items
= sizeof(cursor_wrap_mode_values
) /
448 sizeof(cursor_wrap_mode_values
[0]);
450 for (i
= 0; i
< num_items
; i
++) {
451 if (cursor_wrap_mode
== cursor_wrap_mode_values
[i
]) {
456 rb
->set_option(MENU_TEXT_WRAP_MODE
, &index
, INT
,
457 cursor_wrap_mode_settings
, 3, NULL
);
458 cursor_wrap_mode
= cursor_wrap_mode_values
[index
];
462 playback_control(NULL
);
470 return (result
== MENU_ATTACHED_USB
);
474 /* Calculates the new cursor position if the user wants to move it
475 * vertically as specified by delta. Current wrap mode is respected.
476 * The cursor is not actually moved.
478 * Returns true iff the cursor would be really moved. In any case, the
479 * new cursor position is stored in (new_row, new_col).
482 reversi_gui_cursor_pos_vmove(int row_delta
, int *new_row
, int *new_col
) {
483 *new_row
= cur_row
+ row_delta
;
487 switch (cursor_wrap_mode
) {
492 *new_row
= BOARD_SIZE
- 1;
495 *new_row
= BOARD_SIZE
- 1;
498 *new_col
= BOARD_SIZE
- 1;
502 } else if (*new_row
>= BOARD_SIZE
) {
503 switch (cursor_wrap_mode
) {
513 if (*new_col
>= BOARD_SIZE
) {
520 return (cur_row
!= (*new_row
)) || (cur_col
!= (*new_col
));
524 /* Calculates the new cursor position if the user wants to move it
525 * horisontally as specified by delta. Current wrap mode is respected.
526 * The cursor is not actually moved.
528 * Returns true iff the cursor would be really moved. In any case, the
529 * new cursor position is stored in (new_row, new_col).
532 reversi_gui_cursor_pos_hmove(int col_delta
, int *new_row
, int *new_col
) {
534 *new_col
= cur_col
+ col_delta
;
537 switch (cursor_wrap_mode
) {
542 *new_col
= BOARD_SIZE
- 1;
545 *new_col
= BOARD_SIZE
- 1;
548 *new_row
= BOARD_SIZE
- 1;
552 } else if (*new_col
>= BOARD_SIZE
) {
553 switch (cursor_wrap_mode
) {
563 if (*new_row
>= BOARD_SIZE
) {
570 return (cur_row
!= (*new_row
)) || (cur_col
!= (*new_col
));
574 /* Actually moves the cursor to the new position and updates the screen */
575 static void reversi_gui_move_cursor(int new_row
, int new_col
) {
576 int old_row
, old_col
;
584 /* Only update the changed cells since there are no global changes */
585 reversi_gui_display_cursor(old_row
, old_col
);
586 reversi_gui_display_cursor(new_row
, new_col
);
590 /* plugin entry point */
591 enum plugin_status
plugin_start(const void *parameter
) {
592 bool exit
, draw_screen
;
594 #ifdef HAVE_TOUCHSCREEN
595 int button_x
, button_y
;
597 #if defined(REVERSI_BUTTON_MENU_LONGPRESS) || \
598 defined(REVERSI_BUTTON_MAKE_MOVE_SHORTPRESS)
599 int lastbutton
= BUTTON_NONE
;
604 /* Initialize Font Width and height */
605 rb
->lcd_getstringsize("0", &font_width
, &font_height
);
607 #ifdef HAVE_TOUCHSCREEN
608 rb
->touchscreen_set_mode(TOUCHSCREEN_POINT
);
612 rb
->lcd_set_backdrop(NULL
);
613 rb
->lcd_set_foreground(LCD_BLACK
);
614 rb
->lcd_set_background(LCD_WHITE
);
617 /* Avoid compiler warnings */
620 rb
->srand(*rb
->current_tick
); /* Some AIs use rand() */
621 white_strategy
= &strategy_human
;
622 black_strategy
= &strategy_human
;
625 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
626 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
627 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
628 cursor_wrap_mode
= WRAP_TORUS
;
630 cursor_wrap_mode
= WRAP_FLAT
;
632 /* The main game loop */
636 while (!exit
&& !quit_plugin
) {
637 const game_strategy_t
*cur_strategy
= NULL
;
639 reversi_gui_display_board();
644 cur_strategy
= black_strategy
;
647 cur_strategy
= white_strategy
;
651 if(cur_strategy
->is_robot
&& !game_finished
) {
652 move_t m
= cur_strategy
->move_func(&game
, cur_player
);
653 reversi_make_move(&game
, MOVE_ROW(m
), MOVE_COL(m
), cur_player
);
654 cur_player
= reversi_flipped_color(cur_player
);
656 /* TODO: Add some delay to prevent it from being too fast ? */
657 /* TODO: Don't duplicate end of game check */
658 if (reversi_game_is_finished(&game
, cur_player
)) {
659 reversi_count_occupied_cells(&game
, &w_cnt
, &b_cnt
);
660 rb
->splashf(HZ
*2, "Game over. %s won.",
661 (w_cnt
>b_cnt
?"WHITE":"BLACK"));
662 draw_screen
= true; /* Must update screen after splash */
663 game_finished
= true;
668 /***********************************************************************
669 * Button handling code happens below here
670 **********************************************************************/
671 button
= rb
->button_get(true);
673 /* The touchscreen buttons can act as true buttons so OR them in */
674 #ifdef HAVE_TOUCHSCREEN
675 button
|= touchbutton_check_button(button
, reversi_buttons
, TOUCHBUTTON_COUNT
);
678 /* All of these button presses wait for the release event */
679 if(button
&BUTTON_REL
) {
680 #ifdef REVERSI_BUTTON_QUIT
681 if(button
&REVERSI_BUTTON_QUIT
) {
686 #ifdef HAVE_TOUCHSCREEN
687 if(button
&BUTTON_TOUCHSCREEN
) {
688 button_x
= rb
->button_get_data();
689 button_y
= button_x
& 0xffff;
692 /* Check if the click was in the gameboard, if so move cursor.
693 * This has to happen before MAKE_MOVE is processed.
695 if( (CELL_R(button_y
)<BOARD_SIZE
) &&
696 (CELL_C(button_x
)<BOARD_SIZE
) )
698 reversi_gui_move_cursor(CELL_R(button_y
), CELL_C(button_x
));
703 if( (button
&REVERSI_BUTTON_MENU
)
704 #if defined(REVERSI_BUTTON_MENU_LONGPRESS)
705 && (lastbutton
&BUTTON_REPEAT
)
708 if (reversi_gui_menu()) {
709 return PLUGIN_USB_CONNECTED
;
714 if(button
&REVERSI_BUTTON_MAKE_MOVE
715 #if defined(REVERSI_BUTTON_MAKE_MOVE_SHORTPRESS)
716 && !(lastbutton
&BUTTON_REPEAT
)
719 /* If you touch the game board instead of hitting menu after it
720 * has completed the game will exit out.
724 if (reversi_make_move(&game
, cur_row
, cur_col
, cur_player
) > 0) {
725 /* Move was made. Global changes on the board are possible */
726 draw_screen
= true; /* Redraw the screen next time */
727 cur_player
= reversi_flipped_color(cur_player
);
728 if (reversi_game_is_finished(&game
, cur_player
)) {
729 reversi_count_occupied_cells(&game
, &w_cnt
, &b_cnt
);
730 rb
->splashf(HZ
*2, "Game over. %s won.",
731 (w_cnt
>b_cnt
?"WHITE":"BLACK"));
732 draw_screen
= true; /* Must update screen after splash */
733 game_finished
= true;
736 /* An attempt to make an invalid move */
737 rb
->splash(HZ
/2, "Illegal move!");
739 /* Ignore any button presses during the splash */
740 rb
->button_clear_queue();
745 /* These button presses will run on a release or a repeat event */
746 if(button
&BUTTON_REL
|| button
&BUTTON_REPEAT
) {
747 /* Move cursor left */
748 if(button
&REVERSI_BUTTON_LEFT
) {
749 if (reversi_gui_cursor_pos_hmove(-1, &row
, &col
)) {
750 reversi_gui_move_cursor(row
, col
);
753 /* Move cursor right */
754 if(button
&REVERSI_BUTTON_RIGHT
) {
755 if (reversi_gui_cursor_pos_hmove(1, &row
, &col
)) {
756 reversi_gui_move_cursor(row
, col
);
760 if(button
&REVERSI_BUTTON_UP
) {
761 if (reversi_gui_cursor_pos_vmove(-1, &row
, &col
)) {
762 reversi_gui_move_cursor(row
, col
);
765 /* Move cursor down */
766 if(button
&REVERSI_BUTTON_DOWN
) {
767 if (reversi_gui_cursor_pos_vmove(1, &row
, &col
)) {
768 reversi_gui_move_cursor(row
, col
);
773 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
) {
774 /* Quit if USB has been connected */
775 return PLUGIN_USB_CONNECTED
;
777 #if defined(REVERSI_BUTTON_MENU_LONGPRESS) || \
778 defined(REVERSI_BUTTON_MAKE_MOVE_SHORTPRESS)
779 if (button
!= BUTTON_NONE
) {