forked from len0rd/rockbox
Various clean-ups in preparation for 3.0: 1) Add a built-in default game which is used for the case when Sudoku is started as a plugin and no sudoku.ss exists - this prevents a time-consuming game generation; 2) Allow the user to abort a game generation by pressing any button; 3) Save the current state when user exits via the Quit button (previously, Sudoku only saved when quitting from the main menu); 4) Add a new "edit menu" for when the user is manually entering a new game, rather than displaying all options.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9944 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
254751f9fc
commit
506bac9cf7
2 changed files with 203 additions and 79 deletions
|
|
@ -1056,9 +1056,14 @@ select_template( void )
|
|||
init_template( i );
|
||||
}
|
||||
|
||||
static bool check_buttons(void)
|
||||
{
|
||||
int button = rb->button_get(false);
|
||||
return (button && (!(button & BUTTON_REL)) && (!(button & BUTTON_REPEAT)));
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
bool
|
||||
generate( void )
|
||||
{
|
||||
static int digits[ 9 ];
|
||||
|
|
@ -1066,6 +1071,10 @@ generate( void )
|
|||
int i;
|
||||
|
||||
start:
|
||||
/* Allow the user to abort generation by pressing any button */
|
||||
if (check_buttons())
|
||||
return false;
|
||||
|
||||
for( i = 0 ; i < 9 ; ++i )
|
||||
digits[ i ] = i + 1;
|
||||
|
||||
|
|
@ -1081,11 +1090,19 @@ start:
|
|||
for( i = 0 ; i < len_tmplt ; ++i )
|
||||
fill( tmplt[ i ], digits[ i % 9 ] );
|
||||
|
||||
/* Allow the user to abort generation by pressing any button */
|
||||
if (check_buttons())
|
||||
return false;
|
||||
|
||||
rb->yield();
|
||||
|
||||
if( 0 != solve( ) || idx_history < 81 )
|
||||
goto start;
|
||||
|
||||
/* Allow the user to abort generation by pressing any button */
|
||||
if (check_buttons())
|
||||
return false;
|
||||
|
||||
rb->yield();
|
||||
|
||||
for( i = 0 ; i < len_tmplt ; ++i )
|
||||
|
|
@ -1105,6 +1122,8 @@ start:
|
|||
goto start;
|
||||
|
||||
clear_moves( );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty)
|
||||
|
|
@ -1113,7 +1132,12 @@ bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty)
|
|||
|
||||
rb->srand(*rb->current_tick);
|
||||
|
||||
generate();
|
||||
rb->button_clear_queue();
|
||||
|
||||
if (!generate()) {
|
||||
/* User has aborted with a button press */
|
||||
return false;
|
||||
}
|
||||
|
||||
i=0;
|
||||
for (r=0;r<9;r++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue