summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/recorder/sokoban.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/apps/recorder/sokoban.c b/apps/recorder/sokoban.c
index bac1101838..810cf22c11 100644
--- a/apps/recorder/sokoban.c
+++ b/apps/recorder/sokoban.c
@@ -45,14 +45,62 @@
45static void load_level(int); 45static void load_level(int);
46static void update_screen(void); 46static void update_screen(void);
47static bool sokoban_loop(void); 47static bool sokoban_loop(void);
48static void copy_current_state_to_undo(void);
49static void copy_current_undo_to_state(void);
48 50
49static char board[16][20]; 51static char board[16][20];
52static char undo_board[16][20];
50static int current_level=0; 53static int current_level=0;
54static int undo_current_level=0;
51static int moves=0; 55static int moves=0;
56static int undo_moves=0;
52static int row=0; 57static int row=0;
58static int undo_row=0;
53static int col=0; 59static int col=0;
60static int undo_col=0;
54static int boxes_to_go=0; 61static int boxes_to_go=0;
62static int undo_boxes_to_go=0;
55static char current_spot= ' '; 63static char current_spot= ' ';
64static char undo_current_spot=' ';
65
66
67
68static void copy_current_state_to_undo(void) {
69 int a = 0;
70 int b = 0;
71
72 for (a=0 ; a<16 ; a++) {
73 for (b=0; b<16 ; b++) {
74 undo_board[a][b] = board[a][b];
75 }
76 }
77 undo_current_level = current_level;
78 undo_moves = moves;
79 undo_row = row;
80 undo_col = col;
81 undo_boxes_to_go = boxes_to_go;
82 undo_current_spot = current_spot;
83
84 return;
85}
86
87static void copy_current_undo_to_state(void) {
88 int a = 0;
89 int b = 0;
90
91 for (a=0 ; a<16 ; a++) {
92 for (b=0; b<16 ; b++) {
93 board[a][b] = undo_board[a][b];
94 }
95 }
96 current_level = undo_current_level;
97 moves = undo_moves-1;
98 row = undo_row;
99 col = undo_col;
100 boxes_to_go = undo_boxes_to_go;
101 current_spot = undo_current_spot;
102 return;
103}
56 104
57static void load_level (int level_to_load) { 105static void load_level (int level_to_load) {
58 int a = 0; 106 int a = 0;
@@ -152,9 +200,9 @@ static bool sokoban_loop(void)
152 update_screen(); 200 update_screen();
153 201
154 while(1) { 202 while(1) {
203
155 bool idle = false; 204 bool idle = false;
156 switch ( button_get(true) ) { 205 switch ( button_get(true) ) {
157
158 case BUTTON_OFF: 206 case BUTTON_OFF:
159 /* get out of here */ 207 /* get out of here */
160 return false; 208 return false;
@@ -165,6 +213,11 @@ static bool sokoban_loop(void)
165 idle=true; 213 idle=true;
166 break; 214 break;
167 215
216 case BUTTON_ON:
217 /* this is UNDO */
218 copy_current_undo_to_state();
219 break;
220
168 case BUTTON_F2: 221 case BUTTON_F2:
169 /* same level */ 222 /* same level */
170 load_level(current_level); 223 load_level(current_level);
@@ -188,6 +241,7 @@ static bool sokoban_loop(void)
188 break; 241 break;
189 242
190 case BUTTON_LEFT: 243 case BUTTON_LEFT:
244 copy_current_state_to_undo();
191 switch ( board[row][col-1] ) { 245 switch ( board[row][col-1] ) {
192 case ' ': /* if it is a blank spot */ 246 case ' ': /* if it is a blank spot */
193 board[row][col-1]='@'; 247 board[row][col-1]='@';
@@ -256,6 +310,7 @@ static bool sokoban_loop(void)
256 break; 310 break;
257 311
258 case BUTTON_RIGHT: /* if it is a blank spot */ 312 case BUTTON_RIGHT: /* if it is a blank spot */
313 copy_current_state_to_undo();
259 switch ( board[row][col+1] ) { 314 switch ( board[row][col+1] ) {
260 case ' ': 315 case ' ':
261 board[row][col+1]='@'; 316 board[row][col+1]='@';
@@ -324,6 +379,7 @@ static bool sokoban_loop(void)
324 break; 379 break;
325 380
326 case BUTTON_UP: 381 case BUTTON_UP:
382 copy_current_state_to_undo();
327 switch ( board[row-1][col] ) { 383 switch ( board[row-1][col] ) {
328 case ' ': /* if it is a blank spot */ 384 case ' ': /* if it is a blank spot */
329 board[row-1][col]='@'; 385 board[row-1][col]='@';
@@ -392,6 +448,7 @@ static bool sokoban_loop(void)
392 break; 448 break;
393 449
394 case BUTTON_DOWN: 450 case BUTTON_DOWN:
451 copy_current_state_to_undo();
395 switch ( board[row+1][col] ) { 452 switch ( board[row+1][col] ) {
396 case ' ': /* if it is a blank spot */ 453 case ' ': /* if it is a blank spot */
397 board[row+1][col]='@'; 454 board[row+1][col]='@';
@@ -478,7 +535,7 @@ static bool sokoban_loop(void)
478 moves=0; 535 moves=0;
479 current_level++; 536 current_level++;
480 if (current_level == NUM_LEVELS) { 537 if (current_level == NUM_LEVELS) {
481 for(ii=0; ii<30 ; ii++) { 538 for(ii=0; ii<300 ; ii++) {
482 lcd_clear_display(); 539 lcd_clear_display();
483 lcd_putsxy(10, 20, str(LANG_SOKOBAN_WIN)); 540 lcd_putsxy(10, 20, str(LANG_SOKOBAN_WIN));
484 lcd_update(); 541 lcd_update();