diff options
author | Eric Linenberg <elinenbe@umich.edu> | 2003-01-16 05:44:00 +0000 |
---|---|---|
committer | Eric Linenberg <elinenbe@umich.edu> | 2003-01-16 05:44:00 +0000 |
commit | 16576efae71f9f38ca0e45a0419b0a801613f275 (patch) | |
tree | d1041f5ca492437cb9ddf9de6cb879a7778ad43d /apps/recorder | |
parent | 86a4499d28efbc87d30ac1e1ac6c257f3624611a (diff) | |
download | rockbox-16576efae71f9f38ca0e45a0419b0a801613f275.tar.gz rockbox-16576efae71f9f38ca0e45a0419b0a801613f275.zip |
press ON for undo in sokoban (only 1 undo for now, but better than nothing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3103 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/recorder')
-rw-r--r-- | apps/recorder/sokoban.c | 61 |
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 @@ | |||
45 | static void load_level(int); | 45 | static void load_level(int); |
46 | static void update_screen(void); | 46 | static void update_screen(void); |
47 | static bool sokoban_loop(void); | 47 | static bool sokoban_loop(void); |
48 | static void copy_current_state_to_undo(void); | ||
49 | static void copy_current_undo_to_state(void); | ||
48 | 50 | ||
49 | static char board[16][20]; | 51 | static char board[16][20]; |
52 | static char undo_board[16][20]; | ||
50 | static int current_level=0; | 53 | static int current_level=0; |
54 | static int undo_current_level=0; | ||
51 | static int moves=0; | 55 | static int moves=0; |
56 | static int undo_moves=0; | ||
52 | static int row=0; | 57 | static int row=0; |
58 | static int undo_row=0; | ||
53 | static int col=0; | 59 | static int col=0; |
60 | static int undo_col=0; | ||
54 | static int boxes_to_go=0; | 61 | static int boxes_to_go=0; |
62 | static int undo_boxes_to_go=0; | ||
55 | static char current_spot= ' '; | 63 | static char current_spot= ' '; |
64 | static char undo_current_spot=' '; | ||
65 | |||
66 | |||
67 | |||
68 | static 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 | |||
87 | static 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 | ||
57 | static void load_level (int level_to_load) { | 105 | static 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(); |