summaryrefslogtreecommitdiff
path: root/apps/plugins/blackjack.c
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 /apps/plugins/blackjack.c
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
Diffstat (limited to 'apps/plugins/blackjack.c')
-rw-r--r--apps/plugins/blackjack.c36
1 files changed, 18 insertions, 18 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