summaryrefslogtreecommitdiff
path: root/apps/plugins/sokoban.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sokoban.c')
-rw-r--r--apps/plugins/sokoban.c85
1 files changed, 59 insertions, 26 deletions
diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c
index ff13b470f5..6365e6c3ae 100644
--- a/apps/plugins/sokoban.c
+++ b/apps/plugins/sokoban.c
@@ -33,6 +33,24 @@
33 33
34#define SOKOBAN_LEVEL_SIZE (ROWS*COLS) 34#define SOKOBAN_LEVEL_SIZE (ROWS*COLS)
35 35
36/* variable button definitions */
37#if CONFIG_KEYPAD == RECORDER_PAD
38#define SOKOBAN_QUIT BUTTON_OFF
39#define SOKOBAN_UNDO BUTTON_ON
40#define SOKOBAN_LEVEL_UP BUTTON_F3
41#define SOKOBAN_LEVEL_DOWN BUTTON_F1
42#define SOKOBAN_LEVEL_REPEAT BUTTON_F2
43
44#elif CONFIG_KEYPAD == ONDIO_PAD
45#define SOKOBAN_QUIT BUTTON_OFF
46#define SOKOBAN_UNDO_PRE BUTTON_MENU
47#define SOKOBAN_UNDO (BUTTON_MENU | BUTTON_REL)
48#define SOKOBAN_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT)
49#define SOKOBAN_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT)
50#define SOKOBAN_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP)
51
52#endif
53
36static void init_undo(void); 54static void init_undo(void);
37static void undo(void); 55static void undo(void);
38static void add_undo(int button); 56static void add_undo(int button);
@@ -443,7 +461,7 @@ static bool sokoban_loop(void)
443{ 461{
444 char new_spot; 462 char new_spot;
445 bool moved = true; 463 bool moved = true;
446 int i = 0, button = 0; 464 int i = 0, button = 0, lastbutton = 0;
447 short r = 0, c = 0; 465 short r = 0, c = 0;
448 466
449 current_info.level.level = 1; 467 current_info.level.level = 1;
@@ -465,27 +483,32 @@ static bool sokoban_loop(void)
465 { 483 {
466 case BUTTON_OFF: 484 case BUTTON_OFF:
467 /* get out of here */ 485 /* get out of here */
468 return PLUGIN_OK; 486 return PLUGIN_OK;
469 487
470 case BUTTON_ON: 488 case SOKOBAN_UNDO:
471 case BUTTON_ON | BUTTON_REPEAT: 489#ifdef SOKOBAN_UNDO_PRE
490 if (lastbutton != SOKOBAN_UNDO_PRE)
491 break;
492#else /* repeat can't work here for Ondio */
493 case SOKOBAN_UNDO | BUTTON_REPEAT:
494#endif
472 /* this is UNDO */ 495 /* this is UNDO */
473 undo(); 496 undo();
474 rb->lcd_clear_display(); 497 rb->lcd_clear_display();
475 update_screen(); 498 update_screen();
476 moved = false; 499 moved = false;
477 break; 500 break;
478 501
479 case BUTTON_F3: 502 case SOKOBAN_LEVEL_UP:
480 case BUTTON_F3 | BUTTON_REPEAT: 503 case SOKOBAN_LEVEL_UP | BUTTON_REPEAT:
481 /* increase level */ 504 /* increase level */
482 init_undo(); 505 init_undo();
483 current_info.level.boxes_to_go=0; 506 current_info.level.boxes_to_go=0;
484 moved = true; 507 moved = true;
485 break; 508 break;
486 509
487 case BUTTON_F1: 510 case SOKOBAN_LEVEL_DOWN:
488 case BUTTON_F1 | BUTTON_REPEAT: 511 case SOKOBAN_LEVEL_DOWN | BUTTON_REPEAT:
489 /* previous level */ 512 /* previous level */
490 init_undo(); 513 init_undo();
491 if (current_info.level.level > 1) 514 if (current_info.level.level > 1)
@@ -495,8 +518,8 @@ static bool sokoban_loop(void)
495 moved = false; 518 moved = false;
496 break; 519 break;
497 520
498 case BUTTON_F2: 521 case SOKOBAN_LEVEL_REPEAT:
499 case BUTTON_F2 | BUTTON_REPEAT: 522 case SOKOBAN_LEVEL_REPEAT | BUTTON_REPEAT:
500 /* same level */ 523 /* same level */
501 init_undo(); 524 init_undo();
502 draw_level(); 525 draw_level();
@@ -504,7 +527,7 @@ static bool sokoban_loop(void)
504 break; 527 break;
505 528
506 case BUTTON_LEFT: 529 case BUTTON_LEFT:
507 switch(current_info.board[r][c-1]) 530 switch(current_info.board[r][c-1])
508 { 531 {
509 case ' ': /* if it is a blank spot */ 532 case ' ': /* if it is a blank spot */
510 case '.': /* if it is a home spot */ 533 case '.': /* if it is a home spot */
@@ -527,7 +550,7 @@ static bool sokoban_loop(void)
527 case '.': /* going from a blank to home */ 550 case '.': /* going from a blank to home */
528 current_info.board[r][c-2] = '%'; 551 current_info.board[r][c-2] = '%';
529 current_info.board[r][c-1] = current_info.board[r][c]; 552 current_info.board[r][c-1] = current_info.board[r][c];
530 current_info.board[r][c] = current_info.player.spot; 553 current_info.board[r][c] = current_info.player.spot;
531 current_info.player.spot = ' '; 554 current_info.player.spot = ' ';
532 current_info.level.boxes_to_go--; 555 current_info.level.boxes_to_go--;
533 break; 556 break;
@@ -551,7 +574,7 @@ static bool sokoban_loop(void)
551 case '.': /* if we are going from a home to home */ 574 case '.': /* if we are going from a home to home */
552 current_info.board[r][c-2] = '%'; 575 current_info.board[r][c-2] = '%';
553 current_info.board[r][c-1] = current_info.board[r][c]; 576 current_info.board[r][c-1] = current_info.board[r][c];
554 current_info.board[r][c] = current_info.player.spot; 577 current_info.board[r][c] = current_info.player.spot;
555 current_info.player.spot = '.'; 578 current_info.player.spot = '.';
556 break; 579 break;
557 580
@@ -580,7 +603,7 @@ static bool sokoban_loop(void)
580 current_info.player.spot = new_spot; 603 current_info.player.spot = new_spot;
581 break; 604 break;
582 605
583 case '$': 606 case '$':
584 switch(current_info.board[r][c+2]) { 607 switch(current_info.board[r][c+2]) {
585 case ' ': /* going from blank to blank */ 608 case ' ': /* going from blank to blank */
586 current_info.board[r][c+2] = current_info.board[r][c+1]; 609 current_info.board[r][c+2] = current_info.board[r][c+1];
@@ -592,7 +615,7 @@ static bool sokoban_loop(void)
592 case '.': /* going from a blank to home */ 615 case '.': /* going from a blank to home */
593 current_info.board[r][c+2] = '%'; 616 current_info.board[r][c+2] = '%';
594 current_info.board[r][c+1] = current_info.board[r][c]; 617 current_info.board[r][c+1] = current_info.board[r][c];
595 current_info.board[r][c] = current_info.player.spot; 618 current_info.board[r][c] = current_info.player.spot;
596 current_info.player.spot = ' '; 619 current_info.player.spot = ' ';
597 current_info.level.boxes_to_go--; 620 current_info.level.boxes_to_go--;
598 break; 621 break;
@@ -616,7 +639,7 @@ static bool sokoban_loop(void)
616 case '.': 639 case '.':
617 current_info.board[r][c+2] = '%'; 640 current_info.board[r][c+2] = '%';
618 current_info.board[r][c+1] = current_info.board[r][c]; 641 current_info.board[r][c+1] = current_info.board[r][c];
619 current_info.board[r][c] = current_info.player.spot; 642 current_info.board[r][c] = current_info.player.spot;
620 current_info.player.spot = '.'; 643 current_info.player.spot = '.';
621 break; 644 break;
622 645
@@ -657,7 +680,7 @@ static bool sokoban_loop(void)
657 case '.': /* going from a blank to home */ 680 case '.': /* going from a blank to home */
658 current_info.board[r-2][c] = '%'; 681 current_info.board[r-2][c] = '%';
659 current_info.board[r-1][c] = current_info.board[r][c]; 682 current_info.board[r-1][c] = current_info.board[r][c];
660 current_info.board[r][c] = current_info.player.spot; 683 current_info.board[r][c] = current_info.player.spot;
661 current_info.player.spot = ' '; 684 current_info.player.spot = ' ';
662 current_info.level.boxes_to_go--; 685 current_info.level.boxes_to_go--;
663 break; 686 break;
@@ -681,7 +704,7 @@ static bool sokoban_loop(void)
681 case '.': /* if we are going from a home to home */ 704 case '.': /* if we are going from a home to home */
682 current_info.board[r-2][c] = '%'; 705 current_info.board[r-2][c] = '%';
683 current_info.board[r-1][c] = current_info.board[r][c]; 706 current_info.board[r-1][c] = current_info.board[r][c];
684 current_info.board[r][c] = current_info.player.spot; 707 current_info.board[r][c] = current_info.player.spot;
685 current_info.player.spot = '.'; 708 current_info.player.spot = '.';
686 break; 709 break;
687 710
@@ -722,7 +745,7 @@ static bool sokoban_loop(void)
722 case '.': /* going from a blank to home */ 745 case '.': /* going from a blank to home */
723 current_info.board[r+2][c] = '%'; 746 current_info.board[r+2][c] = '%';
724 current_info.board[r+1][c] = current_info.board[r][c]; 747 current_info.board[r+1][c] = current_info.board[r][c];
725 current_info.board[r][c] = current_info.player.spot; 748 current_info.board[r][c] = current_info.player.spot;
726 current_info.player.spot = ' '; 749 current_info.player.spot = ' ';
727 current_info.level.boxes_to_go--; 750 current_info.level.boxes_to_go--;
728 break; 751 break;
@@ -746,7 +769,7 @@ static bool sokoban_loop(void)
746 case '.': /* going from a home to home */ 769 case '.': /* going from a home to home */
747 current_info.board[r+2][c] = '%'; 770 current_info.board[r+2][c] = '%';
748 current_info.board[r+1][c] = current_info.board[r][c]; 771 current_info.board[r+1][c] = current_info.board[r][c];
749 current_info.board[r][c] = current_info.player.spot; 772 current_info.board[r][c] = current_info.player.spot;
750 current_info.player.spot = '.'; 773 current_info.player.spot = '.';
751 break; 774 break;
752 775
@@ -765,19 +788,21 @@ static bool sokoban_loop(void)
765 current_info.player.row++; 788 current_info.player.row++;
766 break; 789 break;
767 790
768 case SYS_USB_CONNECTED:
769 rb->usb_screen();
770 return PLUGIN_USB_CONNECTED;
771
772 default: 791 default:
792 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
793 return PLUGIN_USB_CONNECTED;
794
773 moved = false; 795 moved = false;
774 break; 796 break;
775 } 797 }
776 798
799 if (button != BUTTON_NONE)
800 lastbutton = button;
801
777 if (moved) { 802 if (moved) {
778 current_info.level.moves++; 803 current_info.level.moves++;
779 rb->lcd_clear_display(); 804 rb->lcd_clear_display();
780 update_screen(); 805 update_screen();
781 } 806 }
782 807
783 /* We have completed this level */ 808 /* We have completed this level */
@@ -845,11 +870,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
845 870
846 rb->lcd_clear_display(); 871 rb->lcd_clear_display();
847 872
873#if CONFIG_KEYPAD == RECORDER_PAD
848 rb->lcd_putsxy(3, 6, "[OFF] To Stop"); 874 rb->lcd_putsxy(3, 6, "[OFF] To Stop");
849 rb->lcd_putsxy(3, 16, "[ON] To Undo"); 875 rb->lcd_putsxy(3, 16, "[ON] To Undo");
850 rb->lcd_putsxy(3, 26, "[F1] - Level"); 876 rb->lcd_putsxy(3, 26, "[F1] - Level");
851 rb->lcd_putsxy(3, 36, "[F2] Same Level"); 877 rb->lcd_putsxy(3, 36, "[F2] Same Level");
852 rb->lcd_putsxy(3, 46, "[F3] + Level"); 878 rb->lcd_putsxy(3, 46, "[F3] + Level");
879#elif CONFIG_KEYPAD == ONDIO_PAD
880 rb->lcd_putsxy(3, 6, "[OFF] To Stop");
881 rb->lcd_putsxy(3, 16, "[MENU] To Undo");
882 rb->lcd_putsxy(3, 26, "[M-LEFT] - Level");
883 rb->lcd_putsxy(3, 36, "[M-UP] Same Level");
884 rb->lcd_putsxy(3, 46, "[M-RIGHT] + Level");
885#endif
853 886
854 rb->lcd_update(); 887 rb->lcd_update();
855 rb->sleep(HZ*2); 888 rb->sleep(HZ*2);