forked from len0rd/rockbox
snake:go back to menu when game is over. save highscores using pluginlib highscore.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22206 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
363cbc22b5
commit
dc993a62c9
1 changed files with 35 additions and 11 deletions
|
@ -34,6 +34,7 @@ dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
|
||||||
|
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
#include "lib/highscore.h"
|
||||||
#include "lib/playback_control.h"
|
#include "lib/playback_control.h"
|
||||||
|
|
||||||
PLUGIN_HEADER
|
PLUGIN_HEADER
|
||||||
|
@ -214,12 +215,16 @@ PLUGIN_HEADER
|
||||||
|
|
||||||
#define BOARD_WIDTH (LCD_WIDTH/4)
|
#define BOARD_WIDTH (LCD_WIDTH/4)
|
||||||
#define BOARD_HEIGHT (LCD_HEIGHT/4)
|
#define BOARD_HEIGHT (LCD_HEIGHT/4)
|
||||||
|
#define NUM_SCORES 5
|
||||||
|
#define SCORE_FILE PLUGIN_GAMES_DIR "/snake.score"
|
||||||
|
|
||||||
static int board[BOARD_WIDTH][BOARD_HEIGHT],snakelength;
|
static int board[BOARD_WIDTH][BOARD_HEIGHT],snakelength;
|
||||||
static unsigned int score,hiscore=0,level=1;
|
static int score,level=1;
|
||||||
static int dir,dead=0;
|
static int dir,dead=0;
|
||||||
static bool apple;
|
static bool apple;
|
||||||
|
|
||||||
|
static struct highscore highscores[NUM_SCORES];
|
||||||
|
|
||||||
void die (void)
|
void die (void)
|
||||||
{
|
{
|
||||||
char pscore[17];
|
char pscore[17];
|
||||||
|
@ -227,12 +232,12 @@ void die (void)
|
||||||
rb->snprintf(pscore,sizeof(pscore),"Your score: %d",score);
|
rb->snprintf(pscore,sizeof(pscore),"Your score: %d",score);
|
||||||
rb->lcd_puts(0,0,"Oops...");
|
rb->lcd_puts(0,0,"Oops...");
|
||||||
rb->lcd_puts(0,1, pscore);
|
rb->lcd_puts(0,1, pscore);
|
||||||
if (score>hiscore) {
|
if (highscore_update(score, level, "", highscores, NUM_SCORES) == 0) {
|
||||||
hiscore=score;
|
|
||||||
rb->lcd_puts(0,2,"New High Score!");
|
rb->lcd_puts(0,2,"New High Score!");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb->snprintf(pscore,sizeof(pscore),"High Score: %d",hiscore);
|
rb->snprintf(pscore, sizeof(pscore),
|
||||||
|
"High Score: %d", highscores[0].score);
|
||||||
rb->lcd_puts(0,2,pscore);
|
rb->lcd_puts(0,2,pscore);
|
||||||
}
|
}
|
||||||
rb->lcd_update();
|
rb->lcd_update();
|
||||||
|
@ -450,8 +455,11 @@ void game_init(void) {
|
||||||
|
|
||||||
MENUITEM_STRINGLIST(menu, "Snake Menu", NULL,
|
MENUITEM_STRINGLIST(menu, "Snake Menu", NULL,
|
||||||
"Start New Game", "Starting Level",
|
"Start New Game", "Starting Level",
|
||||||
|
"High Scores",
|
||||||
"Playback Control", "Quit");
|
"Playback Control", "Quit");
|
||||||
|
|
||||||
|
rb->button_clear_queue();
|
||||||
|
|
||||||
while (!menu_quit) {
|
while (!menu_quit) {
|
||||||
switch(rb->do_menu(&menu, &selection, NULL, false))
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
||||||
{
|
{
|
||||||
|
@ -465,9 +473,18 @@ void game_init(void) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
highscore_show(NUM_SCORES, highscores, NUM_SCORES, true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
playback_control(NULL);
|
playback_control(NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MENU_ATTACHED_USB:
|
||||||
|
dead = 2;
|
||||||
|
menu_quit = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dead=1; /* quit program */
|
dead=1; /* quit program */
|
||||||
menu_quit = true;
|
menu_quit = true;
|
||||||
|
@ -481,9 +498,16 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
{
|
{
|
||||||
(void)(parameter);
|
(void)(parameter);
|
||||||
|
|
||||||
game_init();
|
highscore_load(SCORE_FILE, highscores, NUM_SCORES);
|
||||||
rb->lcd_clear_display();
|
while(dead == 0)
|
||||||
game();
|
{
|
||||||
|
game_init();
|
||||||
|
if(dead)
|
||||||
|
break;
|
||||||
|
rb->lcd_clear_display();
|
||||||
|
game();
|
||||||
|
}
|
||||||
|
highscore_save(SCORE_FILE, highscores, NUM_SCORES);
|
||||||
return (dead==1)?PLUGIN_OK:PLUGIN_USB_CONNECTED;
|
return (dead==1)?PLUGIN_OK:PLUGIN_USB_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue