diff options
author | Robert Hak <adiamas@rockbox.org> | 2002-06-16 23:24:22 +0000 |
---|---|---|
committer | Robert Hak <adiamas@rockbox.org> | 2002-06-16 23:24:22 +0000 |
commit | d58ab78e2cf89e1279536835a16ba9e2b32142a8 (patch) | |
tree | 3e81be32dd0a7f5e6e23e2ae1b35b1d6cd6eb320 | |
parent | 4990c7511a48fec81ca2b438b318f6056b023fa6 (diff) | |
download | rockbox-d58ab78e2cf89e1279536835a16ba9e2b32142a8.tar.gz rockbox-d58ab78e2cf89e1279536835a16ba9e2b32142a8.zip |
first there was tetris, now we have sokoban
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1020 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/recorder/sokoban.c | 586 | ||||
-rw-r--r-- | apps/recorder/sokoban.h | 29 |
2 files changed, 615 insertions, 0 deletions
diff --git a/apps/recorder/sokoban.c b/apps/recorder/sokoban.c new file mode 100644 index 0000000000..159516e361 --- /dev/null +++ b/apps/recorder/sokoban.c | |||
@@ -0,0 +1,586 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: sokoban.c,v 0.01 2002/06/15 | ||
9 | * | ||
10 | * Copyright (C) 2002 Eric Linenberg | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "config.h" | ||
21 | |||
22 | #ifdef HAVE_LCD_BITMAP | ||
23 | |||
24 | #include "sokoban.h" | ||
25 | #include "lcd.h" | ||
26 | #include "button.h" | ||
27 | #include "kernel.h" | ||
28 | |||
29 | #ifdef SIMULATOR | ||
30 | #include <stdio.h> | ||
31 | #endif | ||
32 | #include <string.h> | ||
33 | |||
34 | #define SOKOBAN_TITLE "Sokoban" | ||
35 | #define SOKOBAN_TITLE_FONT 2 | ||
36 | #define NUM_LEVELS 4 | ||
37 | |||
38 | int board[16][20]; | ||
39 | int current_level=0; | ||
40 | int moves=0; | ||
41 | int row=0; | ||
42 | int col=0; | ||
43 | int boxes_to_go=0; | ||
44 | int current_spot=1; | ||
45 | |||
46 | /* 320 boxes per level */ | ||
47 | int levels[320*NUM_LEVELS] = { | ||
48 | /* level 01 */ | ||
49 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
50 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
51 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
52 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
53 | 0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0, | ||
54 | 0,0,0,0,0,0,0,0,2,3,2,0,0,0,0,0,0,0,0,0, | ||
55 | 0,0,0,0,0,0,0,0,2,1,2,2,2,2,0,0,0,0,0,0, | ||
56 | 0,0,0,0,0,0,2,2,2,4,1,4,3,2,0,0,0,0,0,0, | ||
57 | 0,0,0,0,0,0,2,3,1,4,5,2,2,2,0,0,0,0,0,0, | ||
58 | 0,0,0,0,0,0,2,2,2,2,4,2,0,0,0,0,0,0,0,0, | ||
59 | 0,0,0,0,0,0,0,0,0,2,3,2,0,0,0,0,0,0,0,0, | ||
60 | 0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0, | ||
61 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
62 | 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0, | ||
129 | 0,0,0,0,0,2,1,1,1,1,1,2,2,2,0,0,0,0,0,0, | ||
130 | 0,0,0,0,0,2,1,1,2,2,2,2,0,0,0,0,0,0,0,0, | ||
131 | 0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0, | ||
132 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 */ | ||
133 | }; | ||
134 | |||
135 | |||
136 | |||
137 | void load_level(int level_to_load) { | ||
138 | int a = 0; | ||
139 | int b = 0; | ||
140 | int c = 0; | ||
141 | |||
142 | /* load level into board */ | ||
143 | /* get to the current level in the level array */ | ||
144 | a = level_to_load*320; | ||
145 | |||
146 | for(b=0 ; b<16 ; b++) { | ||
147 | for (c=0 ; c<20 ; c++) { | ||
148 | board[b][c] = levels[a]; | ||
149 | a++; | ||
150 | if (board[b][c]==5) { | ||
151 | row = b; | ||
152 | col = c; | ||
153 | } | ||
154 | if (board[b][c]==3) | ||
155 | boxes_to_go++; | ||
156 | } | ||
157 | } | ||
158 | return; | ||
159 | } | ||
160 | |||
161 | void update_screen(void) { | ||
162 | int b = 0; | ||
163 | int c = 0; | ||
164 | char s[25]; | ||
165 | |||
166 | /* load the board to the screen */ | ||
167 | for(b=0 ; b<16 ; b++) { | ||
168 | for (c=0 ; c<20 ; c++) { | ||
169 | |||
170 | /* this is a black space */ | ||
171 | if (board[b][c]==0) { | ||
172 | lcd_drawrect (c*4, b*4, c*4+3, b*4+3); | ||
173 | lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2); | ||
174 | } | ||
175 | /* this is a wall */ | ||
176 | if (board[b][c]==2) { | ||
177 | lcd_drawpixel (c*4, b*4); | ||
178 | lcd_drawpixel (c*4+2, b*4); | ||
179 | lcd_drawpixel (c*4+1, b*4+1); | ||
180 | lcd_drawpixel (c*4+3, b*4+1); | ||
181 | lcd_drawpixel (c*4, b*4+2); | ||
182 | lcd_drawpixel (c*4+2, b*4+2); | ||
183 | lcd_drawpixel (c*4+1, b*4+3); | ||
184 | lcd_drawpixel (c*4+3, b*4+3); | ||
185 | } | ||
186 | /* this is a box */ | ||
187 | if (board[b][c]==4) { | ||
188 | lcd_drawrect (c*4, b*4, c*4+3, b*4+3); | ||
189 | } | ||
190 | /* this is a home location */ | ||
191 | if (board[b][c]==3) { | ||
192 | lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2); | ||
193 | } | ||
194 | /* this is you */ | ||
195 | if (board[b][c]==5) { | ||
196 | lcd_drawline (c*4+1, b*4, c*4+2, b*4); | ||
197 | lcd_drawline (c*4, b*4+1, c*4+3, b*4+1); | ||
198 | lcd_drawline (c*4+1, b*4+2, c*4+2, b*4+2); | ||
199 | lcd_drawpixel (c*4, b*4+3); | ||
200 | lcd_drawpixel (c*4+3, b*4+3); | ||
201 | } | ||
202 | /* this is a box on a home spot */ | ||
203 | if (board[b][c]==7) { | ||
204 | lcd_drawrect (c*4, b*4, c*4+3, b*4+3); | ||
205 | lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2); | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | |||
211 | snprintf (s, sizeof(s), "%d", current_level+1); | ||
212 | lcd_putsxy (86, 20, s, 0); | ||
213 | snprintf (s, sizeof(s), "%d", moves); | ||
214 | lcd_putsxy (86, 52, s, 0); | ||
215 | |||
216 | lcd_drawrect (80,0,111,31); | ||
217 | lcd_drawrect (80,32,111,63); | ||
218 | lcd_putsxy (81, 10, "Level", 0); | ||
219 | lcd_putsxy (81, 42, "Moves", 0); | ||
220 | /* print out the screen */ | ||
221 | lcd_update(); | ||
222 | } | ||
223 | |||
224 | |||
225 | |||
226 | void sokoban_loop(void) { | ||
227 | int ii = 0; | ||
228 | int b = 0; | ||
229 | moves = 0; | ||
230 | current_level = 0; | ||
231 | load_level(current_level); | ||
232 | update_screen(); | ||
233 | |||
234 | while(1) { | ||
235 | b = button_get(false); | ||
236 | |||
237 | if ( b & BUTTON_OFF ) { | ||
238 | /* get out of here */ | ||
239 | return; | ||
240 | } | ||
241 | |||
242 | |||
243 | if ( b & BUTTON_F1 ) { | ||
244 | /* get out of here */ | ||
245 | boxes_to_go=0; | ||
246 | } | ||
247 | |||
248 | if ( b & BUTTON_LEFT ) { | ||
249 | /* if it is a blank spot */ | ||
250 | if (board[row][col-1]==1) { | ||
251 | board[row][col-1]=5; | ||
252 | board[row][col]=current_spot; | ||
253 | current_spot=1; | ||
254 | col--; | ||
255 | moves++; | ||
256 | } | ||
257 | /* if it is a home spot */ | ||
258 | else if (board[row][col-1]==3) { | ||
259 | board[row][col-1]=5; | ||
260 | board[row][col]=current_spot; | ||
261 | current_spot=3; | ||
262 | col--; | ||
263 | moves++; | ||
264 | } | ||
265 | else if (board[row][col-1]==4) { | ||
266 | /* if there is a wall then do not move the box */ | ||
267 | if(board[row][col-2]==2) { | ||
268 | /* do nothing */ | ||
269 | } | ||
270 | /* if we are going from blank to blank */ | ||
271 | else if(board[row][col-2]==1) { | ||
272 | board[row][col-2]=board[row][col-1]; | ||
273 | board[row][col-1]=board[row][col]; | ||
274 | board[row][col]=current_spot; | ||
275 | current_spot=1; | ||
276 | col--; | ||
277 | moves++; | ||
278 | } | ||
279 | /* if we are going from a blank to home */ | ||
280 | else if(board[row][col-2]==3) { | ||
281 | board[row][col-2]=7; | ||
282 | board[row][col-1]=board[row][col]; | ||
283 | board[row][col]=current_spot; | ||
284 | current_spot=1; | ||
285 | col--; | ||
286 | boxes_to_go--; | ||
287 | moves++; | ||
288 | } | ||
289 | } | ||
290 | else if (board[row][col-1]==7) { | ||
291 | /* if there is a wall then do not move the box */ | ||
292 | if(board[row][col-2]==2) { | ||
293 | /* do nothing */ | ||
294 | } | ||
295 | /* we are going from a home to a blank */ | ||
296 | else if(board[row][col-2]==1) { | ||
297 | board[row][col-2]=4; | ||
298 | board[row][col-1]=board[row][col]; | ||
299 | board[row][col]=current_spot; | ||
300 | current_spot=3; | ||
301 | col--; | ||
302 | boxes_to_go++; | ||
303 | moves++; | ||
304 | } | ||
305 | /* if we are going from a home to home */ | ||
306 | else if(board[row][col-2]==3) { | ||
307 | board[row][col-2]=7; | ||
308 | board[row][col-1]=board[row][col]; | ||
309 | board[row][col]=current_spot; | ||
310 | current_spot=3; | ||
311 | col--; | ||
312 | moves++; | ||
313 | } | ||
314 | } | ||
315 | lcd_clear_display(); | ||
316 | update_screen(); | ||
317 | } | ||
318 | |||
319 | |||
320 | if ( b & BUTTON_RIGHT ) { | ||
321 | /* if it is a blank spot */ | ||
322 | if (board[row][col+1]==1) { | ||
323 | board[row][col+1]=5; | ||
324 | board[row][col]=current_spot; | ||
325 | current_spot=1; | ||
326 | col++; | ||
327 | moves++; | ||
328 | } | ||
329 | /* if it is a home spot */ | ||
330 | else if (board[row][col+1]==3) { | ||
331 | board[row][col+1]=5; | ||
332 | board[row][col]=current_spot; | ||
333 | current_spot=3; | ||
334 | col++; | ||
335 | moves++; | ||
336 | } | ||
337 | else if (board[row][col+1]==4) { | ||
338 | /* if there is a wall then do not move the box */ | ||
339 | if(board[row][col+2]==2) { | ||
340 | /* do nothing */ | ||
341 | } | ||
342 | /* if we are going from blank to blank */ | ||
343 | else if(board[row][col+2]==1) { | ||
344 | board[row][col+2]=board[row][col+1]; | ||
345 | board[row][col+1]=board[row][col]; | ||
346 | board[row][col]=current_spot; | ||
347 | current_spot=1; | ||
348 | col++; | ||
349 | moves++; | ||
350 | } | ||
351 | /* if we are going from a blank to home */ | ||
352 | else if(board[row][col+2]==3) { | ||
353 | board[row][col+2]=7; | ||
354 | board[row][col+1]=board[row][col]; | ||
355 | board[row][col]=current_spot; | ||
356 | current_spot=1; | ||
357 | col++; | ||
358 | boxes_to_go--; | ||
359 | moves++; | ||
360 | } | ||
361 | } | ||
362 | else if (board[row][col+1]==7) { | ||
363 | /* if there is a wall then do not move the box */ | ||
364 | if(board[row][col+2]==2) { | ||
365 | /* do nothing */ | ||
366 | } | ||
367 | /* we are going from a home to a blank */ | ||
368 | else if(board[row][col+2]==1) { | ||
369 | board[row][col+2]=4; | ||
370 | board[row][col+1]=board[row][col]; | ||
371 | board[row][col]=current_spot; | ||
372 | current_spot=3; | ||
373 | col++; | ||
374 | boxes_to_go++; | ||
375 | moves++; | ||
376 | } | ||
377 | /* if we are going from a home to home */ | ||
378 | else if(board[row][col+2]==3) { | ||
379 | board[row][col+2]=7; | ||
380 | board[row][col+1]=board[row][col]; | ||
381 | board[row][col]=current_spot; | ||
382 | current_spot=3; | ||
383 | col++; | ||
384 | moves++; | ||
385 | } | ||
386 | } | ||
387 | lcd_clear_display(); | ||
388 | update_screen(); | ||
389 | } | ||
390 | |||
391 | if ( b & BUTTON_UP ) { | ||
392 | /* if it is a blank spot */ | ||
393 | if (board[row-1][col]==1) { | ||
394 | board[row-1][col]=5; | ||
395 | board[row][col]=current_spot; | ||
396 | current_spot=1; | ||
397 | row--; | ||
398 | moves++; | ||
399 | } | ||
400 | /* if it is a home spot */ | ||
401 | else if (board[row-1][col]==3) { | ||
402 | board[row-1][col]=5; | ||
403 | board[row][col]=current_spot; | ||
404 | current_spot=3; | ||
405 | row--; | ||
406 | moves++; | ||
407 | } | ||
408 | else if (board[row-1][col]==4) { | ||
409 | /* if there is a wall then do not move the box */ | ||
410 | if(board[row-2][col]==2) { | ||
411 | /* do nothing */ | ||
412 | } | ||
413 | /* if we are going from blank to blank */ | ||
414 | else if(board[row-2][col]==1) { | ||
415 | board[row-2][col]=board[row-1][col]; | ||
416 | board[row-1][col]=board[row][col]; | ||
417 | board[row][col]=current_spot; | ||
418 | current_spot=1; | ||
419 | row--; | ||
420 | moves++; | ||
421 | } | ||
422 | /* if we are going from a blank to home */ | ||
423 | else if(board[row-2][col]==3) { | ||
424 | board[row-2][col]=7; | ||
425 | board[row-1][col]=board[row][col]; | ||
426 | board[row][col]=current_spot; | ||
427 | current_spot=1; | ||
428 | row--; | ||
429 | boxes_to_go--; | ||
430 | moves++; | ||
431 | } | ||
432 | } | ||
433 | else if (board[row-1][col]==7) { | ||
434 | /* if there is a wall then do not move the box */ | ||
435 | if(board[row-2][col]==2) { | ||
436 | /* do nothing */ | ||
437 | } | ||
438 | /* we are going from a home to a blank */ | ||
439 | else if(board[row-2][col]==1) { | ||
440 | board[row-2][col]=4; | ||
441 | board[row-1][col]=board[row][col]; | ||
442 | board[row][col]=current_spot; | ||
443 | current_spot=3; | ||
444 | row--; | ||
445 | boxes_to_go++; | ||
446 | moves++; | ||
447 | } | ||
448 | /* if we are going from a home to home */ | ||
449 | else if(board[row-2][col]==3) { | ||
450 | board[row-2][col]=7; | ||
451 | board[row-1][col]=board[row][col]; | ||
452 | board[row][col]=current_spot; | ||
453 | current_spot=3; | ||
454 | row--; | ||
455 | moves++; | ||
456 | } | ||
457 | } | ||
458 | lcd_clear_display(); | ||
459 | update_screen(); | ||
460 | } | ||
461 | |||
462 | if ( b & BUTTON_DOWN ) { | ||
463 | /* if it is a blank spot */ | ||
464 | if (board[row+1][col]==1) { | ||
465 | board[row+1][col]=5; | ||
466 | board[row][col]=current_spot; | ||
467 | current_spot=1; | ||
468 | row++; | ||
469 | moves++; | ||
470 | } | ||
471 | /* if it is a home spot */ | ||
472 | else if (board[row+1][col]==3) { | ||
473 | board[row+1][col]=5; | ||
474 | board[row][col]=current_spot; | ||
475 | current_spot=3; | ||
476 | row++; | ||
477 | moves++; | ||
478 | } | ||
479 | else if (board[row+1][col]==4) { | ||
480 | /* if there is a wall then do not move the box */ | ||
481 | if(board[row+2][col]==2) { | ||
482 | /* do nothing */ | ||
483 | } | ||
484 | /* if we are going from blank to blank */ | ||
485 | else if(board[row+2][col]==1) { | ||
486 | board[row+2][col]=board[row+1][col]; | ||
487 | board[row+1][col]=board[row][col]; | ||
488 | board[row][col]=current_spot; | ||
489 | current_spot=1; | ||
490 | row++; | ||
491 | moves++; | ||
492 | } | ||
493 | /* if we are going from a blank to home */ | ||
494 | else if(board[row+2][col]==3) { | ||
495 | board[row+2][col]=7; | ||
496 | board[row+1][col]=board[row][col]; | ||
497 | board[row][col]=current_spot; | ||
498 | current_spot=1; | ||
499 | row++; | ||
500 | boxes_to_go--; | ||
501 | moves++; | ||
502 | } | ||
503 | } | ||
504 | else if (board[row+1][col]==7) { | ||
505 | /* if there is a wall then do not move the box */ | ||
506 | if(board[row+2][col]==2) { | ||
507 | /* do nothing */ | ||
508 | } | ||
509 | /* we are going from a home to a blank */ | ||
510 | else if(board[row+2][col]==1) { | ||
511 | board[row+2][col]=4; | ||
512 | board[row+1][col]=board[row][col]; | ||
513 | board[row][col]=current_spot; | ||
514 | current_spot=3; | ||
515 | row++; | ||
516 | boxes_to_go++; | ||
517 | moves++; | ||
518 | } | ||
519 | /* if we are going from a home to home */ | ||
520 | else if(board[row+2][col]==3) { | ||
521 | board[row+2][col]=7; | ||
522 | board[row+1][col]=board[row][col]; | ||
523 | board[row][col]=current_spot; | ||
524 | current_spot=3; | ||
525 | row++; | ||
526 | moves++; | ||
527 | } | ||
528 | } | ||
529 | lcd_clear_display(); | ||
530 | update_screen(); | ||
531 | } | ||
532 | |||
533 | if (boxes_to_go==0) { | ||
534 | moves=0; | ||
535 | current_level++; | ||
536 | if (current_level == NUM_LEVELS) { | ||
537 | lcd_clear_display(); | ||
538 | lcd_putsxy(10, 20, "YOU WIN!!", 2); | ||
539 | |||
540 | lcd_update(); | ||
541 | for (ii=0 ; ii<20 ; ii++) { | ||
542 | lcd_invertrect(0,0,111,63); | ||
543 | lcd_update(); | ||
544 | } | ||
545 | return; | ||
546 | } | ||
547 | load_level(current_level); | ||
548 | lcd_clear_display(); | ||
549 | update_screen(); | ||
550 | } | ||
551 | } | ||
552 | } | ||
553 | |||
554 | |||
555 | void sokoban(void) | ||
556 | { | ||
557 | int w, h; | ||
558 | int len = strlen(SOKOBAN_TITLE); | ||
559 | |||
560 | lcd_getfontsize(SOKOBAN_TITLE_FONT, &w, &h); | ||
561 | |||
562 | /* Get horizontel centering for text */ | ||
563 | len *= w; | ||
564 | if (len%2 != 0) | ||
565 | len = ((len+1)/2)+(w/2); | ||
566 | else | ||
567 | len /= 2; | ||
568 | |||
569 | if (h%2 != 0) | ||
570 | h = (h/2)+1; | ||
571 | else | ||
572 | h /= 2; | ||
573 | |||
574 | lcd_clear_display(); | ||
575 | lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SOKOBAN_TITLE, | ||
576 | SOKOBAN_TITLE_FONT); | ||
577 | lcd_putsxy( 3,42, "[Off] to stop", 0); | ||
578 | lcd_putsxy( 3,52, "[F1] + level",0); | ||
579 | |||
580 | lcd_update(); | ||
581 | sleep(HZ*2); | ||
582 | lcd_clear_display(); | ||
583 | sokoban_loop(); | ||
584 | } | ||
585 | |||
586 | #endif | ||
diff --git a/apps/recorder/sokoban.h b/apps/recorder/sokoban.h new file mode 100644 index 0000000000..8e6c54c43e --- /dev/null +++ b/apps/recorder/sokoban.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef __SOKOBAN__ | ||
21 | #define __SOKOBAN__ | ||
22 | |||
23 | void load_level(int); | ||
24 | void update_screen(void); | ||
25 | void sokoban_loop(void); | ||
26 | void sokoban(void); | ||
27 | |||
28 | #endif /*__SOKOBAN__ */ | ||
29 | |||