diff options
author | Dave Chapman <dave@dchapman.com> | 2006-05-15 20:08:37 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-05-15 20:08:37 +0000 |
commit | 506bac9cf792d4dbe58c5dc26432192670696f6e (patch) | |
tree | 4e8c81bce9c0685f22afa4209c6460b8498865ba /apps/plugins/sudoku/generator.c | |
parent | 254751f9fc408c8bf1d230e056f95fd92b92cab2 (diff) | |
download | rockbox-506bac9cf792d4dbe58c5dc26432192670696f6e.tar.gz rockbox-506bac9cf792d4dbe58c5dc26432192670696f6e.zip |
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
Diffstat (limited to 'apps/plugins/sudoku/generator.c')
-rw-r--r-- | apps/plugins/sudoku/generator.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/apps/plugins/sudoku/generator.c b/apps/plugins/sudoku/generator.c index 037798d761..eaef8c0f17 100644 --- a/apps/plugins/sudoku/generator.c +++ b/apps/plugins/sudoku/generator.c | |||
@@ -1056,9 +1056,14 @@ select_template( void ) | |||
1056 | init_template( i ); | 1056 | init_template( i ); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | static bool check_buttons(void) | ||
1060 | { | ||
1061 | int button = rb->button_get(false); | ||
1062 | return (button && (!(button & BUTTON_REL)) && (!(button & BUTTON_REPEAT))); | ||
1063 | } | ||
1059 | 1064 | ||
1060 | static | 1065 | static |
1061 | void | 1066 | bool |
1062 | generate( void ) | 1067 | generate( void ) |
1063 | { | 1068 | { |
1064 | static int digits[ 9 ]; | 1069 | static int digits[ 9 ]; |
@@ -1066,6 +1071,10 @@ generate( void ) | |||
1066 | int i; | 1071 | int i; |
1067 | 1072 | ||
1068 | start: | 1073 | start: |
1074 | /* Allow the user to abort generation by pressing any button */ | ||
1075 | if (check_buttons()) | ||
1076 | return false; | ||
1077 | |||
1069 | for( i = 0 ; i < 9 ; ++i ) | 1078 | for( i = 0 ; i < 9 ; ++i ) |
1070 | digits[ i ] = i + 1; | 1079 | digits[ i ] = i + 1; |
1071 | 1080 | ||
@@ -1081,11 +1090,19 @@ start: | |||
1081 | for( i = 0 ; i < len_tmplt ; ++i ) | 1090 | for( i = 0 ; i < len_tmplt ; ++i ) |
1082 | fill( tmplt[ i ], digits[ i % 9 ] ); | 1091 | fill( tmplt[ i ], digits[ i % 9 ] ); |
1083 | 1092 | ||
1093 | /* Allow the user to abort generation by pressing any button */ | ||
1094 | if (check_buttons()) | ||
1095 | return false; | ||
1096 | |||
1084 | rb->yield(); | 1097 | rb->yield(); |
1085 | 1098 | ||
1086 | if( 0 != solve( ) || idx_history < 81 ) | 1099 | if( 0 != solve( ) || idx_history < 81 ) |
1087 | goto start; | 1100 | goto start; |
1088 | 1101 | ||
1102 | /* Allow the user to abort generation by pressing any button */ | ||
1103 | if (check_buttons()) | ||
1104 | return false; | ||
1105 | |||
1089 | rb->yield(); | 1106 | rb->yield(); |
1090 | 1107 | ||
1091 | for( i = 0 ; i < len_tmplt ; ++i ) | 1108 | for( i = 0 ; i < len_tmplt ; ++i ) |
@@ -1105,6 +1122,8 @@ start: | |||
1105 | goto start; | 1122 | goto start; |
1106 | 1123 | ||
1107 | clear_moves( ); | 1124 | clear_moves( ); |
1125 | |||
1126 | return true; | ||
1108 | } | 1127 | } |
1109 | 1128 | ||
1110 | bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty) | 1129 | 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) | |||
1113 | 1132 | ||
1114 | rb->srand(*rb->current_tick); | 1133 | rb->srand(*rb->current_tick); |
1115 | 1134 | ||
1116 | generate(); | 1135 | rb->button_clear_queue(); |
1136 | |||
1137 | if (!generate()) { | ||
1138 | /* User has aborted with a button press */ | ||
1139 | return false; | ||
1140 | } | ||
1117 | 1141 | ||
1118 | i=0; | 1142 | i=0; |
1119 | for (r=0;r<9;r++) { | 1143 | for (r=0;r<9;r++) { |