summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-09-06 14:14:22 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-09-06 14:14:22 +0000
commitd41e698ea00a1922434a75d6ba8f3eaa3485abd3 (patch)
treedc4daf5cbcadef800e1a19a810c1ce3f776e813e
parentc17037a80266e9e97643e8c34459f3ac81510be0 (diff)
downloadrockbox-d41e698ea00a1922434a75d6ba8f3eaa3485abd3.tar.gz
rockbox-d41e698ea00a1922434a75d6ba8f3eaa3485abd3.zip
brickmania, blackjack, jewels, bubbles: Remove save file only if player resumed the game loaded from the file.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22639 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/blackjack.c36
-rw-r--r--apps/plugins/brickmania.c7
-rw-r--r--apps/plugins/bubbles.c9
-rw-r--r--apps/plugins/jewels.c7
4 files changed, 34 insertions, 25 deletions
diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c
index e00b209c9d..9ad19fcf9e 100644
--- a/apps/plugins/blackjack.c
+++ b/apps/plugins/blackjack.c
@@ -36,8 +36,8 @@ PLUGIN_HEADER
36/* final game return status */ 36/* final game return status */
37enum { 37enum {
38 BJ_LOSE, 38 BJ_LOSE,
39 BJ_QUIT_WITHOUT_SAVING,
39 BJ_QUIT, 40 BJ_QUIT,
40 BJ_SAVE_AND_QUIT,
41 BJ_USB, 41 BJ_USB,
42 BJ_END, 42 BJ_END,
43}; 43};
@@ -514,7 +514,8 @@ typedef struct game_context {
514 bool asked_insurance; 514 bool asked_insurance;
515} game_context; 515} game_context;
516 516
517static bool resume; 517static bool resume = false;
518static bool resume_file = false;
518static struct highscore highest[NUM_SCORES]; 519static struct highscore highest[NUM_SCORES];
519 520
520/***************************************************************************** 521/*****************************************************************************
@@ -855,23 +856,19 @@ static bool blackjack_loadgame(struct game_context* bj) {
855 signed int fd; 856 signed int fd;
856 bool loaded = false; 857 bool loaded = false;
857 858
858 resume = false;
859 /* open game file */ 859 /* open game file */
860 fd = rb->open(SAVE_FILE, O_RDONLY); 860 fd = rb->open(SAVE_FILE, O_RDONLY);
861 if(fd < 0) return loaded; 861 if(fd < 0) return false;
862 862
863 /* read in saved game */ 863 /* read in saved game */
864 if(rb->read(fd, bj, sizeof(struct game_context)) 864 if(rb->read(fd, bj, sizeof(struct game_context))
865 == (long)sizeof(struct game_context)) 865 == (long)sizeof(struct game_context))
866 { 866 {
867 resume = true;
868 loaded = true; 867 loaded = true;
869 } 868 }
870 869
871 rb->close(fd); 870 rb->close(fd);
872 871
873 /* delete saved file */
874 rb->remove(SAVE_FILE);
875 return loaded; 872 return loaded;
876} 873}
877 874
@@ -1204,7 +1201,8 @@ static unsigned int blackjack_menu(struct game_context* bj) {
1204 MENUITEM_STRINGLIST(menu, "BlackJack Menu", NULL, 1201 MENUITEM_STRINGLIST(menu, "BlackJack Menu", NULL,
1205 "Resume Game", "Start New Game", 1202 "Resume Game", "Start New Game",
1206 "High Scores", "Help", 1203 "High Scores", "Help",
1207 "Playback Control", "Quit", "Save and Quit"); 1204 "Playback Control",
1205 "Quit without Saving", "Quit");
1208 1206
1209 while(!breakout) { 1207 while(!breakout) {
1210 switch(rb->do_menu(&menu, &selection, NULL, false)) { 1208 switch(rb->do_menu(&menu, &selection, NULL, false)) {
@@ -1213,6 +1211,8 @@ static unsigned int blackjack_menu(struct game_context* bj) {
1213 rb->splash(HZ*2, "Nothing to resume"); 1211 rb->splash(HZ*2, "Nothing to resume");
1214 } else { 1212 } else {
1215 breakout = true; 1213 breakout = true;
1214 if(resume_file)
1215 rb->remove(SAVE_FILE);
1216 } 1216 }
1217 break; 1217 break;
1218 case 1: 1218 case 1:
@@ -1231,9 +1231,9 @@ static unsigned int blackjack_menu(struct game_context* bj) {
1231 return BJ_USB; 1231 return BJ_USB;
1232 break; 1232 break;
1233 case 5: 1233 case 5:
1234 return BJ_QUIT; 1234 return BJ_QUIT_WITHOUT_SAVING;
1235 case 6: 1235 case 6:
1236 return BJ_SAVE_AND_QUIT; 1236 return BJ_QUIT;
1237 1237
1238 case MENU_ATTACHED_USB: 1238 case MENU_ATTACHED_USB:
1239 return BJ_USB; 1239 return BJ_USB;
@@ -1278,6 +1278,7 @@ static int blackjack(struct game_context* bj) {
1278 * play * 1278 * play *
1279 ********************/ 1279 ********************/
1280 1280
1281 resume_file = false;
1281 /* check for resumed game */ 1282 /* check for resumed game */
1282 if(resume) { 1283 if(resume) {
1283 resume = false; 1284 resume = false;
@@ -1508,7 +1509,8 @@ enum plugin_status plugin_start(const void* parameter)
1508 1509
1509 /* load high scores */ 1510 /* load high scores */
1510 highscore_load(HIGH_SCORE,highest,NUM_SCORES); 1511 highscore_load(HIGH_SCORE,highest,NUM_SCORES);
1511 blackjack_loadgame(&bj); 1512 resume = blackjack_loadgame(&bj);
1513 resume_file = resume;
1512 1514
1513 rb->lcd_setfont(FONT_SYSFIXED); 1515 rb->lcd_setfont(FONT_SYSFIXED);
1514 1516
@@ -1537,15 +1539,13 @@ enum plugin_status plugin_start(const void* parameter)
1537 highscore_save(HIGH_SCORE,highest,NUM_SCORES); 1539 highscore_save(HIGH_SCORE,highest,NUM_SCORES);
1538 return PLUGIN_USB_CONNECTED; 1540 return PLUGIN_USB_CONNECTED;
1539 1541
1540 case BJ_SAVE_AND_QUIT:
1541 if (resume) {
1542 rb->splash(HZ, "Saving game...");
1543 blackjack_savegame(&bj);
1544 }
1545 /* fall through */
1546
1547 case BJ_QUIT: 1542 case BJ_QUIT:
1543 rb->splash(HZ/5, "Saving Game and Scores...");
1544 blackjack_savegame(&bj);
1548 highscore_save(HIGH_SCORE,highest,NUM_SCORES); 1545 highscore_save(HIGH_SCORE,highest,NUM_SCORES);
1546 /* fall through */
1547
1548 case BJ_QUIT_WITHOUT_SAVING:
1549 exit = true; 1549 exit = true;
1550 break; 1550 break;
1551 1551
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c
index 82a883c7a4..0eebd3f65c 100644
--- a/apps/plugins/brickmania.c
+++ b/apps/plugins/brickmania.c
@@ -619,6 +619,7 @@ int difficulty = NORMAL;
619int pad_width; 619int pad_width;
620int num_count; 620int num_count;
621bool resume = false; 621bool resume = false;
622bool resume_file = false;
622 623
623typedef struct cube { 624typedef struct cube {
624 int powertop; 625 int powertop;
@@ -751,8 +752,6 @@ static void brickmania_loadgame(void)
751 752
752 rb->close(fd); 753 rb->close(fd);
753 754
754 /* delete saved file */
755 rb->remove(SAVE_FILE);
756 return; 755 return;
757} 756}
758 757
@@ -922,6 +921,8 @@ static int brickmania_menu(void)
922 case 0: 921 case 0:
923 if(game_state!=ST_READY) 922 if(game_state!=ST_READY)
924 game_state = ST_PAUSE; 923 game_state = ST_PAUSE;
924 if(resume_file)
925 rb->remove(SAVE_FILE);
925 return 0; 926 return 0;
926 case 1: 927 case 1:
927 score=0; 928 score=0;
@@ -982,6 +983,7 @@ static int brickmania_game_loop(void)
982 return 1; 983 return 1;
983 } 984 }
984 resume = false; 985 resume = false;
986 resume_file = false;
985 987
986 while(true) { 988 while(true) {
987 /* Convert CYCLETIME (in ms) to HZ */ 989 /* Convert CYCLETIME (in ms) to HZ */
@@ -1778,6 +1780,7 @@ enum plugin_status plugin_start(const void* parameter)
1778 /* now go ahead and have fun! */ 1780 /* now go ahead and have fun! */
1779 rb->srand( *rb->current_tick ); 1781 rb->srand( *rb->current_tick );
1780 brickmania_loadgame(); 1782 brickmania_loadgame();
1783 resume_file = resume;
1781 while(brickmania_game_loop() == 0) { 1784 while(brickmania_game_loop() == 0) {
1782 if(!resume) { 1785 if(!resume) {
1783 int position = highscore_update(score, level+1, "", highest, NUM_SCORES); 1786 int position = highscore_update(score, level+1, "", highest, NUM_SCORES);
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c
index da927de01c..3b28ced87d 100644
--- a/apps/plugins/bubbles.c
+++ b/apps/plugins/bubbles.c
@@ -1274,6 +1274,7 @@ struct highscore highscores[NUM_SCORES];
1274 1274
1275/* used to denote available resume info */ 1275/* used to denote available resume info */
1276static bool resume = false; 1276static bool resume = false;
1277static bool resume_file = false;
1277static unsigned int highlevel = 0; /* the highest level beaten */ 1278static unsigned int highlevel = 0; /* the highest level beaten */
1278static unsigned int last_highlevel = 0; 1279static unsigned int last_highlevel = 0;
1279 1280
@@ -2393,14 +2394,15 @@ static int bubbles_menu(struct game_context* bb) {
2393 rb->splash(HZ/2, "Nothing to resume"); 2394 rb->splash(HZ/2, "Nothing to resume");
2394 else 2395 else
2395 startgame = true; 2396 startgame = true;
2396 2397 if(resume_file)
2397 if(rb->file_exists(SAVE_FILE)) 2398 rb->remove(SAVE_FILE);
2398 rb->remove(SAVE_FILE); 2399 resume_file = false;
2399 break; 2400 break;
2400 case 1: /* new game */ 2401 case 1: /* new game */
2401 bb->level = startlevel; 2402 bb->level = startlevel;
2402 startgame = true; 2403 startgame = true;
2403 resume = false; 2404 resume = false;
2405 resume_file = false;
2404 break; 2406 break;
2405 case 2: /* choose level */ 2407 case 2: /* choose level */
2406 startlevel++; 2408 startlevel++;
@@ -2497,6 +2499,7 @@ enum plugin_status plugin_start(const void* parameter) {
2497 2499
2498 /* load files */ 2500 /* load files */
2499 resume = bubbles_loadgame(&bb); 2501 resume = bubbles_loadgame(&bb);
2502 resume_file = resume;
2500 bubbles_loaddata(); 2503 bubbles_loaddata();
2501 highscore_load(SCORE_FILE, highscores, NUM_SCORES); 2504 highscore_load(SCORE_FILE, highscores, NUM_SCORES);
2502 rb->lcd_clear_display(); 2505 rb->lcd_clear_display();
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c
index f049fdca5c..a55b1b2dae 100644
--- a/apps/plugins/jewels.c
+++ b/apps/plugins/jewels.c
@@ -420,6 +420,7 @@ struct puzzle_level puzzle_levels[NUM_PUZZLE_LEVELS] = {
420#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score" 420#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score"
421struct highscore highest[NUM_SCORES]; 421struct highscore highest[NUM_SCORES];
422 422
423static bool resume_file = false;
423 424
424/***************************************************************************** 425/*****************************************************************************
425* jewels_setcolors() set the foreground and background colors. 426* jewels_setcolors() set the foreground and background colors.
@@ -458,8 +459,6 @@ static bool jewels_loadgame(struct game_context* bj)
458 459
459 rb->close(fd); 460 rb->close(fd);
460 461
461 /* delete saved file */
462 rb->remove(SAVE_FILE);
463 return loaded; 462 return loaded;
464} 463}
465 464
@@ -1361,6 +1360,8 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
1361 switch (rb->do_menu(&main_menu, &choice, NULL, false)) { 1360 switch (rb->do_menu(&main_menu, &choice, NULL, false)) {
1362 case 0: 1361 case 0:
1363 jewels_setcolors(); 1362 jewels_setcolors();
1363 if(resume_file)
1364 rb->remove(SAVE_FILE);
1364 return 0; 1365 return 0;
1365 case 1: 1366 case 1:
1366 jewels_init(bj); 1367 jewels_init(bj);
@@ -1402,9 +1403,11 @@ static int jewels_main(struct game_context* bj) {
1402 int x=0, y=0; 1403 int x=0, y=0;
1403 1404
1404 bool loaded = jewels_loadgame(bj); 1405 bool loaded = jewels_loadgame(bj);
1406 resume_file = loaded;
1405 if (jewels_game_menu(bj, loaded)!=0) 1407 if (jewels_game_menu(bj, loaded)!=0)
1406 return 0; 1408 return 0;
1407 1409
1410 resume_file = false;
1408 while(true) { 1411 while(true) {
1409 no_movesavail = false; 1412 no_movesavail = false;
1410 1413