diff options
author | Johannes Schwarz <ubuntuxer@rockbox.org> | 2009-07-14 11:12:09 +0000 |
---|---|---|
committer | Johannes Schwarz <ubuntuxer@rockbox.org> | 2009-07-14 11:12:09 +0000 |
commit | 9d7a1e457f699bdfb7e2039ae4d0807136cceba1 (patch) | |
tree | 9f9c5ef81e4491d51e98e4cc57bdae2e2df80c1f /apps/plugins | |
parent | 8cc169cb28f10719fb8e2defe8473cefe5027f91 (diff) | |
download | rockbox-9d7a1e457f699bdfb7e2039ae4d0807136cceba1.tar.gz rockbox-9d7a1e457f699bdfb7e2039ae4d0807136cceba1.zip |
Combine the two menus, improve highscore list, automatically save game, improve help text (buttons are missing yet) and clean up the code in jewels (part of FS#10139)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21858 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/jewels.c | 857 |
1 files changed, 300 insertions, 557 deletions
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index ec726cec8a..4db8d2baea 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c | |||
@@ -22,6 +22,8 @@ | |||
22 | ****************************************************************************/ | 22 | ****************************************************************************/ |
23 | 23 | ||
24 | #include "plugin.h" | 24 | #include "plugin.h" |
25 | #include "lib/display_text.h" | ||
26 | #include "lib/highscore.h" | ||
25 | #include "lib/playback_control.h" | 27 | #include "lib/playback_control.h" |
26 | 28 | ||
27 | #ifdef HAVE_LCD_BITMAP | 29 | #ifdef HAVE_LCD_BITMAP |
@@ -242,79 +244,68 @@ CONFIG_KEYPAD == MROBE500_PAD | |||
242 | #define TILE_WIDTH 22 | 244 | #define TILE_WIDTH 22 |
243 | #define TILE_HEIGHT 22 | 245 | #define TILE_HEIGHT 22 |
244 | #define YOFS 0 | 246 | #define YOFS 0 |
245 | #define NUM_SCORES 10 | 247 | #define NUM_SCORES 5 |
246 | 248 | ||
247 | /* use 16x16 tiles (iPod Nano) */ | 249 | /* use 16x16 tiles (iPod Nano) */ |
248 | #elif (LCD_HEIGHT == 132) && (LCD_WIDTH == 176) | 250 | #elif (LCD_HEIGHT == 132) && (LCD_WIDTH == 176) |
249 | #define TILE_WIDTH 16 | 251 | #define TILE_WIDTH 16 |
250 | #define TILE_HEIGHT 16 | 252 | #define TILE_HEIGHT 16 |
251 | #define YOFS 4 | 253 | #define YOFS 4 |
252 | #define NUM_SCORES 10 | 254 | #define NUM_SCORES 5 |
253 | 255 | ||
254 | /* use 16x16 tiles (H100, iAudio X5, iPod 3G, iPod 4G grayscale) */ | 256 | /* use 16x16 tiles (H100, iAudio X5, iPod 3G, iPod 4G grayscale) */ |
255 | #elif (LCD_HEIGHT == 128) && (LCD_WIDTH == 160) | 257 | #elif (LCD_HEIGHT == 128) && (LCD_WIDTH == 160) |
256 | #define TILE_WIDTH 16 | 258 | #define TILE_WIDTH 16 |
257 | #define TILE_HEIGHT 16 | 259 | #define TILE_HEIGHT 16 |
258 | #define YOFS 0 | 260 | #define YOFS 0 |
259 | #define NUM_SCORES 10 | 261 | #define NUM_SCORES 5 |
260 | 262 | ||
261 | /* use 14x14 tiles (H10 5/6 GB) */ | 263 | /* use 14x14 tiles (H10 5/6 GB) */ |
262 | #elif (LCD_HEIGHT == 128) && (LCD_WIDTH == 128) | 264 | #elif (LCD_HEIGHT == 128) && (LCD_WIDTH == 128) |
263 | #define TILE_WIDTH 14 | 265 | #define TILE_WIDTH 14 |
264 | #define TILE_HEIGHT 14 | 266 | #define TILE_HEIGHT 14 |
265 | #define YOFS 0 | 267 | #define YOFS 0 |
266 | #define NUM_SCORES 10 | 268 | #define NUM_SCORES 5 |
267 | 269 | ||
268 | /* use 13x13 tiles (iPod Mini) */ | 270 | /* use 13x13 tiles (iPod Mini) */ |
269 | #elif (LCD_HEIGHT == 110) && (LCD_WIDTH == 138) | 271 | #elif (LCD_HEIGHT == 110) && (LCD_WIDTH == 138) |
270 | #define TILE_WIDTH 13 | 272 | #define TILE_WIDTH 13 |
271 | #define TILE_HEIGHT 13 | 273 | #define TILE_HEIGHT 13 |
272 | #define YOFS 6 | 274 | #define YOFS 6 |
273 | #define NUM_SCORES 10 | 275 | #define NUM_SCORES 5 |
274 | 276 | ||
275 | /* use 12x12 tiles (iAudio M3) */ | 277 | /* use 12x12 tiles (iAudio M3) */ |
276 | #elif (LCD_HEIGHT == 96) && (LCD_WIDTH == 128) | 278 | #elif (LCD_HEIGHT == 96) && (LCD_WIDTH == 128) |
277 | #define TILE_WIDTH 12 | 279 | #define TILE_WIDTH 12 |
278 | #define TILE_HEIGHT 12 | 280 | #define TILE_HEIGHT 12 |
279 | #define YOFS 0 | 281 | #define YOFS 0 |
280 | #define NUM_SCORES 9 | 282 | #define NUM_SCORES 5 |
281 | 283 | ||
282 | /* use 10x10 tiles (Sansa c200) */ | 284 | /* use 10x10 tiles (Sansa c200) */ |
283 | #elif (LCD_HEIGHT == 80) && (LCD_WIDTH == 132) | 285 | #elif (LCD_HEIGHT == 80) && (LCD_WIDTH == 132) |
284 | #define TILE_WIDTH 10 | 286 | #define TILE_WIDTH 10 |
285 | #define TILE_HEIGHT 10 | 287 | #define TILE_HEIGHT 10 |
286 | #define YOFS 0 | 288 | #define YOFS 0 |
287 | #define NUM_SCORES 8 | 289 | #define NUM_SCORES 5 |
288 | 290 | ||
289 | /* use 10x8 tiles (iFP 700) */ | 291 | /* use 10x8 tiles (iFP 700) */ |
290 | #elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 128) | 292 | #elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 128) |
291 | #define TILE_WIDTH 10 | 293 | #define TILE_WIDTH 10 |
292 | #define TILE_HEIGHT 8 | 294 | #define TILE_HEIGHT 8 |
293 | #define YOFS 0 | 295 | #define YOFS 0 |
294 | #define NUM_SCORES 8 | 296 | #define NUM_SCORES 5 |
295 | 297 | ||
296 | /* use 10x8 tiles (Recorder, Ondio) */ | 298 | /* use 10x8 tiles (Recorder, Ondio) */ |
297 | #elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 112) | 299 | #elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 112) |
298 | #define TILE_WIDTH 10 | 300 | #define TILE_WIDTH 10 |
299 | #define TILE_HEIGHT 8 | 301 | #define TILE_HEIGHT 8 |
300 | #define YOFS 0 | 302 | #define YOFS 0 |
301 | #define NUM_SCORES 8 | 303 | #define NUM_SCORES 5 |
302 | 304 | ||
303 | #else | 305 | #else |
304 | #error JEWELS: Unsupported LCD | 306 | #error JEWELS: Unsupported LCD |
305 | #endif | 307 | #endif |
306 | 308 | ||
307 | /* save files */ | ||
308 | #define SCORE_FILE PLUGIN_GAMES_DIR "/jewels.score" | ||
309 | #define SAVE_FILE PLUGIN_GAMES_DIR "/jewels.save" | ||
310 | |||
311 | /* final game return status */ | ||
312 | #define BJ_QUIT_FROM_GAME 4 | ||
313 | #define BJ_END 3 | ||
314 | #define BJ_USB 2 | ||
315 | #define BJ_QUIT 1 | ||
316 | #define BJ_LOSE 0 | ||
317 | |||
318 | /* swap directions */ | 309 | /* swap directions */ |
319 | #define SWAP_UP 0 | 310 | #define SWAP_UP 0 |
320 | #define SWAP_RIGHT 1 | 311 | #define SWAP_RIGHT 1 |
@@ -331,6 +322,9 @@ CONFIG_KEYPAD == MROBE500_PAD | |||
331 | /* animation frame rate */ | 322 | /* animation frame rate */ |
332 | #define MAX_FPS 20 | 323 | #define MAX_FPS 20 |
333 | 324 | ||
325 | /* text margin */ | ||
326 | #define MARGIN 5 | ||
327 | |||
334 | /* Game types */ | 328 | /* Game types */ |
335 | enum game_type { | 329 | enum game_type { |
336 | GAME_TYPE_NORMAL, | 330 | GAME_TYPE_NORMAL, |
@@ -363,23 +357,21 @@ struct tile { | |||
363 | * score is the current level score | 357 | * score is the current level score |
364 | * segments is the number of cleared segments in the current run | 358 | * segments is the number of cleared segments in the current run |
365 | * level is the current level | 359 | * level is the current level |
360 | * tmp_type is the select type in the menu | ||
366 | * type is the game type (normal or puzzle) | 361 | * type is the game type (normal or puzzle) |
367 | * highscores is the list of high scores | ||
368 | * resume denotes whether to resume the currently loaded game | ||
369 | * dirty denotes whether the high scores are out of sync with the saved file | ||
370 | * playboard is the game playing board (first row is hidden) | 362 | * playboard is the game playing board (first row is hidden) |
371 | * num_jewels is the number of different jewels to use | 363 | * num_jewels is the number of different jewels to use |
364 | * playgame is true, if a game is started | ||
372 | */ | 365 | */ |
373 | struct game_context { | 366 | struct game_context { |
374 | unsigned int score; | 367 | unsigned int score; |
375 | unsigned int segments; | 368 | unsigned int segments; |
376 | unsigned int level; | 369 | unsigned int level; |
377 | unsigned int type; | 370 | unsigned int type; |
378 | unsigned int highscores[NUM_SCORES]; | 371 | unsigned int tmp_type; |
379 | bool resume; | ||
380 | bool dirty; | ||
381 | struct tile playboard[BJ_HEIGHT][BJ_WIDTH]; | 372 | struct tile playboard[BJ_HEIGHT][BJ_WIDTH]; |
382 | unsigned int num_jewels; | 373 | unsigned int num_jewels; |
374 | bool playgame; | ||
383 | }; | 375 | }; |
384 | 376 | ||
385 | #define MAX_NUM_JEWELS 7 | 377 | #define MAX_NUM_JEWELS 7 |
@@ -435,27 +427,11 @@ struct puzzle_level puzzle_levels[NUM_PUZZLE_LEVELS] = { | |||
435 | {4, 7, PUZZLE_TILE_LEFT|PUZZLE_TILE_UP} } }, | 427 | {4, 7, PUZZLE_TILE_LEFT|PUZZLE_TILE_UP} } }, |
436 | }; | 428 | }; |
437 | 429 | ||
438 | /***************************************************************************** | 430 | #define SAVE_FILE PLUGIN_GAMES_DIR "/jewels.save" |
439 | * jewels_init() initializes jewels data structures. | ||
440 | ******************************************************************************/ | ||
441 | static void jewels_init(struct game_context* bj) { | ||
442 | /* seed the rand generator */ | ||
443 | rb->srand(*rb->current_tick); | ||
444 | 431 | ||
445 | /* check for resumed game */ | 432 | #define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score" |
446 | if(bj->resume) { | 433 | struct highscore highest[NUM_SCORES]; |
447 | bj->resume = false; | ||
448 | return; | ||
449 | } | ||
450 | 434 | ||
451 | /* reset scoring */ | ||
452 | bj->level = 1; | ||
453 | bj->score = 0; | ||
454 | bj->segments = 0; | ||
455 | |||
456 | /* clear playing board */ | ||
457 | rb->memset(bj->playboard, 0, sizeof(bj->playboard)); | ||
458 | } | ||
459 | 435 | ||
460 | /***************************************************************************** | 436 | /***************************************************************************** |
461 | * jewels_setcolors() set the foreground and background colors. | 437 | * jewels_setcolors() set the foreground and background colors. |
@@ -468,6 +444,54 @@ static inline void jewels_setcolors(void) { | |||
468 | } | 444 | } |
469 | 445 | ||
470 | /***************************************************************************** | 446 | /***************************************************************************** |
447 | * jewels_loadgame() loads the saved game and returns load success. | ||
448 | ******************************************************************************/ | ||
449 | static bool jewels_loadgame(struct game_context* bj) | ||
450 | { | ||
451 | int fd; | ||
452 | bool loaded = false; | ||
453 | |||
454 | /* open game file */ | ||
455 | fd = rb->open(SAVE_FILE, O_RDONLY); | ||
456 | if(fd < 0) return loaded; | ||
457 | |||
458 | /* read in saved game */ | ||
459 | while(true) { | ||
460 | if(rb->read(fd, &bj->tmp_type, sizeof(bj->tmp_type)) <= 0) break; | ||
461 | if(rb->read(fd, &bj->type, sizeof(bj->type)) <= 0) break; | ||
462 | if(rb->read(fd, &bj->score, sizeof(bj->score)) <= 0) break; | ||
463 | if(rb->read(fd, &bj->level, sizeof(bj->level)) <= 0) break; | ||
464 | if(rb->read(fd, &bj->segments, sizeof(bj->segments)) <= 0) break; | ||
465 | if(rb->read(fd, &bj->num_jewels, sizeof(bj->num_jewels)) <= 0) break; | ||
466 | if(rb->read(fd, bj->playboard, sizeof(bj->playboard)) <= 0) break; | ||
467 | loaded = true; | ||
468 | break; | ||
469 | } | ||
470 | |||
471 | rb->close(fd); | ||
472 | |||
473 | return loaded; | ||
474 | } | ||
475 | |||
476 | /***************************************************************************** | ||
477 | * jewels_savegame() saves the current game state. | ||
478 | ******************************************************************************/ | ||
479 | static void jewels_savegame(struct game_context* bj) | ||
480 | { | ||
481 | int fd; | ||
482 | /* write out the game state to the save file */ | ||
483 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | ||
484 | rb->write(fd, &bj->tmp_type, sizeof(bj->tmp_type)); | ||
485 | rb->write(fd, &bj->type, sizeof(bj->type)); | ||
486 | rb->write(fd, &bj->score, sizeof(bj->score)); | ||
487 | rb->write(fd, &bj->level, sizeof(bj->level)); | ||
488 | rb->write(fd, &bj->segments, sizeof(bj->segments)); | ||
489 | rb->write(fd, &bj->num_jewels, sizeof(bj->num_jewels)); | ||
490 | rb->write(fd, bj->playboard, sizeof(bj->playboard)); | ||
491 | rb->close(fd); | ||
492 | } | ||
493 | |||
494 | /***************************************************************************** | ||
471 | * jewels_drawboard() redraws the entire game board. | 495 | * jewels_drawboard() redraws the entire game board. |
472 | ******************************************************************************/ | 496 | ******************************************************************************/ |
473 | static void jewels_drawboard(struct game_context* bj) { | 497 | static void jewels_drawboard(struct game_context* bj) { |
@@ -861,6 +885,8 @@ static unsigned int jewels_swapjewels(struct game_context* bj, | |||
861 | bool undo = false; | 885 | bool undo = false; |
862 | unsigned int points = 0; | 886 | unsigned int points = 0; |
863 | long lasttick, currenttick; | 887 | long lasttick, currenttick; |
888 | |||
889 | bj->playgame = true; | ||
864 | 890 | ||
865 | /* check for invalid parameters */ | 891 | /* check for invalid parameters */ |
866 | if(x < 0 || x >= BJ_WIDTH || y < 0 || y >= BJ_HEIGHT-1 || | 892 | if(x < 0 || x >= BJ_WIDTH || y < 0 || y >= BJ_HEIGHT-1 || |
@@ -1082,17 +1108,15 @@ static bool jewels_movesavail(struct game_context* bj) { | |||
1082 | } | 1108 | } |
1083 | } | 1109 | } |
1084 | } | 1110 | } |
1085 | |||
1086 | if(moves) break; | 1111 | if(moves) break; |
1087 | } | 1112 | } |
1088 | |||
1089 | return moves; | 1113 | return moves; |
1090 | } | 1114 | } |
1091 | 1115 | ||
1092 | /***************************************************************************** | 1116 | /***************************************************************************** |
1093 | * jewels_puzzle_is_finished(bj) checks if the puzzle is finished. | 1117 | * jewels_puzzle_is_finished() checks if the puzzle is finished. |
1094 | ******************************************************************************/ | 1118 | ******************************************************************************/ |
1095 | static int jewels_puzzle_is_finished(struct game_context* bj) { | 1119 | static bool jewels_puzzle_is_finished(struct game_context* bj) { |
1096 | unsigned int i, j; | 1120 | unsigned int i, j; |
1097 | for(i=0; i<BJ_HEIGHT; i++) { | 1121 | for(i=0; i<BJ_HEIGHT; i++) { |
1098 | for(j=0; j<BJ_WIDTH; j++) { | 1122 | for(j=0; j<BJ_WIDTH; j++) { |
@@ -1103,32 +1127,32 @@ static int jewels_puzzle_is_finished(struct game_context* bj) { | |||
1103 | if(i==0 || bj->playboard[i-1][j].type<=MAX_NUM_JEWELS || | 1127 | if(i==0 || bj->playboard[i-1][j].type<=MAX_NUM_JEWELS || |
1104 | !((bj->playboard[i-1][j].type-MAX_NUM_JEWELS) | 1128 | !((bj->playboard[i-1][j].type-MAX_NUM_JEWELS) |
1105 | &PUZZLE_TILE_DOWN)) | 1129 | &PUZZLE_TILE_DOWN)) |
1106 | return 0; | 1130 | return false; |
1107 | } | 1131 | } |
1108 | if(mytype&PUZZLE_TILE_DOWN) { | 1132 | if(mytype&PUZZLE_TILE_DOWN) { |
1109 | if(i==BJ_HEIGHT-1 || | 1133 | if(i==BJ_HEIGHT-1 || |
1110 | bj->playboard[i+1][j].type<=MAX_NUM_JEWELS || | 1134 | bj->playboard[i+1][j].type<=MAX_NUM_JEWELS || |
1111 | !((bj->playboard[i+1][j].type-MAX_NUM_JEWELS) | 1135 | !((bj->playboard[i+1][j].type-MAX_NUM_JEWELS) |
1112 | &PUZZLE_TILE_UP)) | 1136 | &PUZZLE_TILE_UP)) |
1113 | return 0; | 1137 | return false; |
1114 | } | 1138 | } |
1115 | if(mytype&PUZZLE_TILE_LEFT) { | 1139 | if(mytype&PUZZLE_TILE_LEFT) { |
1116 | if(j==0 || bj->playboard[i][j-1].type<=MAX_NUM_JEWELS || | 1140 | if(j==0 || bj->playboard[i][j-1].type<=MAX_NUM_JEWELS || |
1117 | !((bj->playboard[i][j-1].type-MAX_NUM_JEWELS) | 1141 | !((bj->playboard[i][j-1].type-MAX_NUM_JEWELS) |
1118 | &PUZZLE_TILE_RIGHT)) | 1142 | &PUZZLE_TILE_RIGHT)) |
1119 | return 0; | 1143 | return false; |
1120 | } | 1144 | } |
1121 | if(mytype&PUZZLE_TILE_RIGHT) { | 1145 | if(mytype&PUZZLE_TILE_RIGHT) { |
1122 | if(j==BJ_WIDTH-1 || | 1146 | if(j==BJ_WIDTH-1 || |
1123 | bj->playboard[i][j+1].type<=MAX_NUM_JEWELS || | 1147 | bj->playboard[i][j+1].type<=MAX_NUM_JEWELS || |
1124 | !((bj->playboard[i][j+1].type-MAX_NUM_JEWELS) | 1148 | !((bj->playboard[i][j+1].type-MAX_NUM_JEWELS) |
1125 | &PUZZLE_TILE_LEFT)) | 1149 | &PUZZLE_TILE_LEFT)) |
1126 | return 0; | 1150 | return false; |
1127 | } | 1151 | } |
1128 | } | 1152 | } |
1129 | } | 1153 | } |
1130 | } | 1154 | } |
1131 | return 1; | 1155 | return true; |
1132 | } | 1156 | } |
1133 | 1157 | ||
1134 | /***************************************************************************** | 1158 | /***************************************************************************** |
@@ -1165,7 +1189,7 @@ static unsigned int jewels_initlevel(struct game_context* bj) { | |||
1165 | } | 1189 | } |
1166 | break; | 1190 | break; |
1167 | } | 1191 | } |
1168 | 1192 | ||
1169 | jewels_drawboard(bj); | 1193 | jewels_drawboard(bj); |
1170 | 1194 | ||
1171 | /* run the play board */ | 1195 | /* run the play board */ |
@@ -1175,7 +1199,28 @@ static unsigned int jewels_initlevel(struct game_context* bj) { | |||
1175 | } | 1199 | } |
1176 | 1200 | ||
1177 | /***************************************************************************** | 1201 | /***************************************************************************** |
1178 | * jewels_nextlevel() advances the game to the next level and returns | 1202 | * jewels_init() initializes jewels data structures. |
1203 | ******************************************************************************/ | ||
1204 | static void jewels_init(struct game_context* bj) { | ||
1205 | /* seed the rand generator */ | ||
1206 | rb->srand(*rb->current_tick); | ||
1207 | |||
1208 | bj->type = bj->tmp_type; | ||
1209 | bj->level = 1; | ||
1210 | bj->score = 0; | ||
1211 | bj->segments = 0; | ||
1212 | |||
1213 | jewels_setcolors(); | ||
1214 | |||
1215 | /* clear playing board */ | ||
1216 | rb->memset(bj->playboard, 0, sizeof(bj->playboard)); | ||
1217 | do { | ||
1218 | bj->score += jewels_initlevel(bj); | ||
1219 | } while(!jewels_movesavail(bj)); | ||
1220 | } | ||
1221 | |||
1222 | /***************************************************************************** | ||
1223 | * jewels_nextlevel() advances the game to the next bj->level and returns | ||
1179 | * points earned. | 1224 | * points earned. |
1180 | ******************************************************************************/ | 1225 | ******************************************************************************/ |
1181 | static void jewels_nextlevel(struct game_context* bj) { | 1226 | static void jewels_nextlevel(struct game_context* bj) { |
@@ -1206,12 +1251,7 @@ static void jewels_nextlevel(struct game_context* bj) { | |||
1206 | 1251 | ||
1207 | case GAME_TYPE_PUZZLE: | 1252 | case GAME_TYPE_PUZZLE: |
1208 | bj->level++; | 1253 | bj->level++; |
1209 | if(bj->level>NUM_PUZZLE_LEVELS) { | 1254 | rb->splashf(HZ*2, "Level %d", bj->level); |
1210 | rb->splash(HZ*2, "You win!"); | ||
1211 | bj->level = 1; | ||
1212 | } else { | ||
1213 | rb->splashf(HZ*2, "Level %d", bj->level); | ||
1214 | } | ||
1215 | break; | 1255 | break; |
1216 | } | 1256 | } |
1217 | 1257 | ||
@@ -1219,445 +1259,189 @@ static void jewels_nextlevel(struct game_context* bj) { | |||
1219 | bj->score += points; | 1259 | bj->score += points; |
1220 | } | 1260 | } |
1221 | 1261 | ||
1222 | /***************************************************************************** | 1262 | static void jewels_show_highscores(int position) |
1223 | * jewels_recordscore() inserts a high score into the high scores list and | 1263 | { |
1224 | * returns the high score position. | 1264 | int i, w, h; |
1225 | ******************************************************************************/ | 1265 | char str[30]; |
1226 | static int jewels_recordscore(struct game_context* bj) { | ||
1227 | int i; | ||
1228 | int position = 0; | ||
1229 | unsigned int current, temp; | ||
1230 | |||
1231 | /* calculate total score */ | ||
1232 | current = (bj->level-1)*LEVEL_PTS+bj->score; | ||
1233 | if(current <= 0) return 0; | ||
1234 | |||
1235 | /* insert the current score into the high scores */ | ||
1236 | for(i=0; i<NUM_SCORES; i++) { | ||
1237 | if(current >= bj->highscores[i]) { | ||
1238 | if(!position) { | ||
1239 | position = i+1; | ||
1240 | bj->dirty = true; | ||
1241 | } | ||
1242 | temp = bj->highscores[i]; | ||
1243 | bj->highscores[i] = current; | ||
1244 | current = temp; | ||
1245 | } | ||
1246 | } | ||
1247 | |||
1248 | return position; | ||
1249 | } | ||
1250 | |||
1251 | /***************************************************************************** | ||
1252 | * jewels_loadscores() loads the high scores saved file. | ||
1253 | ******************************************************************************/ | ||
1254 | static void jewels_loadscores(struct game_context* bj) { | ||
1255 | int fd; | ||
1256 | |||
1257 | bj->dirty = false; | ||
1258 | |||
1259 | /* clear high scores */ | ||
1260 | rb->memset(bj->highscores, 0, sizeof(bj->highscores)); | ||
1261 | 1266 | ||
1262 | /* open scores file */ | 1267 | #ifdef HAVE_LCD_COLOR |
1263 | fd = rb->open(SCORE_FILE, O_RDONLY); | 1268 | rb->lcd_set_background(LCD_BLACK); |
1264 | if(fd < 0) return; | 1269 | rb->lcd_set_foreground(LCD_WHITE); |
1270 | #endif | ||
1271 | rb->button_clear_queue(); | ||
1272 | rb->lcd_clear_display(); | ||
1265 | 1273 | ||
1266 | /* read in high scores */ | 1274 | rb->lcd_setfont(FONT_UI); |
1267 | if(rb->read(fd, bj->highscores, sizeof(bj->highscores)) <= 0) { | 1275 | rb->lcd_getstringsize("High Scores", &w, &h); |
1268 | /* scores are bad, reset */ | 1276 | /* check wether it fits on screen */ |
1269 | rb->memset(bj->highscores, 0, sizeof(bj->highscores)); | 1277 | if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) { |
1278 | rb->lcd_setfont(FONT_SYSFIXED); | ||
1279 | rb->lcd_getstringsize("High Scores", &w, &h); | ||
1270 | } | 1280 | } |
1281 | rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); | ||
1282 | rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); | ||
1283 | rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); | ||
1271 | 1284 | ||
1272 | rb->close(fd); | 1285 | for (i = 0; i<NUM_SCORES; i++) |
1273 | } | 1286 | { |
1274 | 1287 | #ifdef HAVE_LCD_COLOR | |
1275 | /***************************************************************************** | 1288 | if (i == position) { |
1276 | * jewels_savescores() saves the high scores saved file. | 1289 | rb->lcd_set_foreground(LCD_RGBPACK(245,0,0)); |
1277 | ******************************************************************************/ | 1290 | } |
1278 | static void jewels_savescores(struct game_context* bj) { | 1291 | #endif |
1279 | int fd; | 1292 | rb->snprintf (str, sizeof (str), "%d)", i+1); |
1280 | 1293 | rb->lcd_putsxy (MARGIN,3*h + h*i, str); | |
1281 | /* write out the high scores to the save file */ | 1294 | rb->snprintf (str, sizeof (str), "%d", highest[i].score); |
1282 | fd = rb->open(SCORE_FILE, O_WRONLY|O_CREAT); | 1295 | rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); |
1283 | rb->write(fd, bj->highscores, sizeof(bj->highscores)); | 1296 | rb->snprintf (str, sizeof (str), "%d", highest[i].level); |
1284 | rb->close(fd); | 1297 | rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); |
1285 | bj->dirty = false; | 1298 | if(i == position) { |
1286 | } | 1299 | #ifdef HAVE_LCD_COLOR |
1287 | 1300 | rb->lcd_set_foreground(LCD_WHITE); | |
1288 | /***************************************************************************** | 1301 | #else |
1289 | * jewels_loadgame() loads the saved game and returns load success. | 1302 | rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); |
1290 | ******************************************************************************/ | 1303 | #endif |
1291 | static bool jewels_loadgame(struct game_context* bj) { | 1304 | } |
1292 | int fd; | ||
1293 | bool loaded = false; | ||
1294 | |||
1295 | /* open game file */ | ||
1296 | fd = rb->open(SAVE_FILE, O_RDONLY); | ||
1297 | if(fd < 0) return loaded; | ||
1298 | |||
1299 | /* read in saved game */ | ||
1300 | while(true) { | ||
1301 | if(rb->read(fd, &bj->score, sizeof(bj->score)) <= 0) break; | ||
1302 | if(rb->read(fd, &bj->level, sizeof(bj->level)) <= 0) break; | ||
1303 | if(rb->read(fd, &bj->type, sizeof(bj->type)) <= 0) break; | ||
1304 | if(rb->read(fd, bj->playboard, sizeof(bj->playboard)) <= 0) break; | ||
1305 | bj->resume = true; | ||
1306 | loaded = true; | ||
1307 | break; | ||
1308 | } | 1305 | } |
1309 | 1306 | rb->lcd_update(); | |
1310 | rb->close(fd); | 1307 | rb->button_get(true); |
1311 | 1308 | rb->lcd_setfont(FONT_SYSFIXED); | |
1312 | /* delete saved file */ | ||
1313 | rb->remove(SAVE_FILE); | ||
1314 | return loaded; | ||
1315 | } | 1309 | } |
1316 | 1310 | ||
1317 | /***************************************************************************** | 1311 | static int jewels_help(void) |
1318 | * jewels_savegame() saves the current game state. | 1312 | { |
1319 | ******************************************************************************/ | 1313 | rb->lcd_setfont(FONT_UI); |
1320 | static void jewels_savegame(struct game_context* bj) { | 1314 | #define WORDS (sizeof help_text / sizeof (char*)) |
1321 | int fd; | 1315 | static char *help_text[] = { |
1316 | "Jewels", "", "Aim", "", "Swap", "pairs", "of", "jewels", "to", | ||
1317 | "form", "connected", "segments", "of", "three", "or", "more", "of", | ||
1318 | "the", "same", "type.", "", "The", "goal", "of", "the", "game", | ||
1319 | "is", "to", "score", "as", "many", "points", "as", "possible", | ||
1320 | "before", "running", "out", "of", "available", "moves." | ||
1321 | }; | ||
1322 | static struct style_text formation[]={ | ||
1323 | { 0, TEXT_CENTER|TEXT_UNDERLINE }, | ||
1324 | { 2, C_RED } | ||
1325 | }; | ||
1322 | 1326 | ||
1323 | /* write out the game state to the save file */ | 1327 | #ifdef HAVE_LCD_COLOR |
1324 | fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT); | 1328 | rb->lcd_set_background(LCD_BLACK); |
1325 | rb->write(fd, &bj->score, sizeof(bj->score)); | 1329 | rb->lcd_set_foreground(LCD_WHITE); |
1326 | rb->write(fd, &bj->level, sizeof(bj->level)); | 1330 | #endif |
1327 | rb->write(fd, &bj->type, sizeof(bj->type)); | 1331 | if (display_text(WORDS, help_text, formation, NULL)==PLUGIN_USB_CONNECTED) |
1328 | rb->write(fd, bj->playboard, sizeof(bj->playboard)); | 1332 | return PLUGIN_USB_CONNECTED; |
1329 | rb->close(fd); | 1333 | int button; |
1334 | do { | ||
1335 | button = rb->button_get(true); | ||
1336 | if (button == SYS_USB_CONNECTED) { | ||
1337 | return PLUGIN_USB_CONNECTED; | ||
1338 | } | ||
1339 | } while( ( button == BUTTON_NONE ) | ||
1340 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); | ||
1341 | rb->lcd_setfont(FONT_SYSFIXED); | ||
1330 | 1342 | ||
1331 | bj->resume = true; | 1343 | return 0; |
1332 | } | 1344 | } |
1333 | 1345 | ||
1334 | /***************************************************************************** | 1346 | static void jewels_choose_mode(struct game_context* bj) |
1335 | * jewels_callback() is the default event handler callback which is called | 1347 | { |
1336 | * on usb connect and shutdown. | 1348 | rb->button_clear_queue(); |
1337 | ******************************************************************************/ | 1349 | int choice = bj->tmp_type; |
1338 | static void jewels_callback(void* param) { | 1350 | MENUITEM_STRINGLIST (main_menu, "Jewels Mode", NULL, |
1339 | struct game_context* bj = (struct game_context*) param; | 1351 | "Normal", |
1340 | if(bj->dirty) { | 1352 | "Puzzle"); |
1341 | rb->splash(HZ, "Saving high scores..."); | 1353 | choice = rb->do_menu(&main_menu, &choice, NULL, false); |
1342 | jewels_savescores(bj); | 1354 | switch (choice) { |
1355 | case 0: | ||
1356 | bj->tmp_type=GAME_TYPE_NORMAL; | ||
1357 | break; | ||
1358 | case 1: | ||
1359 | bj->tmp_type=GAME_TYPE_PUZZLE; | ||
1360 | break; | ||
1361 | default: | ||
1362 | break; | ||
1343 | } | 1363 | } |
1344 | } | 1364 | } |
1345 | 1365 | ||
1346 | /***************************************************************************** | 1366 | static bool _ingame; |
1347 | * jewels_displayscores() displays the high scores | 1367 | static int jewels_menu_cb(int action, const struct menu_item_ex *this_item) |
1348 | ******************************************************************************/ | ||
1349 | static char * scores_get_name(int selected_item, void * data, | ||
1350 | char * buffer, size_t buffer_len) | ||
1351 | { | ||
1352 | struct game_context* bj = (struct game_context*)data; | ||
1353 | rb->snprintf(buffer, buffer_len, "#%02d: %d", | ||
1354 | selected_item+1, bj->highscores[selected_item]); | ||
1355 | return buffer; | ||
1356 | } | ||
1357 | static void jewels_displayscores(struct game_context* bj) | ||
1358 | { | 1368 | { |
1359 | struct simplelist_info info; | 1369 | if(action == ACTION_REQUEST_MENUITEM |
1360 | rb->simplelist_info_init(&info, "High Scores", NUM_SCORES, (void*)bj); | 1370 | && !_ingame && ((intptr_t)this_item)==0) |
1361 | info.hide_selection = true; | 1371 | return ACTION_EXIT_MENUITEM; |
1362 | info.get_name = scores_get_name; | 1372 | return action; |
1363 | rb->simplelist_show_list(&info); | ||
1364 | } | 1373 | } |
1365 | |||
1366 | |||
1367 | /***************************************************************************** | 1374 | /***************************************************************************** |
1368 | * jewels_main() is the main game subroutine, it returns the final game status. | 1375 | * jewels_game_menu() shows the game menu. |
1369 | ******************************************************************************/ | 1376 | ******************************************************************************/ |
1370 | static int jewels_main(struct game_context* bj) { | 1377 | static int jewels_game_menu(struct game_context* bj, bool ingame) |
1371 | int w, h; | 1378 | { |
1372 | int button; | 1379 | rb->button_clear_queue(); |
1373 | struct viewport vp[NB_SCREENS]; | 1380 | int choice = 0; |
1374 | char str[18]; | 1381 | |
1375 | bool inmenu = true; | 1382 | _ingame = ingame; |
1376 | bool selected = false; | 1383 | |
1377 | 1384 | MENUITEM_STRINGLIST (main_menu, "Jewels Menu", jewels_menu_cb, | |
1378 | /* the cursor coordinates */ | 1385 | "Resume Game", |
1379 | int x=0, y=0; | 1386 | "Start New Game", |
1380 | 1387 | "Mode", | |
1381 | /* don't resume by default */ | 1388 | "Help", |
1382 | bj->resume = false; | 1389 | "High Score", |
1383 | 1390 | "Playback Control", | |
1384 | /******************** | 1391 | "Quit"); |
1385 | * menu * | 1392 | |
1386 | ********************/ | 1393 | while (1) { |
1387 | MENUITEM_STRINGLIST(main_menu,"Jewels",NULL, | 1394 | switch (rb->do_menu(&main_menu, &choice, NULL, false)) { |
1388 | "New Game", "Puzzle", "Resume Saved Game", | ||
1389 | "High Scores", "Help", "Quit"); | ||
1390 | FOR_NB_SCREENS(h) | ||
1391 | { | ||
1392 | rb->viewport_set_defaults(&vp[h], h); | ||
1393 | #if (LCD_DEPTH >= 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH >= 16) | ||
1394 | if (rb->screens[h]->depth >= 16) | ||
1395 | { | ||
1396 | vp->bg_pattern = LCD_RGBPACK(49, 26, 26); | ||
1397 | vp->fg_pattern = LCD_RGBPACK(210, 181, 181); | ||
1398 | } | ||
1399 | #endif | ||
1400 | } | ||
1401 | |||
1402 | while(inmenu) { | ||
1403 | |||
1404 | switch (rb->do_menu(&main_menu, NULL, vp, true)) { | ||
1405 | case 0: | 1395 | case 0: |
1406 | inmenu = false; | 1396 | jewels_setcolors(); |
1407 | bj->type = GAME_TYPE_NORMAL; | 1397 | return 0; |
1408 | break; | ||
1409 | |||
1410 | case 1: | 1398 | case 1: |
1411 | inmenu = false; | 1399 | jewels_init(bj); |
1412 | bj->type = GAME_TYPE_PUZZLE; | 1400 | return 0; |
1413 | break; | ||
1414 | |||
1415 | case 2: | 1401 | case 2: |
1416 | if(!jewels_loadgame(bj)) { | 1402 | jewels_choose_mode(bj); |
1417 | rb->splash(HZ*2, "Nothing to resume"); | ||
1418 | } else { | ||
1419 | inmenu = false; | ||
1420 | } | ||
1421 | break; | 1403 | break; |
1422 | |||
1423 | case 3: | 1404 | case 3: |
1424 | jewels_displayscores(bj); | 1405 | jewels_help(); |
1425 | break; | 1406 | break; |
1426 | |||
1427 | case 4: | 1407 | case 4: |
1428 | /* welcome screen to display key bindings */ | 1408 | jewels_show_highscores(NUM_SCORES); |
1429 | rb->lcd_clear_display(); | ||
1430 | rb->snprintf(str, 5, "%s", "Help"); | ||
1431 | rb->lcd_getstringsize(str, &w, &h); | ||
1432 | rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, str); | ||
1433 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
1434 | rb->lcd_puts(0, 2, "Controls:"); | ||
1435 | rb->lcd_puts(0, 3, "Directions = move"); | ||
1436 | rb->lcd_puts(0, 4, "PLAY = select"); | ||
1437 | rb->lcd_puts(0, 5, "Long PLAY = menu"); | ||
1438 | rb->lcd_puts(0, 6, "OFF = cancel"); | ||
1439 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
1440 | rb->lcd_puts(0, 2, "Controls:"); | ||
1441 | rb->lcd_puts(0, 3, "Directions = move"); | ||
1442 | rb->lcd_puts(0, 4, "MENU = select"); | ||
1443 | rb->lcd_puts(0, 5, "Long MENU = menu"); | ||
1444 | rb->lcd_puts(0, 6, "OFF = cancel"); | ||
1445 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD | ||
1446 | rb->lcd_puts(0, 2, "Controls:"); | ||
1447 | rb->lcd_puts(0, 3, "Directions = move"); | ||
1448 | rb->lcd_puts(0, 4, "SELECT = select"); | ||
1449 | rb->lcd_puts(0, 5, "Long SELECT = menu"); | ||
1450 | rb->lcd_puts(0, 6, "PLAY = cancel"); | ||
1451 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
1452 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1453 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1454 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1455 | rb->lcd_puts(0, 5, "same type."); | ||
1456 | rb->lcd_puts(0, 7, "Controls:"); | ||
1457 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1458 | rb->lcd_puts(0, 9, "SELECT to select"); | ||
1459 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1460 | rb->lcd_puts(0, 11, "OFF to cancel"); | ||
1461 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ | ||
1462 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) | ||
1463 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1464 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1465 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1466 | rb->lcd_puts(0, 5, "same type."); | ||
1467 | rb->lcd_puts(0, 7, "Controls:"); | ||
1468 | rb->lcd_puts(0, 8, "Directions or scroll to move"); | ||
1469 | rb->lcd_puts(0, 9, "SELECT to select"); | ||
1470 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1471 | #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD | ||
1472 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1473 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1474 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1475 | rb->lcd_puts(0, 5, "same type."); | ||
1476 | rb->lcd_puts(0, 7, "Controls:"); | ||
1477 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1478 | rb->lcd_puts(0, 9, "SELECT to select"); | ||
1479 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1480 | rb->lcd_puts(0, 11, "PLAY to cancel"); | ||
1481 | #elif CONFIG_KEYPAD == GIGABEAT_PAD \ | ||
1482 | || CONFIG_KEYPAD == MROBE100_PAD | ||
1483 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1484 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1485 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1486 | rb->lcd_puts(0, 5, "same type."); | ||
1487 | rb->lcd_puts(0, 7, "Controls:"); | ||
1488 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1489 | rb->lcd_puts(0, 9, "SELECT to select"); | ||
1490 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1491 | rb->lcd_puts(0, 11, "POWER to cancel"); | ||
1492 | #elif CONFIG_KEYPAD == SANSA_E200_PAD \ | ||
1493 | || CONFIG_KEYPAD == SANSA_C200_PAD \ | ||
1494 | || CONFIG_KEYPAD == SANSA_CLIP_PAD \ | ||
1495 | || CONFIG_KEYPAD == SANSA_FUZE_PAD \ | ||
1496 | || CONFIG_KEYPAD == SANSA_M200_PAD | ||
1497 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1498 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1499 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1500 | rb->lcd_puts(0, 5, "same type."); | ||
1501 | rb->lcd_puts(0, 7, "Controls:"); | ||
1502 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1503 | rb->lcd_puts(0, 9, "SELECT to select"); | ||
1504 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1505 | rb->lcd_puts(0, 11, "POWER to cancel"); | ||
1506 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD | ||
1507 | rb->lcd_puts(0, 2, "Swap pairs of jewels"); | ||
1508 | rb->lcd_puts(0, 3, "to form connected"); | ||
1509 | rb->lcd_puts(0, 4, "segments of three or "); | ||
1510 | rb->lcd_puts(0, 5, "more of the"); | ||
1511 | rb->lcd_puts(0, 6, "same type."); | ||
1512 | rb->lcd_puts(0, 8, "Controls:"); | ||
1513 | rb->lcd_puts(0, 9, "Directions or scroll to move"); | ||
1514 | rb->lcd_puts(0, 10, "PLAY to select"); | ||
1515 | rb->lcd_puts(0, 11, "Long PLAY for menu"); | ||
1516 | rb->lcd_puts(0, 12, "POWER to cancel"); | ||
1517 | #elif CONFIG_KEYPAD == IAUDIO_M3_PAD | ||
1518 | rb->lcd_puts(0, 2, "Swap pairs of jewels"); | ||
1519 | rb->lcd_puts(0, 3, "to form connected"); | ||
1520 | rb->lcd_puts(0, 4, "segments of three or "); | ||
1521 | rb->lcd_puts(0, 5, "more of the"); | ||
1522 | rb->lcd_puts(0, 6, "same type."); | ||
1523 | rb->lcd_puts(0, 8, "Controls:"); | ||
1524 | rb->lcd_puts(0, 9, "Directions or scroll to move"); | ||
1525 | rb->lcd_puts(0, 10, "PLAY to select"); | ||
1526 | rb->lcd_puts(0, 11, "Long PLAY for menu"); | ||
1527 | rb->lcd_puts(0, 12, "REC to cancel"); | ||
1528 | #elif CONFIG_KEYPAD == COWOND2_PAD | ||
1529 | rb->lcd_puts(0, 11, "POWER to cancel"); | ||
1530 | #elif CONFIG_KEYPAD == GIGABEAT_S_PAD | ||
1531 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1532 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1533 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1534 | rb->lcd_puts(0, 5, "same type."); | ||
1535 | rb->lcd_puts(0, 7, "Controls:"); | ||
1536 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1537 | rb->lcd_puts(0, 9, "SELECT to select"); | ||
1538 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1539 | rb->lcd_puts(0, 11, "BACK to cancel"); | ||
1540 | #elif CONFIG_KEYPAD == CREATIVEZVM_PAD | ||
1541 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1542 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1543 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1544 | rb->lcd_puts(0, 5, "same type."); | ||
1545 | rb->lcd_puts(0, 7, "Controls:"); | ||
1546 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1547 | rb->lcd_puts(0, 9, "MIDDLE to select"); | ||
1548 | rb->lcd_puts(0, 10, "Long MIDDLE to show menu"); | ||
1549 | rb->lcd_puts(0, 11, "BACK to cancel"); | ||
1550 | #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD | ||
1551 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1552 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1553 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1554 | rb->lcd_puts(0, 5, "same type."); | ||
1555 | rb->lcd_puts(0, 7, "Controls:"); | ||
1556 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1557 | rb->lcd_puts(0, 9, "SELECT/PLAY to select"); | ||
1558 | rb->lcd_puts(0, 10, "Long SELECT to show menu"); | ||
1559 | rb->lcd_puts(0, 11, "POWER to cancel"); | ||
1560 | #elif CONFIG_KEYPAD == ONDAVX747_PAD || CONFIG_KEYPAD == MROBE500_PAD | ||
1561 | rb->lcd_puts(0, 11, "POWER to cancel"); | ||
1562 | #else | ||
1563 | #warning: missing help text. | ||
1564 | #endif | ||
1565 | |||
1566 | #ifdef HAVE_TOUCHSCREEN | ||
1567 | rb->lcd_puts(0, 2, "Swap pairs of jewels to"); | ||
1568 | rb->lcd_puts(0, 3, "form connected segments"); | ||
1569 | rb->lcd_puts(0, 4, "of three or more of the"); | ||
1570 | rb->lcd_puts(0, 5, "same type."); | ||
1571 | rb->lcd_puts(0, 7, "Controls:"); | ||
1572 | rb->lcd_puts(0, 8, "Directions to move"); | ||
1573 | rb->lcd_puts(0, 9, "CENTER to select"); | ||
1574 | rb->lcd_puts(0, 10, "Long CENTER to show menu"); | ||
1575 | #endif | ||
1576 | rb->lcd_update(); | ||
1577 | while(true) { | ||
1578 | button = rb->button_get(true); | ||
1579 | if(button != BUTTON_NONE && !(button&BUTTON_REL)) break; | ||
1580 | } | ||
1581 | rb->lcd_clear_display(); | ||
1582 | break; | 1409 | break; |
1583 | |||
1584 | case 5: | 1410 | case 5: |
1585 | return BJ_QUIT; | 1411 | playback_control(NULL); |
1586 | 1412 | break; | |
1413 | case 6: | ||
1414 | if (bj->playgame) { | ||
1415 | rb->splash(HZ*1, "Saving game ..."); | ||
1416 | jewels_savegame(bj); | ||
1417 | } | ||
1418 | return 1; | ||
1587 | case MENU_ATTACHED_USB: | 1419 | case MENU_ATTACHED_USB: |
1588 | jewels_callback(bj); | 1420 | return 1; |
1589 | return BJ_USB; | ||
1590 | |||
1591 | default: | 1421 | default: |
1592 | return BJ_QUIT; | ||
1593 | } | ||
1594 | } | ||
1595 | |||
1596 | /******************** | ||
1597 | * init * | ||
1598 | ********************/ | ||
1599 | jewels_init(bj); | ||
1600 | |||
1601 | /******************** | ||
1602 | * setup the board * | ||
1603 | ********************/ | ||
1604 | bj->score += jewels_initlevel(bj); | ||
1605 | if (!jewels_movesavail(bj)) { | ||
1606 | switch(bj->type) { | ||
1607 | case GAME_TYPE_NORMAL: | ||
1608 | return BJ_LOSE; | ||
1609 | |||
1610 | case GAME_TYPE_PUZZLE: | ||
1611 | do { | ||
1612 | rb->splash(2*HZ, "No more moves!"); | ||
1613 | bj->score += jewels_initlevel(bj); | ||
1614 | } while(!jewels_movesavail(bj)); | ||
1615 | break; | 1422 | break; |
1616 | } | 1423 | } |
1617 | } | 1424 | } |
1425 | } | ||
1618 | 1426 | ||
1619 | /********************** | 1427 | static int jewels_main(struct game_context* bj) { |
1620 | * play * | 1428 | int button; |
1621 | **********************/ | 1429 | int position; |
1622 | MENUITEM_STRINGLIST(ingame_menu,"Menu",NULL, | 1430 | bool selected = false; |
1623 | "Audio Playback", "Resume Game", | 1431 | bool no_movesavail; |
1624 | "Save Game", "End Game", "Exit Jewels"); | 1432 | int x=0, y=0; |
1433 | |||
1434 | bj->playgame = false; | ||
1435 | if(!jewels_loadgame(bj)) { | ||
1436 | if (jewels_game_menu(bj, false)!=0) | ||
1437 | return 0; | ||
1438 | } else { | ||
1439 | if (jewels_game_menu(bj, true)!=0) | ||
1440 | return 0; | ||
1441 | } | ||
1625 | 1442 | ||
1626 | selected = false; | ||
1627 | while(true) { | 1443 | while(true) { |
1628 | bool no_movesavail = false; | 1444 | no_movesavail = false; |
1629 | |||
1630 | while(inmenu) { | ||
1631 | switch (rb->do_menu(&ingame_menu, NULL, vp, true)) { | ||
1632 | case 0: | ||
1633 | playback_control(NULL); | ||
1634 | inmenu = false; | ||
1635 | break; | ||
1636 | |||
1637 | case 1: | ||
1638 | inmenu = false; | ||
1639 | break; | ||
1640 | |||
1641 | case 2: | ||
1642 | rb->splash(HZ, "Saving game..."); | ||
1643 | jewels_savegame(bj); | ||
1644 | return BJ_END; | ||
1645 | |||
1646 | case 3: | ||
1647 | return BJ_END; | ||
1648 | |||
1649 | case 4: | ||
1650 | return BJ_QUIT_FROM_GAME; | ||
1651 | |||
1652 | case MENU_ATTACHED_USB: | ||
1653 | jewels_callback(bj); | ||
1654 | return BJ_USB; | ||
1655 | |||
1656 | default: | ||
1657 | inmenu = false; | ||
1658 | break; | ||
1659 | } | ||
1660 | } | ||
1661 | 1445 | ||
1662 | /* refresh the board */ | 1446 | /* refresh the board */ |
1663 | jewels_drawboard(bj); | 1447 | jewels_drawboard(bj); |
@@ -1749,127 +1533,86 @@ static int jewels_main(struct game_context* bj) { | |||
1749 | selected = !selected; | 1533 | selected = !selected; |
1750 | break; | 1534 | break; |
1751 | 1535 | ||
1752 | #ifdef JEWELS_MENU | ||
1753 | case JEWELS_MENU: | ||
1754 | #endif | ||
1755 | case (JEWELS_SELECT|BUTTON_REPEAT): /* show menu */ | ||
1756 | inmenu = true; | ||
1757 | selected = false; | ||
1758 | break; | ||
1759 | |||
1760 | #ifdef JEWELS_CANCEL | ||
1761 | #ifdef JEWELS_RC_CANCEL | 1536 | #ifdef JEWELS_RC_CANCEL |
1762 | case JEWELS_RC_CANCEL: | 1537 | case JEWELS_RC_CANCEL: |
1763 | #endif | 1538 | #endif |
1764 | case JEWELS_CANCEL: /* end game */ | 1539 | case JEWELS_CANCEL: /* end game */ |
1765 | return BJ_END; | 1540 | if (jewels_game_menu(bj, true)!=0) |
1541 | return 0; | ||
1766 | break; | 1542 | break; |
1767 | #endif | ||
1768 | 1543 | ||
1769 | default: | 1544 | default: |
1770 | if(rb->default_event_handler_ex(button, jewels_callback, | 1545 | if (rb->default_event_handler (button) == SYS_USB_CONNECTED) |
1771 | (void*) bj) == SYS_USB_CONNECTED) | 1546 | return PLUGIN_USB_CONNECTED; |
1772 | return BJ_USB; | ||
1773 | break; | 1547 | break; |
1774 | } | 1548 | } |
1775 | 1549 | ||
1776 | if (no_movesavail) { | ||
1777 | switch(bj->type) { | ||
1778 | case GAME_TYPE_NORMAL: | ||
1779 | return BJ_LOSE; | ||
1780 | |||
1781 | case GAME_TYPE_PUZZLE: | ||
1782 | do { | ||
1783 | rb->splash(2*HZ, "No more moves!"); | ||
1784 | bj->score += jewels_initlevel(bj); | ||
1785 | } while(!jewels_movesavail(bj)); | ||
1786 | break; | ||
1787 | } | ||
1788 | } | ||
1789 | |||
1790 | switch(bj->type) { | 1550 | switch(bj->type) { |
1791 | case GAME_TYPE_NORMAL: | 1551 | case GAME_TYPE_NORMAL: |
1792 | if(bj->score >= LEVEL_PTS) | 1552 | if(bj->score >= LEVEL_PTS) |
1793 | jewels_nextlevel(bj); | 1553 | jewels_nextlevel(bj); |
1794 | break; | 1554 | break; |
1795 | |||
1796 | case GAME_TYPE_PUZZLE: | 1555 | case GAME_TYPE_PUZZLE: |
1797 | if(jewels_puzzle_is_finished(bj)) | 1556 | if (jewels_puzzle_is_finished(bj)) { |
1798 | jewels_nextlevel(bj); | 1557 | if (bj->level < NUM_PUZZLE_LEVELS) { |
1558 | jewels_nextlevel(bj); | ||
1559 | } else { | ||
1560 | rb->splash(2*HZ, "Congratulations!"); | ||
1561 | rb->splash(2*HZ, "You have finished the game!"); | ||
1562 | if (jewels_game_menu(bj, false)!=0) { | ||
1563 | return 0; | ||
1564 | } | ||
1565 | } | ||
1799 | break; | 1566 | break; |
1567 | } | ||
1568 | } | ||
1569 | |||
1570 | if (no_movesavail) { | ||
1571 | switch(bj->type) { | ||
1572 | case GAME_TYPE_NORMAL: | ||
1573 | rb->splash(HZ*2, "Game Over!"); | ||
1574 | rb->lcd_clear_display(); | ||
1575 | if (highscore_would_update(bj->score, highest, | ||
1576 | NUM_SCORES)) { | ||
1577 | position=highscore_update(bj->score, | ||
1578 | bj->level, "", | ||
1579 | highest,NUM_SCORES); | ||
1580 | if (position == 0) { | ||
1581 | rb->splash(HZ*2, "New High Score"); | ||
1582 | } | ||
1583 | jewels_show_highscores(position); | ||
1584 | } | ||
1585 | break; | ||
1586 | case GAME_TYPE_PUZZLE: | ||
1587 | rb->splash(2*HZ, "Game Over"); | ||
1588 | break; | ||
1589 | } | ||
1590 | if (jewels_game_menu(bj, false)!=0) { | ||
1591 | return 0; | ||
1592 | } | ||
1800 | } | 1593 | } |
1801 | } | 1594 | } |
1802 | } | 1595 | } |
1803 | 1596 | ||
1804 | /***************************************************************************** | 1597 | /* this is the plugin entry point */ |
1805 | * plugin entry point. | 1598 | enum plugin_status plugin_start(const void* parameter) |
1806 | ******************************************************************************/ | 1599 | { |
1807 | enum plugin_status plugin_start(const void* parameter) { | ||
1808 | struct game_context bj; | ||
1809 | bool exit = false; | ||
1810 | int position; | ||
1811 | char str[19]; | ||
1812 | |||
1813 | /* plugin init */ | ||
1814 | (void)parameter; | 1600 | (void)parameter; |
1815 | /* end of plugin init */ | ||
1816 | 1601 | ||
1817 | /* load high scores */ | 1602 | /* load high scores */ |
1818 | jewels_loadscores(&bj); | 1603 | highscore_load(HIGH_SCORE,highest,NUM_SCORES); |
1819 | 1604 | ||
1820 | rb->lcd_setfont(FONT_SYSFIXED); | 1605 | rb->lcd_setfont(FONT_SYSFIXED); |
1821 | #if LCD_DEPTH > 1 | 1606 | #if LCD_DEPTH > 1 |
1822 | rb->lcd_set_backdrop(NULL); | 1607 | rb->lcd_set_backdrop(NULL); |
1823 | #endif | 1608 | #endif |
1824 | jewels_setcolors(); | ||
1825 | |||
1826 | while(!exit) { | ||
1827 | switch(jewels_main(&bj)){ | ||
1828 | case BJ_LOSE: | ||
1829 | rb->splash(HZ*2, "No more moves!"); | ||
1830 | /* fall through to BJ_END */ | ||
1831 | |||
1832 | case BJ_END: | ||
1833 | if(!bj.resume) { | ||
1834 | if((position = jewels_recordscore(&bj))) { | ||
1835 | rb->snprintf(str, 19, "New high score #%d!", position); | ||
1836 | rb->splash(HZ*2, str); | ||
1837 | } | ||
1838 | } | ||
1839 | break; | ||
1840 | |||
1841 | case BJ_USB: | ||
1842 | rb->lcd_setfont(FONT_UI); | ||
1843 | return PLUGIN_USB_CONNECTED; | ||
1844 | |||
1845 | case BJ_QUIT: | ||
1846 | if(bj.dirty) { | ||
1847 | rb->splash(HZ, "Saving high scores..."); | ||
1848 | jewels_savescores(&bj); | ||
1849 | } | ||
1850 | exit = true; | ||
1851 | break; | ||
1852 | |||
1853 | case BJ_QUIT_FROM_GAME: | ||
1854 | if(!bj.resume) { | ||
1855 | if((position = jewels_recordscore(&bj))) { | ||
1856 | rb->snprintf(str, 19, "New high score #%d!", position); | ||
1857 | rb->splash(HZ*2, str); | ||
1858 | } | ||
1859 | } | ||
1860 | if(bj.dirty) { | ||
1861 | rb->splash(HZ, "Saving high scores..."); | ||
1862 | jewels_savescores(&bj); | ||
1863 | } | ||
1864 | exit = true; | ||
1865 | break; | ||
1866 | |||
1867 | default: | ||
1868 | break; | ||
1869 | } | ||
1870 | } | ||
1871 | 1609 | ||
1610 | struct game_context bj; | ||
1611 | bj.tmp_type = GAME_TYPE_NORMAL; | ||
1612 | jewels_main(&bj); | ||
1613 | highscore_save(HIGH_SCORE,highest,NUM_SCORES); | ||
1872 | rb->lcd_setfont(FONT_UI); | 1614 | rb->lcd_setfont(FONT_UI); |
1615 | |||
1873 | return PLUGIN_OK; | 1616 | return PLUGIN_OK; |
1874 | } | 1617 | } |
1875 | 1618 | ||