diff options
Diffstat (limited to 'apps/plugins/minesweeper.c')
-rw-r--r-- | apps/plugins/minesweeper.c | 78 |
1 files changed, 67 insertions, 11 deletions
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c index 127d96d3d5..e60cfb4688 100644 --- a/apps/plugins/minesweeper.c +++ b/apps/plugins/minesweeper.c | |||
@@ -33,11 +33,32 @@ use F3 to see how many mines are left (supposing all your flags are correct) | |||
33 | 33 | ||
34 | #ifdef HAVE_LCD_BITMAP | 34 | #ifdef HAVE_LCD_BITMAP |
35 | 35 | ||
36 | //what the minesweeper() function can return | 36 | //what the minesweeper() function can return |
37 | #define MINESWEEPER_USB 3 | ||
37 | #define MINESWEEPER_QUIT 2 | 38 | #define MINESWEEPER_QUIT 2 |
38 | #define MINESWEEPER_LOSE 1 | 39 | #define MINESWEEPER_LOSE 1 |
39 | #define MINESWEEPER_WIN 0 | 40 | #define MINESWEEPER_WIN 0 |
40 | 41 | ||
42 | /* variable button definitions */ | ||
43 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
44 | #define MINESWP_QUIT BUTTON_OFF | ||
45 | #define MINESWP_START BUTTON_ON | ||
46 | #define MINESWP_TOGGLE BUTTON_PLAY | ||
47 | #define MINESWP_TOGGLE2 BUTTON_F1 | ||
48 | #define MINESWP_DISCOVER BUTTON_ON | ||
49 | #define MINESWP_DISCOVER2 BUTTON_F2 | ||
50 | #define MINESWP_INFO BUTTON_F3 | ||
51 | |||
52 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
53 | #define MINESWP_QUIT BUTTON_OFF | ||
54 | #define MINESWP_START BUTTON_MENU | ||
55 | #define MINESWP_TOGGLE_PRE BUTTON_MENU | ||
56 | #define MINESWP_TOGGLE (BUTTON_MENU | BUTTON_REL) | ||
57 | #define MINESWP_DISCOVER (BUTTON_MENU | BUTTON_REPEAT) | ||
58 | #define MINESWP_INFO (BUTTON_MENU | BUTTON_OFF) | ||
59 | |||
60 | #endif | ||
61 | |||
41 | 62 | ||
42 | /* here is a global api struct pointer. while not strictly necessary, | 63 | /* here is a global api struct pointer. while not strictly necessary, |
43 | it's nice not to have to pass the api pointer in all function calls | 64 | 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){ | |||
254 | int minesweeper(void) | 275 | int minesweeper(void) |
255 | { | 276 | { |
256 | int i,j; | 277 | int i,j; |
278 | int button; | ||
279 | int lastbutton = BUTTON_NONE; | ||
257 | 280 | ||
258 | /* the cursor coordinates */ | 281 | /* the cursor coordinates */ |
259 | int x=0,y=0; | 282 | int x=0,y=0; |
@@ -277,12 +300,17 @@ int minesweeper(void) | |||
277 | rb->snprintf(str, 20, "%d%% mines", p); | 300 | rb->snprintf(str, 20, "%d%% mines", p); |
278 | rb->lcd_putsxy(1,19,str); | 301 | rb->lcd_putsxy(1,19,str); |
279 | rb->lcd_putsxy(1,28,"down / up"); | 302 | rb->lcd_putsxy(1,28,"down / up"); |
303 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
280 | rb->lcd_putsxy(1,44,"ON to start"); | 304 | rb->lcd_putsxy(1,44,"ON to start"); |
305 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
306 | rb->lcd_putsxy(1,44,"MENU to start"); | ||
307 | #endif | ||
281 | 308 | ||
282 | rb->lcd_update(); | 309 | rb->lcd_update(); |
283 | 310 | ||
284 | 311 | ||
285 | switch(rb->button_get(true)){ | 312 | button = rb->button_get(true); |
313 | switch(button){ | ||
286 | case BUTTON_DOWN: | 314 | case BUTTON_DOWN: |
287 | case BUTTON_LEFT: | 315 | case BUTTON_LEFT: |
288 | p = (p + 98)%100; | 316 | p = (p + 98)%100; |
@@ -293,12 +321,17 @@ int minesweeper(void) | |||
293 | p = (p + 2)%100; | 321 | p = (p + 2)%100; |
294 | break; | 322 | break; |
295 | 323 | ||
296 | case BUTTON_ON:/* start playing */ | 324 | case MINESWP_START:/* start playing */ |
297 | i = 1; | 325 | i = 1; |
298 | break; | 326 | break; |
299 | 327 | ||
300 | case BUTTON_OFF:/* quit program */ | 328 | case MINESWP_QUIT:/* quit program */ |
301 | return MINESWEEPER_QUIT; | 329 | return MINESWEEPER_QUIT; |
330 | |||
331 | default: | ||
332 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | ||
333 | return MINESWEEPER_USB; | ||
334 | break; | ||
302 | } | 335 | } |
303 | if(i==1) | 336 | if(i==1) |
304 | break; | 337 | break; |
@@ -345,34 +378,41 @@ int minesweeper(void) | |||
345 | /* update the screen */ | 378 | /* update the screen */ |
346 | rb->lcd_update(); | 379 | rb->lcd_update(); |
347 | 380 | ||
348 | switch(rb->button_get(true)){ | 381 | button = rb->button_get(true); |
382 | switch(button){ | ||
349 | /* quit minesweeper (you really shouldn't use this button ...) */ | 383 | /* quit minesweeper (you really shouldn't use this button ...) */ |
350 | case BUTTON_OFF: | 384 | case MINESWP_QUIT: |
351 | return MINESWEEPER_QUIT; | 385 | return MINESWEEPER_QUIT; |
352 | 386 | ||
353 | /* move cursor left */ | 387 | /* move cursor left */ |
354 | case BUTTON_LEFT: | 388 | case BUTTON_LEFT: |
389 | case (BUTTON_LEFT | BUTTON_REPEAT): | ||
355 | x = (x + width - 1)%width; | 390 | x = (x + width - 1)%width; |
356 | break; | 391 | break; |
357 | 392 | ||
358 | /* move cursor right */ | 393 | /* move cursor right */ |
359 | case BUTTON_RIGHT: | 394 | case BUTTON_RIGHT: |
395 | case (BUTTON_RIGHT | BUTTON_REPEAT): | ||
360 | x = (x + 1)%width; | 396 | x = (x + 1)%width; |
361 | break; | 397 | break; |
362 | 398 | ||
363 | /* move cursor down */ | 399 | /* move cursor down */ |
364 | case BUTTON_DOWN: | 400 | case BUTTON_DOWN: |
401 | case (BUTTON_DOWN | BUTTON_REPEAT): | ||
365 | y = (y + 1)%height; | 402 | y = (y + 1)%height; |
366 | break; | 403 | break; |
367 | 404 | ||
368 | /* move cursor up */ | 405 | /* move cursor up */ |
369 | case BUTTON_UP: | 406 | case BUTTON_UP: |
407 | case (BUTTON_UP | BUTTON_REPEAT): | ||
370 | y = (y + height - 1)%height; | 408 | y = (y + height - 1)%height; |
371 | break; | 409 | break; |
372 | 410 | ||
373 | /* discover a tile (and it's neighbors if .neighbors == 0) */ | 411 | /* discover a tile (and it's neighbors if .neighbors == 0) */ |
374 | case BUTTON_ON: | 412 | case MINESWP_DISCOVER: |
375 | case BUTTON_F2: | 413 | #ifdef MINESWP_DISCOVER2 |
414 | case MINESWP_DISCOVER2: | ||
415 | #endif | ||
376 | if(minefield[y][x].flag) break; | 416 | if(minefield[y][x].flag) break; |
377 | /* we put the mines on the first "click" so that you don't */ | 417 | /* we put the mines on the first "click" so that you don't */ |
378 | /* lose on the first "click" */ | 418 | /* lose on the first "click" */ |
@@ -393,14 +433,20 @@ int minesweeper(void) | |||
393 | break; | 433 | break; |
394 | 434 | ||
395 | /* toggle flag under cursor */ | 435 | /* toggle flag under cursor */ |
396 | case BUTTON_PLAY: | 436 | case MINESWP_TOGGLE: |
397 | case BUTTON_F1: | 437 | #ifdef MINESWP_TOGGLE_PRE |
438 | if (lastbutton != MINESWP_TOGGLE_PRE) | ||
439 | break; | ||
440 | #endif | ||
441 | #ifdef MINESWP_TOGGLE2 | ||
442 | case MINESWP_TOGGLE2: | ||
443 | #endif | ||
398 | minefield[y][x].flag = (minefield[y][x].flag + 1)%2; | 444 | minefield[y][x].flag = (minefield[y][x].flag + 1)%2; |
399 | break; | 445 | break; |
400 | 446 | ||
401 | /* show how many mines you think you have found and how many */ | 447 | /* show how many mines you think you have found and how many */ |
402 | /* there really are on the game */ | 448 | /* there really are on the game */ |
403 | case BUTTON_F3: | 449 | case MINESWP_INFO: |
404 | tiles_left = 0; | 450 | tiles_left = 0; |
405 | for(i=0;i<height;i++){ | 451 | for(i=0;i<height;i++){ |
406 | for(j=0;j<width;j++){ | 452 | for(j=0;j<width;j++){ |
@@ -409,7 +455,14 @@ int minesweeper(void) | |||
409 | } | 455 | } |
410 | rb->splash(HZ*2, true, "You found %d mines out of %d", tiles_left, mine_num); | 456 | rb->splash(HZ*2, true, "You found %d mines out of %d", tiles_left, mine_num); |
411 | break; | 457 | break; |
458 | |||
459 | default: | ||
460 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | ||
461 | return MINESWEEPER_USB; | ||
462 | break; | ||
412 | } | 463 | } |
464 | if (button != BUTTON_NONE) | ||
465 | lastbutton = button; | ||
413 | } | 466 | } |
414 | 467 | ||
415 | } | 468 | } |
@@ -431,6 +484,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
431 | case MINESWEEPER_LOSE: | 484 | case MINESWEEPER_LOSE: |
432 | rb->splash(HZ*2, true, "You Lost :("); | 485 | rb->splash(HZ*2, true, "You Lost :("); |
433 | break; | 486 | break; |
487 | |||
488 | case MINESWEEPER_USB: | ||
489 | return PLUGIN_USB_CONNECTED; | ||
434 | 490 | ||
435 | default: | 491 | default: |
436 | break; | 492 | break; |