forked from len0rd/rockbox
Plugin rework 2: (all) Compile-time keyboard configuration, for Ondio adaption. (all) Now using the default event handler, standard placement is now in switch() default case. (minesweeper,pong,snake,snake2) added USB handling. (mandelbrot,mosaique) Fixed return value. (minesweeper) fast moving with button repeat. (oscillograph) Fixed cleanup in USB case.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5304 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
d24766675d
commit
e35a658ded
11 changed files with 543 additions and 163 deletions
|
@ -33,11 +33,32 @@ use F3 to see how many mines are left (supposing all your flags are correct)
|
|||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
|
||||
//what the minesweeper() function can return
|
||||
//what the minesweeper() function can return
|
||||
#define MINESWEEPER_USB 3
|
||||
#define MINESWEEPER_QUIT 2
|
||||
#define MINESWEEPER_LOSE 1
|
||||
#define MINESWEEPER_WIN 0
|
||||
|
||||
/* variable button definitions */
|
||||
#if CONFIG_KEYPAD == RECORDER_PAD
|
||||
#define MINESWP_QUIT BUTTON_OFF
|
||||
#define MINESWP_START BUTTON_ON
|
||||
#define MINESWP_TOGGLE BUTTON_PLAY
|
||||
#define MINESWP_TOGGLE2 BUTTON_F1
|
||||
#define MINESWP_DISCOVER BUTTON_ON
|
||||
#define MINESWP_DISCOVER2 BUTTON_F2
|
||||
#define MINESWP_INFO BUTTON_F3
|
||||
|
||||
#elif CONFIG_KEYPAD == ONDIO_PAD
|
||||
#define MINESWP_QUIT BUTTON_OFF
|
||||
#define MINESWP_START BUTTON_MENU
|
||||
#define MINESWP_TOGGLE_PRE BUTTON_MENU
|
||||
#define MINESWP_TOGGLE (BUTTON_MENU | BUTTON_REL)
|
||||
#define MINESWP_DISCOVER (BUTTON_MENU | BUTTON_REPEAT)
|
||||
#define MINESWP_INFO (BUTTON_MENU | BUTTON_OFF)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* here is a global api struct pointer. while not strictly necessary,
|
||||
it's nice not to have to pass the api pointer in all function calls
|
||||
|
@ -254,6 +275,8 @@ void minesweeper_putmines(int p, int x, int y){
|
|||
int minesweeper(void)
|
||||
{
|
||||
int i,j;
|
||||
int button;
|
||||
int lastbutton = BUTTON_NONE;
|
||||
|
||||
/* the cursor coordinates */
|
||||
int x=0,y=0;
|
||||
|
@ -277,12 +300,17 @@ int minesweeper(void)
|
|||
rb->snprintf(str, 20, "%d%% mines", p);
|
||||
rb->lcd_putsxy(1,19,str);
|
||||
rb->lcd_putsxy(1,28,"down / up");
|
||||
#if CONFIG_KEYPAD == RECORDER_PAD
|
||||
rb->lcd_putsxy(1,44,"ON to start");
|
||||
#elif CONFIG_KEYPAD == ONDIO_PAD
|
||||
rb->lcd_putsxy(1,44,"MENU to start");
|
||||
#endif
|
||||
|
||||
rb->lcd_update();
|
||||
|
||||
|
||||
switch(rb->button_get(true)){
|
||||
button = rb->button_get(true);
|
||||
switch(button){
|
||||
case BUTTON_DOWN:
|
||||
case BUTTON_LEFT:
|
||||
p = (p + 98)%100;
|
||||
|
@ -293,12 +321,17 @@ int minesweeper(void)
|
|||
p = (p + 2)%100;
|
||||
break;
|
||||
|
||||
case BUTTON_ON:/* start playing */
|
||||
case MINESWP_START:/* start playing */
|
||||
i = 1;
|
||||
break;
|
||||
|
||||
case BUTTON_OFF:/* quit program */
|
||||
case MINESWP_QUIT:/* quit program */
|
||||
return MINESWEEPER_QUIT;
|
||||
|
||||
default:
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
||||
return MINESWEEPER_USB;
|
||||
break;
|
||||
}
|
||||
if(i==1)
|
||||
break;
|
||||
|
@ -345,34 +378,41 @@ int minesweeper(void)
|
|||
/* update the screen */
|
||||
rb->lcd_update();
|
||||
|
||||
switch(rb->button_get(true)){
|
||||
button = rb->button_get(true);
|
||||
switch(button){
|
||||
/* quit minesweeper (you really shouldn't use this button ...) */
|
||||
case BUTTON_OFF:
|
||||
case MINESWP_QUIT:
|
||||
return MINESWEEPER_QUIT;
|
||||
|
||||
/* move cursor left */
|
||||
case BUTTON_LEFT:
|
||||
case (BUTTON_LEFT | BUTTON_REPEAT):
|
||||
x = (x + width - 1)%width;
|
||||
break;
|
||||
|
||||
/* move cursor right */
|
||||
case BUTTON_RIGHT:
|
||||
case (BUTTON_RIGHT | BUTTON_REPEAT):
|
||||
x = (x + 1)%width;
|
||||
break;
|
||||
|
||||
/* move cursor down */
|
||||
case BUTTON_DOWN:
|
||||
case (BUTTON_DOWN | BUTTON_REPEAT):
|
||||
y = (y + 1)%height;
|
||||
break;
|
||||
|
||||
/* move cursor up */
|
||||
case BUTTON_UP:
|
||||
case (BUTTON_UP | BUTTON_REPEAT):
|
||||
y = (y + height - 1)%height;
|
||||
break;
|
||||
|
||||
/* discover a tile (and it's neighbors if .neighbors == 0) */
|
||||
case BUTTON_ON:
|
||||
case BUTTON_F2:
|
||||
case MINESWP_DISCOVER:
|
||||
#ifdef MINESWP_DISCOVER2
|
||||
case MINESWP_DISCOVER2:
|
||||
#endif
|
||||
if(minefield[y][x].flag) break;
|
||||
/* we put the mines on the first "click" so that you don't */
|
||||
/* lose on the first "click" */
|
||||
|
@ -393,14 +433,20 @@ int minesweeper(void)
|
|||
break;
|
||||
|
||||
/* toggle flag under cursor */
|
||||
case BUTTON_PLAY:
|
||||
case BUTTON_F1:
|
||||
case MINESWP_TOGGLE:
|
||||
#ifdef MINESWP_TOGGLE_PRE
|
||||
if (lastbutton != MINESWP_TOGGLE_PRE)
|
||||
break;
|
||||
#endif
|
||||
#ifdef MINESWP_TOGGLE2
|
||||
case MINESWP_TOGGLE2:
|
||||
#endif
|
||||
minefield[y][x].flag = (minefield[y][x].flag + 1)%2;
|
||||
break;
|
||||
|
||||
/* show how many mines you think you have found and how many */
|
||||
/* there really are on the game */
|
||||
case BUTTON_F3:
|
||||
case MINESWP_INFO:
|
||||
tiles_left = 0;
|
||||
for(i=0;i<height;i++){
|
||||
for(j=0;j<width;j++){
|
||||
|
@ -409,7 +455,14 @@ int minesweeper(void)
|
|||
}
|
||||
rb->splash(HZ*2, true, "You found %d mines out of %d", tiles_left, mine_num);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
||||
return MINESWEEPER_USB;
|
||||
break;
|
||||
}
|
||||
if (button != BUTTON_NONE)
|
||||
lastbutton = button;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -431,6 +484,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|||
case MINESWEEPER_LOSE:
|
||||
rb->splash(HZ*2, true, "You Lost :(");
|
||||
break;
|
||||
|
||||
case MINESWEEPER_USB:
|
||||
return PLUGIN_USB_CONNECTED;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue