summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-07-14 12:07:53 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-07-14 12:07:53 +0000
commite37f9f16915a1a05059aee931723c127a53a68e0 (patch)
treefadd6a3a52e705ec68038aa3eac94b3252f009d2 /apps/plugins
parentfec4206f39fa40f05b919c13f1c5e2a487f8fd17 (diff)
downloadrockbox-e37f9f16915a1a05059aee931723c127a53a68e0.tar.gz
rockbox-e37f9f16915a1a05059aee931723c127a53a68e0.zip
add a way to quit without saving game.
some cosmetic fixes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21860 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/jewels.c72
1 files changed, 29 insertions, 43 deletions
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c
index 4db8d2baea..08051c8e9e 100644
--- a/apps/plugins/jewels.c
+++ b/apps/plugins/jewels.c
@@ -361,7 +361,6 @@ struct tile {
361 * type is the game type (normal or puzzle) 361 * type is the game type (normal or puzzle)
362 * playboard is the game playing board (first row is hidden) 362 * playboard is the game playing board (first row is hidden)
363 * 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
365 */ 364 */
366struct game_context { 365struct game_context {
367 unsigned int score; 366 unsigned int score;
@@ -371,7 +370,6 @@ struct game_context {
371 unsigned int tmp_type; 370 unsigned int tmp_type;
372 struct tile playboard[BJ_HEIGHT][BJ_WIDTH]; 371 struct tile playboard[BJ_HEIGHT][BJ_WIDTH];
373 unsigned int num_jewels; 372 unsigned int num_jewels;
374 bool playgame;
375}; 373};
376 374
377#define MAX_NUM_JEWELS 7 375#define MAX_NUM_JEWELS 7
@@ -431,6 +429,7 @@ struct puzzle_level puzzle_levels[NUM_PUZZLE_LEVELS] = {
431 429
432#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score" 430#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score"
433struct highscore highest[NUM_SCORES]; 431struct highscore highest[NUM_SCORES];
432bool highest_updated = false;
434 433
435 434
436/***************************************************************************** 435/*****************************************************************************
@@ -470,6 +469,8 @@ static bool jewels_loadgame(struct game_context* bj)
470 469
471 rb->close(fd); 470 rb->close(fd);
472 471
472 /* delete saved file */
473 rb->remove(SAVE_FILE);
473 return loaded; 474 return loaded;
474} 475}
475 476
@@ -885,8 +886,6 @@ static unsigned int jewels_swapjewels(struct game_context* bj,
885 bool undo = false; 886 bool undo = false;
886 unsigned int points = 0; 887 unsigned int points = 0;
887 long lasttick, currenttick; 888 long lasttick, currenttick;
888
889 bj->playgame = true;
890 889
891 /* check for invalid parameters */ 890 /* check for invalid parameters */
892 if(x < 0 || x >= BJ_WIDTH || y < 0 || y >= BJ_HEIGHT-1 || 891 if(x < 0 || x >= BJ_WIDTH || y < 0 || y >= BJ_HEIGHT-1 ||
@@ -1189,7 +1188,7 @@ static unsigned int jewels_initlevel(struct game_context* bj) {
1189 } 1188 }
1190 break; 1189 break;
1191 } 1190 }
1192 1191
1193 jewels_drawboard(bj); 1192 jewels_drawboard(bj);
1194 1193
1195 /* run the play board */ 1194 /* run the play board */
@@ -1204,12 +1203,12 @@ static unsigned int jewels_initlevel(struct game_context* bj) {
1204static void jewels_init(struct game_context* bj) { 1203static void jewels_init(struct game_context* bj) {
1205 /* seed the rand generator */ 1204 /* seed the rand generator */
1206 rb->srand(*rb->current_tick); 1205 rb->srand(*rb->current_tick);
1207 1206
1208 bj->type = bj->tmp_type; 1207 bj->type = bj->tmp_type;
1209 bj->level = 1; 1208 bj->level = 1;
1210 bj->score = 0; 1209 bj->score = 0;
1211 bj->segments = 0; 1210 bj->segments = 0;
1212 1211
1213 jewels_setcolors(); 1212 jewels_setcolors();
1214 1213
1215 /* clear playing board */ 1214 /* clear playing board */
@@ -1343,31 +1342,12 @@ static int jewels_help(void)
1343 return 0; 1342 return 0;
1344} 1343}
1345 1344
1346static void jewels_choose_mode(struct game_context* bj)
1347{
1348 rb->button_clear_queue();
1349 int choice = bj->tmp_type;
1350 MENUITEM_STRINGLIST (main_menu, "Jewels Mode", NULL,
1351 "Normal",
1352 "Puzzle");
1353 choice = rb->do_menu(&main_menu, &choice, NULL, false);
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;
1363 }
1364}
1365
1366static bool _ingame; 1345static bool _ingame;
1367static int jewels_menu_cb(int action, const struct menu_item_ex *this_item) 1346static int jewels_menu_cb(int action, const struct menu_item_ex *this_item)
1368{ 1347{
1348 int i = ((intptr_t)this_item);
1369 if(action == ACTION_REQUEST_MENUITEM 1349 if(action == ACTION_REQUEST_MENUITEM
1370 && !_ingame && ((intptr_t)this_item)==0) 1350 && !_ingame && (i==0 || i==6))
1371 return ACTION_EXIT_MENUITEM; 1351 return ACTION_EXIT_MENUITEM;
1372 return action; 1352 return action;
1373} 1353}
@@ -1381,6 +1361,11 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
1381 1361
1382 _ingame = ingame; 1362 _ingame = ingame;
1383 1363
1364 static struct opt_items mode[] = {
1365 { "Normal", -1 },
1366 { "Puzzle", -1 },
1367 };
1368
1384 MENUITEM_STRINGLIST (main_menu, "Jewels Menu", jewels_menu_cb, 1369 MENUITEM_STRINGLIST (main_menu, "Jewels Menu", jewels_menu_cb,
1385 "Resume Game", 1370 "Resume Game",
1386 "Start New Game", 1371 "Start New Game",
@@ -1388,8 +1373,9 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
1388 "Help", 1373 "Help",
1389 "High Score", 1374 "High Score",
1390 "Playback Control", 1375 "Playback Control",
1376 "Save and Quit",
1391 "Quit"); 1377 "Quit");
1392 1378
1393 while (1) { 1379 while (1) {
1394 switch (rb->do_menu(&main_menu, &choice, NULL, false)) { 1380 switch (rb->do_menu(&main_menu, &choice, NULL, false)) {
1395 case 0: 1381 case 0:
@@ -1399,7 +1385,7 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
1399 jewels_init(bj); 1385 jewels_init(bj);
1400 return 0; 1386 return 0;
1401 case 2: 1387 case 2:
1402 jewels_choose_mode(bj); 1388 rb->set_option("Mode", &bj->tmp_type, INT, mode, 2, NULL);
1403 break; 1389 break;
1404 case 3: 1390 case 3:
1405 jewels_help(); 1391 jewels_help();
@@ -1411,11 +1397,13 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
1411 playback_control(NULL); 1397 playback_control(NULL);
1412 break; 1398 break;
1413 case 6: 1399 case 6:
1414 if (bj->playgame) { 1400 if (ingame) {
1415 rb->splash(HZ*1, "Saving game ..."); 1401 rb->splash(HZ*1, "Saving game ...");
1416 jewels_savegame(bj); 1402 jewels_savegame(bj);
1417 } 1403 }
1418 return 1; 1404 return 1;
1405 case 7:
1406 return 1;
1419 case MENU_ATTACHED_USB: 1407 case MENU_ATTACHED_USB:
1420 return 1; 1408 return 1;
1421 default: 1409 default:
@@ -1430,15 +1418,10 @@ static int jewels_main(struct game_context* bj) {
1430 bool selected = false; 1418 bool selected = false;
1431 bool no_movesavail; 1419 bool no_movesavail;
1432 int x=0, y=0; 1420 int x=0, y=0;
1433 1421
1434 bj->playgame = false; 1422 bool loaded = jewels_loadgame(bj);
1435 if(!jewels_loadgame(bj)) { 1423 if (jewels_game_menu(bj, loaded)!=0)
1436 if (jewels_game_menu(bj, false)!=0) 1424 return 0;
1437 return 0;
1438 } else {
1439 if (jewels_game_menu(bj, true)!=0)
1440 return 0;
1441 }
1442 1425
1443 while(true) { 1426 while(true) {
1444 no_movesavail = false; 1427 no_movesavail = false;
@@ -1546,7 +1529,7 @@ static int jewels_main(struct game_context* bj) {
1546 return PLUGIN_USB_CONNECTED; 1529 return PLUGIN_USB_CONNECTED;
1547 break; 1530 break;
1548 } 1531 }
1549 1532
1550 switch(bj->type) { 1533 switch(bj->type) {
1551 case GAME_TYPE_NORMAL: 1534 case GAME_TYPE_NORMAL:
1552 if(bj->score >= LEVEL_PTS) 1535 if(bj->score >= LEVEL_PTS)
@@ -1576,7 +1559,8 @@ static int jewels_main(struct game_context* bj) {
1576 NUM_SCORES)) { 1559 NUM_SCORES)) {
1577 position=highscore_update(bj->score, 1560 position=highscore_update(bj->score,
1578 bj->level, "", 1561 bj->level, "",
1579 highest,NUM_SCORES); 1562 highest,NUM_SCORES);
1563 highest_updated = true;
1580 if (position == 0) { 1564 if (position == 0) {
1581 rb->splash(HZ*2, "New High Score"); 1565 rb->splash(HZ*2, "New High Score");
1582 } 1566 }
@@ -1601,6 +1585,7 @@ enum plugin_status plugin_start(const void* parameter)
1601 1585
1602 /* load high scores */ 1586 /* load high scores */
1603 highscore_load(HIGH_SCORE,highest,NUM_SCORES); 1587 highscore_load(HIGH_SCORE,highest,NUM_SCORES);
1588 highest_updated = false;
1604 1589
1605 rb->lcd_setfont(FONT_SYSFIXED); 1590 rb->lcd_setfont(FONT_SYSFIXED);
1606#if LCD_DEPTH > 1 1591#if LCD_DEPTH > 1
@@ -1610,7 +1595,8 @@ enum plugin_status plugin_start(const void* parameter)
1610 struct game_context bj; 1595 struct game_context bj;
1611 bj.tmp_type = GAME_TYPE_NORMAL; 1596 bj.tmp_type = GAME_TYPE_NORMAL;
1612 jewels_main(&bj); 1597 jewels_main(&bj);
1613 highscore_save(HIGH_SCORE,highest,NUM_SCORES); 1598 if(highest_updated)
1599 highscore_save(HIGH_SCORE,highest,NUM_SCORES);
1614 rb->lcd_setfont(FONT_UI); 1600 rb->lcd_setfont(FONT_UI);
1615 1601
1616 return PLUGIN_OK; 1602 return PLUGIN_OK;