2002-06-16 23:24:22 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2002-06-20 10:49:15 +00:00
|
|
|
* $Id$
|
2002-06-16 23:24:22 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Eric Linenberg
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-09-06 07:35:40 +00:00
|
|
|
#include "options.h"
|
2002-10-29 10:45:29 +00:00
|
|
|
|
2002-08-31 23:41:17 +00:00
|
|
|
#ifdef USE_GAMES
|
2002-08-31 22:55:40 +00:00
|
|
|
|
|
|
|
#include <sprintf.h>
|
2002-06-16 23:24:22 +00:00
|
|
|
#include "sokoban.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
2002-08-23 12:32:52 +00:00
|
|
|
#include "menu.h"
|
2002-09-24 17:22:12 +00:00
|
|
|
#include "screens.h"
|
2002-10-29 10:45:29 +00:00
|
|
|
#include "font.h"
|
2002-06-16 23:24:22 +00:00
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
#include "sokoban_levels.h"
|
|
|
|
|
2002-06-16 23:24:22 +00:00
|
|
|
#ifdef SIMULATOR
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
2002-09-18 14:08:05 +00:00
|
|
|
#include "lang.h"
|
2002-06-16 23:24:22 +00:00
|
|
|
#define SOKOBAN_TITLE "Sokoban"
|
|
|
|
#define SOKOBAN_TITLE_FONT 2
|
2002-06-20 10:49:15 +00:00
|
|
|
#define NUM_LEVELS sizeof(levels)/320
|
2002-06-16 23:24:22 +00:00
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
static void load_level(int);
|
|
|
|
static void update_screen(void);
|
|
|
|
static bool sokoban_loop(void);
|
|
|
|
|
2002-06-20 10:49:15 +00:00
|
|
|
static char board[16][20];
|
|
|
|
static int current_level=0;
|
|
|
|
static int moves=0;
|
|
|
|
static int row=0;
|
|
|
|
static int col=0;
|
|
|
|
static int boxes_to_go=0;
|
2002-10-19 12:06:16 +00:00
|
|
|
static char current_spot= ' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
static void load_level (int level_to_load) {
|
2002-06-16 23:24:22 +00:00
|
|
|
int a = 0;
|
|
|
|
int b = 0;
|
|
|
|
int c = 0;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-19 14:26:41 +00:00
|
|
|
boxes_to_go = 0;
|
2002-06-16 23:24:22 +00:00
|
|
|
/* load level into board */
|
|
|
|
/* get to the current level in the level array */
|
|
|
|
|
|
|
|
for(b=0 ; b<16 ; b++) {
|
|
|
|
for (c=0 ; c<20 ; c++) {
|
2002-10-19 12:06:16 +00:00
|
|
|
board[b][c] = levels[level_to_load][a]/* - '0'*/;
|
2002-06-16 23:24:22 +00:00
|
|
|
a++;
|
2002-10-19 12:06:16 +00:00
|
|
|
if (board[b][c]=='@') {
|
2002-06-16 23:24:22 +00:00
|
|
|
row = b;
|
|
|
|
col = c;
|
|
|
|
}
|
2002-10-19 12:06:16 +00:00
|
|
|
if (board[b][c]=='.')
|
2002-06-16 23:24:22 +00:00
|
|
|
boxes_to_go++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
static void update_screen(void) {
|
2002-06-16 23:24:22 +00:00
|
|
|
int b = 0;
|
|
|
|
int c = 0;
|
|
|
|
char s[25];
|
|
|
|
|
|
|
|
/* load the board to the screen */
|
|
|
|
for(b=0 ; b<16 ; b++) {
|
|
|
|
for (c=0 ; c<20 ; c++) {
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[b][c] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case 'X': /* this is a black space */
|
2002-08-28 14:22:40 +00:00
|
|
|
lcd_drawrect (c*4, b*4, 4, 4);
|
|
|
|
lcd_drawrect (c*4+1, b*4+1, 2, 2);
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '#': /* this is a wall */
|
2002-06-20 10:49:15 +00:00
|
|
|
lcd_drawpixel (c*4, b*4);
|
|
|
|
lcd_drawpixel (c*4+2, b*4);
|
|
|
|
lcd_drawpixel (c*4+1, b*4+1);
|
|
|
|
lcd_drawpixel (c*4+3, b*4+1);
|
|
|
|
lcd_drawpixel (c*4, b*4+2);
|
|
|
|
lcd_drawpixel (c*4+2, b*4+2);
|
|
|
|
lcd_drawpixel (c*4+1, b*4+3);
|
|
|
|
lcd_drawpixel (c*4+3, b*4+3);
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* this is a home location */
|
2002-08-28 14:22:40 +00:00
|
|
|
lcd_drawrect (c*4+1, b*4+1, 2, 2);
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '$': /* this is a box */
|
2002-08-28 14:22:40 +00:00
|
|
|
lcd_drawrect (c*4, b*4, 4, 4);
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '@': /* this is you */
|
2002-06-20 10:49:15 +00:00
|
|
|
lcd_drawline (c*4+1, b*4, c*4+2, b*4);
|
|
|
|
lcd_drawline (c*4, b*4+1, c*4+3, b*4+1);
|
|
|
|
lcd_drawline (c*4+1, b*4+2, c*4+2, b*4+2);
|
|
|
|
lcd_drawpixel (c*4, b*4+3);
|
|
|
|
lcd_drawpixel (c*4+3, b*4+3);
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '%': /* this is a box on a home spot */
|
2002-08-28 14:22:40 +00:00
|
|
|
lcd_drawrect (c*4, b*4, 4, 4);
|
|
|
|
lcd_drawrect (c*4+1, b*4+1, 2, 2);
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
2002-06-16 23:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
snprintf (s, sizeof(s), "%d", current_level+1);
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy (86, 22, s);
|
2002-06-16 23:24:22 +00:00
|
|
|
snprintf (s, sizeof(s), "%d", moves);
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy (86, 54, s);
|
2002-06-16 23:24:22 +00:00
|
|
|
|
2002-08-28 14:22:40 +00:00
|
|
|
lcd_drawrect (80,0,32,32);
|
|
|
|
lcd_drawrect (80,32,32,64);
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy (81, 10, str(LANG_SOKOBAN_LEVEL));
|
|
|
|
lcd_putsxy (81, 42, str(LANG_SOKOBAN_MOVE));
|
2002-06-16 23:24:22 +00:00
|
|
|
/* print out the screen */
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
static bool sokoban_loop(void)
|
|
|
|
{
|
2002-06-16 23:24:22 +00:00
|
|
|
int ii = 0;
|
|
|
|
moves = 0;
|
|
|
|
current_level = 0;
|
|
|
|
load_level(current_level);
|
|
|
|
update_screen();
|
|
|
|
|
|
|
|
while(1) {
|
2002-06-24 11:02:18 +00:00
|
|
|
bool idle = false;
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( button_get(true) ) {
|
|
|
|
|
|
|
|
case BUTTON_OFF:
|
|
|
|
/* get out of here */
|
2002-09-24 17:22:12 +00:00
|
|
|
return false;
|
2002-06-20 10:49:15 +00:00
|
|
|
|
|
|
|
case BUTTON_F3:
|
|
|
|
/* increase level */
|
|
|
|
boxes_to_go=0;
|
2002-06-24 11:02:18 +00:00
|
|
|
idle=true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_F2:
|
|
|
|
/* same level */
|
|
|
|
load_level(current_level);
|
|
|
|
moves=0;
|
2002-06-24 11:02:18 +00:00
|
|
|
idle=true;
|
2002-06-25 14:43:16 +00:00
|
|
|
load_level(current_level);
|
|
|
|
lcd_clear_display();
|
|
|
|
update_screen();
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
2002-06-19 14:26:41 +00:00
|
|
|
|
2002-06-20 10:49:15 +00:00
|
|
|
case BUTTON_F1:
|
|
|
|
/* previous level */
|
2002-06-24 11:02:18 +00:00
|
|
|
if (current_level)
|
2002-06-20 10:49:15 +00:00
|
|
|
current_level--;
|
|
|
|
load_level(current_level);
|
|
|
|
moves=0;
|
2002-06-24 11:02:18 +00:00
|
|
|
idle=true;
|
2002-06-25 14:43:16 +00:00
|
|
|
load_level(current_level);
|
|
|
|
lcd_clear_display();
|
|
|
|
update_screen();
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
switch ( board[row][col-1] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if it is a blank spot */
|
|
|
|
board[row][col-1]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if it is a home spot */
|
|
|
|
board[row][col-1]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '$':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row][col-2] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if we are going from blank to blank */
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col-2]=board[row][col-1];
|
|
|
|
board[row][col-1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a blank to home */
|
|
|
|
board[row][col-2]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col-1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go--;
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '%':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row][col-2] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* we are going from a home to a blank */
|
|
|
|
board[row][col-2]='$';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col-1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go++;
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a home to home */
|
|
|
|
board[row][col-2]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col-1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
|
|
|
break;
|
2002-06-20 10:49:15 +00:00
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
if (!idle)
|
|
|
|
col--;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_RIGHT: /* if it is a blank spot */
|
|
|
|
switch ( board[row][col+1] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ':
|
|
|
|
board[row][col+1]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if it is a home spot */
|
|
|
|
board[row][col+1]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '$':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row][col+2] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if we are going from blank to blank */
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col+2]=board[row][col+1];
|
|
|
|
board[row][col+1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a blank to home */
|
|
|
|
board[row][col+2]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col+1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go--;
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '%':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row][col+2] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* we are going from a home to a blank */
|
|
|
|
board[row][col+2]='$';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col+1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go++;
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.':
|
|
|
|
board[row][col+2]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col+1]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2002-06-24 11:02:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
|
|
|
break;
|
2002-06-20 10:49:15 +00:00
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
if (!idle)
|
|
|
|
col++;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_UP:
|
|
|
|
switch ( board[row-1][col] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if it is a blank spot */
|
|
|
|
board[row-1][col]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if it is a home spot */
|
|
|
|
board[row-1][col]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '$':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row-2][col] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if we are going from blank to blank */
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row-2][col]=board[row-1][col];
|
|
|
|
board[row-1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a blank to home */
|
|
|
|
board[row-2][col]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row-1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go--;
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '%':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row-2][col] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* we are going from a home to a blank */
|
|
|
|
board[row-2][col]='$';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row-1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go++;
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a home to home */
|
|
|
|
board[row-2][col]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row-1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2002-06-24 11:02:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
|
|
|
break;
|
2002-06-20 10:49:15 +00:00
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
if (!idle)
|
|
|
|
row--;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
switch ( board[row+1][col] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if it is a blank spot */
|
|
|
|
board[row+1][col]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if it is a home spot */
|
|
|
|
board[row+1][col]='@';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '$':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row+2][col] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* if we are going from blank to blank */
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row+2][col]=board[row+1][col];
|
|
|
|
board[row+1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a blank to home */
|
|
|
|
board[row+2][col]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row+1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot=' ';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go--;
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '%':
|
2002-06-20 10:49:15 +00:00
|
|
|
switch ( board[row+2][col] ) {
|
2002-10-19 12:06:16 +00:00
|
|
|
case ' ': /* we are going from a home to a blank */
|
|
|
|
board[row+2][col]='$';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row+1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-20 10:49:15 +00:00
|
|
|
boxes_to_go++;
|
|
|
|
break;
|
|
|
|
|
2002-10-19 12:06:16 +00:00
|
|
|
case '.': /* if we are going from a home to home */
|
|
|
|
board[row+2][col]='%';
|
2002-06-20 10:49:15 +00:00
|
|
|
board[row+1][col]=board[row][col];
|
|
|
|
board[row][col]=current_spot;
|
2002-10-19 12:06:16 +00:00
|
|
|
current_spot='.';
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
idle = true;
|
|
|
|
break;
|
2002-06-20 10:49:15 +00:00
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
if (!idle)
|
|
|
|
row++;
|
|
|
|
break;
|
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
usb_screen();
|
|
|
|
return true;
|
|
|
|
|
2002-06-24 11:02:18 +00:00
|
|
|
default:
|
|
|
|
idle = true;
|
2002-06-20 10:49:15 +00:00
|
|
|
break;
|
2002-06-19 14:26:41 +00:00
|
|
|
}
|
2002-06-24 11:02:18 +00:00
|
|
|
|
|
|
|
if (!idle) {
|
|
|
|
moves++;
|
|
|
|
lcd_clear_display();
|
|
|
|
update_screen();
|
|
|
|
}
|
|
|
|
|
2002-06-16 23:24:22 +00:00
|
|
|
if (boxes_to_go==0) {
|
|
|
|
moves=0;
|
|
|
|
current_level++;
|
|
|
|
if (current_level == NUM_LEVELS) {
|
2002-06-19 14:26:41 +00:00
|
|
|
for(ii=0; ii<30 ; ii++) {
|
|
|
|
lcd_clear_display();
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy(10, 20, str(LANG_SOKOBAN_WIN));
|
2002-06-16 23:24:22 +00:00
|
|
|
lcd_update();
|
2002-06-19 14:26:41 +00:00
|
|
|
lcd_invertrect(0,0,111,63);
|
2002-06-19 14:29:01 +00:00
|
|
|
lcd_update();
|
2002-06-20 10:49:15 +00:00
|
|
|
if ( button_get(false) )
|
2002-09-24 17:22:12 +00:00
|
|
|
return false;
|
2002-06-16 23:24:22 +00:00
|
|
|
}
|
2002-09-24 17:22:12 +00:00
|
|
|
return false;
|
2002-06-16 23:24:22 +00:00
|
|
|
}
|
|
|
|
load_level(current_level);
|
|
|
|
lcd_clear_display();
|
|
|
|
update_screen();
|
|
|
|
}
|
|
|
|
}
|
2002-09-24 17:22:12 +00:00
|
|
|
|
|
|
|
return false;
|
2002-06-16 23:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
bool sokoban(void)
|
2002-06-16 23:24:22 +00:00
|
|
|
{
|
2002-09-24 17:22:12 +00:00
|
|
|
bool result;
|
2002-06-16 23:24:22 +00:00
|
|
|
int w, h;
|
2002-09-24 18:04:15 +00:00
|
|
|
int len;
|
2002-06-16 23:24:22 +00:00
|
|
|
|
2002-10-29 10:45:29 +00:00
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_getstringsize(SOKOBAN_TITLE, &w, &h);
|
2002-06-16 23:24:22 +00:00
|
|
|
|
|
|
|
/* Get horizontel centering for text */
|
2002-09-24 18:04:15 +00:00
|
|
|
len = w;
|
2002-06-16 23:24:22 +00:00
|
|
|
if (len%2 != 0)
|
|
|
|
len = ((len+1)/2)+(w/2);
|
|
|
|
else
|
|
|
|
len /= 2;
|
|
|
|
|
|
|
|
if (h%2 != 0)
|
|
|
|
h = (h/2)+1;
|
|
|
|
else
|
|
|
|
h /= 2;
|
|
|
|
|
|
|
|
lcd_clear_display();
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SOKOBAN_TITLE);
|
2002-06-19 14:26:41 +00:00
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ*2);
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_putsxy( 3,12, str(LANG_SOKOBAN_QUIT));
|
|
|
|
lcd_putsxy( 3,22, str(LANG_SOKOBAN_F1));
|
|
|
|
lcd_putsxy( 3,32, str(LANG_SOKOBAN_F2));
|
|
|
|
lcd_putsxy( 3,42, str(LANG_SOKOBAN_F3));
|
2002-06-16 23:24:22 +00:00
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ*2);
|
|
|
|
lcd_clear_display();
|
2002-09-24 17:22:12 +00:00
|
|
|
result = sokoban_loop();
|
2002-08-23 12:32:52 +00:00
|
|
|
|
2002-10-29 10:45:29 +00:00
|
|
|
lcd_setfont(FONT_UI);
|
|
|
|
|
2002-09-24 17:22:12 +00:00
|
|
|
return result;
|
2002-06-16 23:24:22 +00:00
|
|
|
}
|
2002-08-31 22:55:40 +00:00
|
|
|
|
|
|
|
#endif
|