From d41e698ea00a1922434a75d6ba8f3eaa3485abd3 Mon Sep 17 00:00:00 2001 From: Teruaki Kawashima Date: Sun, 6 Sep 2009 14:14:22 +0000 Subject: 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 --- apps/plugins/blackjack.c | 36 ++++++++++++++++++------------------ apps/plugins/brickmania.c | 7 +++++-- apps/plugins/bubbles.c | 9 ++++++--- apps/plugins/jewels.c | 7 +++++-- 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 /* final game return status */ enum { BJ_LOSE, + BJ_QUIT_WITHOUT_SAVING, BJ_QUIT, - BJ_SAVE_AND_QUIT, BJ_USB, BJ_END, }; @@ -514,7 +514,8 @@ typedef struct game_context { bool asked_insurance; } game_context; -static bool resume; +static bool resume = false; +static bool resume_file = false; static struct highscore highest[NUM_SCORES]; /***************************************************************************** @@ -855,23 +856,19 @@ static bool blackjack_loadgame(struct game_context* bj) { signed int fd; bool loaded = false; - resume = false; /* open game file */ fd = rb->open(SAVE_FILE, O_RDONLY); - if(fd < 0) return loaded; + if(fd < 0) return false; /* read in saved game */ if(rb->read(fd, bj, sizeof(struct game_context)) == (long)sizeof(struct game_context)) { - resume = true; loaded = true; } rb->close(fd); - /* delete saved file */ - rb->remove(SAVE_FILE); return loaded; } @@ -1204,7 +1201,8 @@ static unsigned int blackjack_menu(struct game_context* bj) { MENUITEM_STRINGLIST(menu, "BlackJack Menu", NULL, "Resume Game", "Start New Game", "High Scores", "Help", - "Playback Control", "Quit", "Save and Quit"); + "Playback Control", + "Quit without Saving", "Quit"); while(!breakout) { switch(rb->do_menu(&menu, &selection, NULL, false)) { @@ -1213,6 +1211,8 @@ static unsigned int blackjack_menu(struct game_context* bj) { rb->splash(HZ*2, "Nothing to resume"); } else { breakout = true; + if(resume_file) + rb->remove(SAVE_FILE); } break; case 1: @@ -1231,9 +1231,9 @@ static unsigned int blackjack_menu(struct game_context* bj) { return BJ_USB; break; case 5: - return BJ_QUIT; + return BJ_QUIT_WITHOUT_SAVING; case 6: - return BJ_SAVE_AND_QUIT; + return BJ_QUIT; case MENU_ATTACHED_USB: return BJ_USB; @@ -1278,6 +1278,7 @@ static int blackjack(struct game_context* bj) { * play * ********************/ + resume_file = false; /* check for resumed game */ if(resume) { resume = false; @@ -1508,7 +1509,8 @@ enum plugin_status plugin_start(const void* parameter) /* load high scores */ highscore_load(HIGH_SCORE,highest,NUM_SCORES); - blackjack_loadgame(&bj); + resume = blackjack_loadgame(&bj); + resume_file = resume; rb->lcd_setfont(FONT_SYSFIXED); @@ -1537,15 +1539,13 @@ enum plugin_status plugin_start(const void* parameter) highscore_save(HIGH_SCORE,highest,NUM_SCORES); return PLUGIN_USB_CONNECTED; - case BJ_SAVE_AND_QUIT: - if (resume) { - rb->splash(HZ, "Saving game..."); - blackjack_savegame(&bj); - } - /* fall through */ - case BJ_QUIT: + rb->splash(HZ/5, "Saving Game and Scores..."); + blackjack_savegame(&bj); highscore_save(HIGH_SCORE,highest,NUM_SCORES); + /* fall through */ + + case BJ_QUIT_WITHOUT_SAVING: exit = true; break; 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; int pad_width; int num_count; bool resume = false; +bool resume_file = false; typedef struct cube { int powertop; @@ -751,8 +752,6 @@ static void brickmania_loadgame(void) rb->close(fd); - /* delete saved file */ - rb->remove(SAVE_FILE); return; } @@ -922,6 +921,8 @@ static int brickmania_menu(void) case 0: if(game_state!=ST_READY) game_state = ST_PAUSE; + if(resume_file) + rb->remove(SAVE_FILE); return 0; case 1: score=0; @@ -982,6 +983,7 @@ static int brickmania_game_loop(void) return 1; } resume = false; + resume_file = false; while(true) { /* Convert CYCLETIME (in ms) to HZ */ @@ -1778,6 +1780,7 @@ enum plugin_status plugin_start(const void* parameter) /* now go ahead and have fun! */ rb->srand( *rb->current_tick ); brickmania_loadgame(); + resume_file = resume; while(brickmania_game_loop() == 0) { if(!resume) { 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]; /* used to denote available resume info */ static bool resume = false; +static bool resume_file = false; static unsigned int highlevel = 0; /* the highest level beaten */ static unsigned int last_highlevel = 0; @@ -2393,14 +2394,15 @@ static int bubbles_menu(struct game_context* bb) { rb->splash(HZ/2, "Nothing to resume"); else startgame = true; - - if(rb->file_exists(SAVE_FILE)) - rb->remove(SAVE_FILE); + if(resume_file) + rb->remove(SAVE_FILE); + resume_file = false; break; case 1: /* new game */ bb->level = startlevel; startgame = true; resume = false; + resume_file = false; break; case 2: /* choose level */ startlevel++; @@ -2497,6 +2499,7 @@ enum plugin_status plugin_start(const void* parameter) { /* load files */ resume = bubbles_loadgame(&bb); + resume_file = resume; bubbles_loaddata(); highscore_load(SCORE_FILE, highscores, NUM_SCORES); 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] = { #define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score" struct highscore highest[NUM_SCORES]; +static bool resume_file = false; /***************************************************************************** * jewels_setcolors() set the foreground and background colors. @@ -458,8 +459,6 @@ static bool jewels_loadgame(struct game_context* bj) rb->close(fd); - /* delete saved file */ - rb->remove(SAVE_FILE); return loaded; } @@ -1361,6 +1360,8 @@ static int jewels_game_menu(struct game_context* bj, bool ingame) switch (rb->do_menu(&main_menu, &choice, NULL, false)) { case 0: jewels_setcolors(); + if(resume_file) + rb->remove(SAVE_FILE); return 0; case 1: jewels_init(bj); @@ -1402,9 +1403,11 @@ static int jewels_main(struct game_context* bj) { int x=0, y=0; bool loaded = jewels_loadgame(bj); + resume_file = loaded; if (jewels_game_menu(bj, loaded)!=0) return 0; + resume_file = false; while(true) { no_movesavail = false; -- cgit