/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * 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" #include "features.h" #ifdef USE_GAMES #include #include "sokoban.h" #include "lcd.h" #include "button.h" #include "kernel.h" #include "menu.h" #ifdef SIMULATOR #include #endif #include #define SOKOBAN_TITLE "Sokoban" #define SOKOBAN_TITLE_FONT 2 #define NUM_LEVELS sizeof(levels)/320 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; static int current_spot=1; /* 320 boxes per level */ static const char levels[][320] = { "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222000000000" "00000000232000000000" "00000000212222000000" "00000022241432000000" "00000023145222000000" "00000022224200000000" "00000000023200000000" "00000000022200000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000222220000000000" "00000211120000000000" "00000254420222000000" "00000214120232000000" "00000222122232000000" "00000022111132000000" "00000021112112000000" "00000021112222000000" "00000022222000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222220000000" "00000021111122200000" "00000224222111200000" "00000215141141200000" "00000213321412200000" "00000223321112000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000022222000000" "00000022221132000000" "00000021114172000000" "00000021441432000000" "00000022522332000000" "00000002222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222000000000" "00000002512220000000" "00000002141120000000" "00000022212122000000" "00000023212112000000" "00000023411212000000" "00000023111412000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222222200000" "00000002211215200000" "00000002111211200000" "00000002414141200000" "00000002142211200000" "00000222141212200000" "00000233333112000000" "00000222222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222222000000" "00000022211112000000" "00000223142212200000" "00000233414115200000" "00000233141412200000" "00000222222112000000" "00000000002222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222222000000" "00000000211112000000" "00000022244412000000" "00000025143312000000" "00000021433322000000" "00000022221120000000" "00000000022220000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222200000000" "00000000233200000000" "00000002213220000000" "00000002114320000000" "00000022141122000000" "00000021124412000000" "00000021151112000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222220000000" "00000022211520000000" "00000021143122000000" "00000021134312000000" "00000022217412000000" "00000000211122000000" "00000000222220000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222222000000" "00000021121112000000" "00000021433412000000" "00000025437122000000" "00000021433412000000" "00000021121112000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222220000000" "00000002111122200000" "00000002141111200000" "00000222141221200000" "00000233314111200000" "00000233342412200000" "00000222212141200000" "00000000211511200000" "00000000222222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222200000000" "00000021111200000000" "00000021444220000000" "00000021123322200000" "00000022113341200000" "00000002151111200000" "00000002222222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222222200000" "00000002111231200000" "00000022114333200000" "00000021141273200000" "00000221224212200000" "00000211141141200000" "00000211121111200000" "00000222222251200000" "00000000000222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222220000000" "00000023333120000000" "00000222333422200000" "00000211424141200000" "00000214411241200000" "00000211112111200000" "00000222215122200000" "00000000222220000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222222000000" "00000023311112000000" "00000023341452000000" "00000024244422000000" "00000023341412000000" "00000023311112000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000222222220000000" "00000211111120000000" "00000212441120000000" "00000213332120000000" "00000223334122000000" "00000021221412000000" "00000024114112000000" "00000021121152000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222200000000" "00000222111222200000" "00000211141411200000" "00000214111415200000" "00000222442222200000" "00000002113320000000" "00000002333320000000" "00000002222220000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000222222222000000" "00000211171112000000" "00000214343152000000" "00000213434312000000" "00000214343412000000" "00000211171112000000" "00000222222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222222200000" "00000221111111200000" "00000211124241200000" "00000214411343200000" "00000215222333200000" "00000222202222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222220000000" "00000002313320000000" "00000002314320000000" "00000022211422000000" "00000021411412000000" "00000021242212000000" "00000021115112000000" "00000022222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222000000000" "00000021112222000000" "00000221241112000000" "00000214114412000000" "00000212423732000000" "00000211153332000000" "00000222222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000022222000000" "00000022221112200000" "00000021414111200000" "00000025237321200000" "00000021237321200000" "00000021114141200000" "00000022111222200000" "00000002222200000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222220000000" "00000222231122000000" "00000214343112000000" "00000254212412000000" "00000214313112000000" "00000222242412000000" "00000002313112000000" "00000002222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000222222220000" "00000222211113120000" "00000211414143120000" "00000211322223220000" "00000214341415200000" "00000211311112200000" "00000222222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000222222200000000" "00000211111222220000" "00000214137314120000" "00000254371734120000" "00000214137314120000" "00000222222111120000" "00000000002222220000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000222222000000000" "00000211112000000000" "00000214112222000000" "00000214733712000000" "00000217337412000000" "00000222211412000000" "00000000215112000000" "00000000222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000022222200000" "00000022223115200000" "00000021144411200000" "00000023223223200000" "00000021114111200000" "00000021143212200000" "00000022221112000000" "00000000022222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222222200000" "00000023114315200000" "00000021343411200000" "00000022434142200000" "00000021343411200000" "00000023114311200000" "00000022222222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222222000000" "00000002115112000000" "00000002241412000000" "00000002114422000000" "00000002333320000000" "00000002222220000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022220000000000" "00000021122222000000" "00000224122112000000" "00000211454112000000" "00000211122412000000" "00000222322122200000" "00000023334141200000" "00000022331111200000" "00000002222222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222222000000" "00000021123312200000" "00000021431471200000" "00000021145411200000" "00000021741341200000" "00000022133211200000" "00000002222222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222220000000" "00000221171122000000" "00000213131312000000" "00000214171112000000" "00000274474472000000" "00000211171412000000" "00000213135312000000" "00000221171122000000" "00000022222220000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000222222222000000" "00000211134152000000" "00000214171412000000" "00000273337372000000" "00000214471112000000" "00000211131412000000" "00000222222222000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000022222200000" "00000222223111200000" "00000211233221200000" "00000211433111200000" "00000211213212200000" "00002221224211200000" "00002141111441200000" "00002124211211200000" "00002511222222200000" "00002222200000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000002222220000000" "00000002133320000000" "00002222333320000000" "00002112224122200000" "00002141411441200000" "00002514141111200000" "00002112222111200000" "00002222002222200000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000022222222200000" "00000021122111200000" "00000021114111200000" "00000024122214200000" "00000021233321200000" "00000221233321220000" "00000214114114120000" "00000211111215120000" "00000222222222220000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000222222200000" "00000022211111200000" "00000221112121200000" "00000211234441200000" "00000212372122200000" "00000211332120000000" "00000222334122000000" "00000002321412000000" "00000022121252000000" "00000021411412000000" "00000021111222000000" "00000022222200000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000022222222220000" "00000221111111120000" "00000251444141120000" "00000221411414120000" "00000022122221220000" "00000002111141220000" "00000222122414120000" "00000211112111120000" "00000211112222220000" "00000211112200000000" "00000233333200000000" "00000233333200000000" "00000222222200000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000222222220000000" "00000211111120000000" "00000215142120000000" "00000221211120000000" "00000214232120000000" "00000211373420000000" "00000221232120000000" "00000021231122000000" "00000221432112000000" "00000211214112000000" "00000214111222000000" "00000211222200000000" "00000222200000000000" "00000000000000000000", "00000000000000000000" "00000000000222200000" "00000000000251200000" "00000002222211200000" "00002222111111200000" "00002111322212200000" "00002121211112200000" "00002121414231200000" "00002121171121200000" "00002132414121200000" "00002211112121200000" "00000212223111200000" "00000211111222200000" "00000222222200000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000002222200000000" "00000002111220000000" "00000002114120000000" "00000002141520000000" "00000002223120000000" "00000000023220000000" "00000000023120000000" "00000002223120000000" "00000002114120000000" "00000002141120000000" "00000002211220000000" "00000000222200000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000022220000000000" "00000021122222000000" "00000021121112000000" "00000021311212000000" "00000022421132000000" "00000002124212000000" "00000022311312000000" "00000021122112000000" "00000021121172000000" "00000021411412000000" "00000021427152000000" "00000021123222000000" "00000022222200000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000222000000000" "00000000232222220000" "00000022234121120000" "00000023331124120000" "00000023221411120000" "00000223414221220000" "00000234121221200000" "00000232411111200000" "00000234112414200000" "00000231422151200000" "00000234111141200000" "00000231222222200000" "00000222200000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000022220000000" "00000002221122000000" "00000022111112200000" "00000021112133200000" "00000221427243200000" "00000211412143200000" "00000211415143200000" "00000211412143200000" "00000224427243200000" "00000023112133200000" "00000022311112200000" "00000002221122000000" "00000000022220000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000022222222200000" "00000021111111200000" "00000021212221200000" "00000021441121200000" "00000025411121200000" "00000022122121200000" "00000021114141200000" "00000021422121200000" "00000021112421200000" "00000023332111200000" "00000023232422200000" "00000023331120000000" "00000022222220000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000222222220000000" "00000211111320000000" "00000212423322000000" "00000211143332000000" "00000221223432000000" "00000021221122000000" "00000024221120000000" "00000221112420000000" "00000211211120000000" "00000211141222200000" "00000214141115200000" "00000211222111200000" "00000222202222200000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000022220000000000" "00000021122220000000" "00000021141120000000" "00000021232120000000" "00000021212120000000" "00000023434320000000" "00000021212120000000" "00000021232120000000" "00000021144120000000" "00000022151120000000" "00000002112220000000" "00000002222000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00002222220222200000" "00002111122211200000" "00002144112211200000" "00002112141111200000" "00002212214211200000" "00000212333112200000" "00000211333242200000" "00000212333211200000" "00002212122251200000" "00002114141141200000" "00002124222211200000" "00002111200222200000" "00002222200000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000222222222200000" "00000233414173200000" "00000237141433200000" "00000223414172200000" "00000027141432000000" "00000023414132000000" "00000023141432000000" "00000023454172000000" "00000227141432200000" "00000233414173200000" "00000237141433200000" "00000222222222200000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00002222200000000000" "00002111200000000000" "00002411200000000000" "00222114220000000000" "00211414120000000000" "22212122120002222220" "21112122122222113320" "21411411111111113320" "22222122212522113320" "00002111112222222220" "00002222222000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00022222222222200000" "00023311211111222000" "00023311214114112000" "00023311242222112000" "00023311115122112000" "00023311211114122000" "00022222212241412000" "00000214114141412000" "00000211112111112000" "00000222222222222000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000022222222000" "00000000021111152000" "00000000021424122000" "00000000021411420000" "00000000022414120000" "02222222221412122200" "02333311221411411200" "02233311114114111200" "02333311222222222200" "02222222200000000000" "00000000000000000000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000022222222" "00000000000021133332" "02222222222221133332" "02111121141411133332" "02144424114121133332" "02114111114121133332" "02144124141422222222" "02114121111120000000" "02212222222220000000" "02111121111220000000" "02111114111220000000" "02114424411520000000" "02111121111220000000" "02222222222200000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000022222000000" "00000000021112222200" "00000000021242211200" "00000000021111141200" "02222222221222111200" "02333311221411422200" "02333311114144122000" "02333311224114152000" "02222222221141122000" "00000000021414112000" "00000000022212212000" "00000000000211112000" "00000000000222222000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00002222220022200000" "00002331120225220000" "00002331122211120000" "00002331111144120000" "00002331121214120000" "00002332221214120000" "00002222141241120000" "00000002114214120000" "00000002141141120000" "00000002112211120000" "00000002222222220000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000000222220000" "00000222222211122000" "00002212152214412000" "00002111141111112000" "00002114112221112000" "00002221222224222000" "00002141122213320000" "00002141414133320000" "00002111122233320000" "00002144120233320000" "00002112220222220000" "00002222000000000000" "00000000000000000000" "00000000000000000000", "00002222000000000000" "00002112222222222200" "00002111141114141200" "00002142141211411200" "00002114141121111200" "00222142121122221200" "00252414141122111200" "00211114124211121200" "00211141111414141200" "00222221122222222200" "00002111111200000000" "00002333333200000000" "00002333333200000000" "00002333333200000000" "00002222222200000000" "00000000000000000000", "00000000000000000000" "00000000000222222200" "00000000000211333200" "00000002222211333200" "00000002111111313200" "00000002112211333200" "00000002212211333200" "00000022212222222200" "00000021444122000000" "00222221141412222200" "02211124141112111200" "02514114111141141200" "02222221441412222200" "00000021111112000000" "00000022222222000000" "00000000000000000000", "02220022222222222220" "22522221111111211120" "21441114411414133320" "21144421111411233320" "21411121441441233320" "22211121141111233320" "21111121414141233320" "21111222222122233320" "22121121141411233320" "21122121441414223320" "21332121141111112320" "21332121444144412320" "22222121111111212320" "00002122222222212320" "00002111111111112320" "00002222222222222220", "00000000000000000000" "00000000000222200000" "00000022220211200000" "00002221122241200000" "00022111511411200000" "00221141442212200000" "00211242211111200000" "00212141441212220000" "00211141211214122222" "02222111121144121112" "02222122141111111112" "02311112221122222222" "02331332022220000000" "02333232000000000000" "02333332000000000000" "02222222000000000000", "00000000000000000000" "00000000000000000000" "00222222222222222200" "00211111111111111200" "00212122222211111200" "00212114141414211200" "00212111454111221220" "00212124141422233320" "00212111414112233320" "00212224441412233320" "00211111212212233320" "00222221112212233320" "00000022222111112220" "00000000002111112000" "00000000002222222000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00022222222200000000" "00221112211222222000" "22211111211211112220" "21141241211211333120" "21214254221212323120" "21121241121111313120" "21411114121212323120" "21112211224141313120" "21412111211242323120" "22141141114114333120" "02412222221111221120" "02112000022222222220" "02222000000000000000" "00000000000000000000", "00000000222222200000" "00222222211111200000" "00211111214541200000" "00244121112222222220" "00212223333332211120" "00211143333332212120" "00212223333331111120" "02211122221222124220" "02112411121141121200" "02114144411214221200" "02111414122244121200" "02222211111411121200" "00000222122211121200" "00000002111112111200" "00000002222222211200" "00000000000000222200", "00000222222220000000" "00000211121120000000" "00000211411120000000" "00022212411122220000" "00021141122411120000" "00021121514121420000" "00021121111114122220" "00022122224221111120" "00021423333321211120" "00021143377314212220" "00221123333321112000" "00211122212222222000" "00214411211200000000" "00211211111200000000" "00222222111200000000" "00000002222200000000", "00022222000000000000" "00021112200000000000" "00021111200222200000" "00021411222211200000" "00021144141114200000" "00022251241111220000" "00002112211414122000" "00002141122122132000" "00002112422411232000" "00002221114332232000" "00000211112373332000" "00000214412333332000" "00000211222222222000" "00000211200000000000" "00000222200000000000" "00000000000000000000", "00000000000000000000" "00000222222222200000" "00000233112111200000" "00000233111111200000" "00000233112112222000" "00002222222112112200" "00002111111111111200" "00002112112211211200" "00222212211222212200" "00211411222221211200" "00212141141121411200" "00215411411121112200" "00222212212222222000" "00000211112000000000" "00000222222000000000" "00000000000000000000", "00000000000000000000" "00000222222222220000" "00000211311211120000" "00000212311115120000" "02222212233212222000" "22112133222111112220" "21412333111412114120" "21111331221122122120" "22224224214121112120" "00221211112414412120" "00211412121121422120" "00211111111111111120" "00211222222222221120" "00222200000000022220" "00000000000000000000" "00000000000000000000", "00022222200000000000" "00021115222200000000" "02222214111200000000" "02111221111222200000" "02141211221111200000" "02141211222221200000" "02214114111121200000" "02214141222121200000" "02212114112121200000" "02212124211121200000" "02212221112121222222" "02114112222121233332" "02111141111411133232" "02222411421411133332" "02111111121122133332" "02222222222222222222", "00000222222222200000" "02222211111111222200" "02111112111411251200" "02122222224222211222" "02121111221211241332" "02121411411211211232" "02121411211111241332" "02121122212211111232" "02122211211211241332" "02121111214222211232" "02124111411411271332" "02111141214141211232" "02222142221111271332" "00002111144122233332" "00002111111220222222" "00002222222200000000", "00000000000000000000" "00022222222200000000" "00021111111200000000" "00021111111222200000" "00022122221211200000" "00022125221111200000" "00021444141144200000" "00021121221411200000" "00021121221141222200" "00022221144414211200" "00002111221113333200" "00002121112123313200" "00002111212122333200" "00002222214112333200" "00000000221112222200" "00000000022222000000", "02222220000022220000" "02111122222221122222" "02111421121141121112" "02114114114121414112" "02241411121521411112" "02114122222222222122" "02121112333333321420" "02122112133333321120" "02121114333333334120" "02121412333313321120" "02114142222422221420" "02141112221411141122" "02141111141411411112" "02212222221412222212" "02111111111211111112" "02222222222222222222", "00000000000000000000" "00000222222200000000" "00000211211222200000" "02222214241211220000" "02331211211211122220" "02331214241211421120" "02311211111241121120" "02331114211214111120" "02335211241241121120" "02331214211111421120" "02331211244241121122" "02331214211211424112" "02331211211211121112" "02231222211222221112" "00222200222200022222" "00000000000000000000", "02222222222222220000" "02333333333311322220" "02333333333344321120" "02222222222241211122" "02111111411411111412" "02212222111211412112" "02111111211122112122" "02114211212211222122" "02141242221111222122" "02221141211211222122" "00221111412212112122" "00214112114114141112" "00211411424441121112" "00211211411111122222" "00215221121111120000" "00222222222222220000", "02222000000000000000" "02112222222222222200" "02112111332333333200" "02112121222221333200" "02242111133333333200" "02111224222222112222" "02141211111222222512" "02241214111222222112" "02114124442211111112" "02111111211112424222" "02122221244444111120" "02121111411111211120" "02121112212211111222" "02122222242222221412" "02111111112000021112" "02222222222000022222", "00000000000000000000" "00000000000000000000" "00022222220000000000" "00021121122222000000" "00221121123332220000" "00211421123331120000" "00214124413331120000" "00211421123331320000" "00211121422222222000" "00224111111141412000" "00221121144121112000" "00022222211224452000" "00000000211111122000" "00000000222222220000" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "02222222222222222200" "02333111211112111220" "22333331142212124120" "23333332114112111120" "23333332112112121120" "22222222214114141120" "00211111242241224220" "02211141111214111120" "02112212221211224120" "02141441111141141120" "02141111422412222220" "02222222115122000000" "00000002222220000000" "00000000000000000000", "00000000000222220000" "00000002222211120000" "00000022141141122220" "00222221411414122320" "00211111114411223320" "00211222222122233120" "00221211211112333120" "00214111211112333120" "00251241221222233320" "00222211414411223320" "00000221141411433320" "00000021441141211320" "00000021114141122220" "00000022222211120000" "00000000000222220000" "00000000000000000000", "00000000000000000000" "02222200000000000000" "02111220000000000000" "02141122222222200000" "02212121111111222222" "02212111424251121112" "02112111111412111412" "02112221222222222122" "02112213373333312122" "02212217373373712122" "02142222222222122412" "02114111411411114112" "02112111211121112112" "02222222222222222222" "00000000000000000000" "00000000000000000000", "00000000000000000000" "00000000222222222220" "00000000211121111120" "02222200211111414120" "02111222221422121220" "02141221112122141120" "02141154412122444120" "02212221112122111120" "02212111222122222420" "02212111114112333320" "02112221221412333322" "02141114121112334312" "02112214121122333312" "02222211122222233322" "00000222220000222220" "00000000000000000000", "00022220000000000000" "00021122222222200000" "00221122112111200000" "00211421454111222200" "00241141121414211220" "02211422124141111120" "02112112121114441120" "02141111411422122220" "02141412421121120000" "02211222112224120000" "00211233331111120000" "00222233333322220000" "00002333322220000000" "00002333220000000000" "00002333200000000000" "00002222200000000000", "00000000000000000000" "00000000002222000000" "00000022222112000000" "00000221111142000000" "00002214112212220000" "00002541412141120000" "00002222122111420000" "00000233332414120000" "00000233332111420000" "00000233331144122000" "00000233312141112000" "00000222222414112000" "00000000002111222000" "00000000002412220000" "00000000002112000000" "00000000002222000000", "00000000000000000000" "00002222222222220000" "00002211111221120000" "00002211141114120000" "00002222122144120000" "00002111412111120000" "00002144412122220000" "00002111212141220000" "00002112112114120000" "00002142142111120000" "00002111332122220000" "00002222331412520000" "00002333332142120000" "00002233332114120000" "00002223322111120000" "00002222222222220000", "00000000000000000000" "00002222222220000000" "00002333311122000000" "00002323211412200000" "00022333321215220000" "00021333321121122000" "00021111124122412000" "00022122211411112000" "00002411414142112000" "00002121141412212000" "00002112221122112000" "00002111122122122000" "00002114121141120000" "00002224141112220000" "00000021122222000000" "00000022220000000000", "22222222222202222220" "21112111121222333320" "21114421115113333320" "21112122211121333320" "22122122211211333320" "02141411111212122220" "02114142211211111120" "22221211222212122120" "21121241112212111120" "21411411212212111220" "21214141111212111200" "21141221221212222200" "21441111144112000000" "22122122214112000000" "02111120211112000000" "02222220222222000000", "00000000000002222200" "02222200222222111200" "02111222211414141200" "02141112212212211220" "02111414111114114120" "02221411221221111122" "00021222221222224412" "00224222221522111112" "00214112224222141122" "00214112111222112220" "00214414121114412000" "00211111211122112000" "00222222233132222000" "00000233333333320000" "00000233333333320000" "00000222222222220000", "00000000000000000000" "22222222222000000000" "23333331112222222220" "23333331112112211120" "23322214111141111120" "23331414121122211120" "23332422222111121120" "22211112111241124120" "00211441414114221120" "00211411124241224120" "00222122121111221120" "00021141412212222220" "00021111411411200000" "00022111212111200000" "00002222252222200000" "00000000222000000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000002222000000" "00002222222152000000" "00002111114112000000" "00002111422142000000" "00002242333212000000" "00000214333112000000" "00000212313212200000" "00000211121241200000" "00000241141111200000" "00000211222222200000" "00000222200000000000" "00000000000000000000" "00000000000000000000", "00000000000000222222" "00222222222222233332" "02211122111112233332" "02114422114152233332" "02111111441421133332" "02114122144121213332" "02114122141121133332" "02212222212221223222" "02211141141221113112" "02142221121222221222" "02111411121111111200" "02114124141422211200" "02144421411120222200" "02111121144120000000" "02222221112220000000" "00000022222000000000", "00000022222222222200" "00000021111111111220" "00000021121244141120" "00000024124211221520" "00000221221214121220" "00000211141241121200" "00000211121411121200" "00000221414111221200" "00000211211221141200" "00000211112214421200" "00222222441112111200" "00233332112222222200" "00232333122000000000" "00233331112000000000" "00233331112000000000" "00222222222000000000", "00000000000222220000" "00000000002211122000" "00000000022111112000" "00000000221144112000" "00000002214411412000" "00000002141111412000" "22220002111441222220" "21122222222122111120" "23111111111111444520" "23212222222122111220" "23212222222312414220" "23333333333312111120" "22222222222222114120" "00000000000002211220" "00000000000000222200" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000022222222000000" "00022221111112222220" "00021111221414111520" "00021221224241414220" "02221333333211441220" "02111333333211211120" "02121333333241141120" "02121333333144214120" "02114222122241141220" "02221141141141141200" "00021141141141141200" "00022222211122222200" "00000000222220000000" "00000000000000000000", "00000000000000000000" "00000000000000000000" "00000000222222200000" "00002222211211222200" "00002111211141111200" "02222124412212211200" "22111111212112212220" "21122214241141141120" "23331111212211211120" "23332111151212221220" "23332112221141141120" "22222222022111211120" "00000000002222222220" "00000000000000000000" "00000000000000000000" "00000000000000000000", "02222200000000000000" "02111200000000000000" "02121222222200000000" "02111111452222220000" "02141224122211120000" "02122221411114120000" "02122222121124122220" "22112222122411111120" "21142114112122122120" "21111111112123332120" "22222211222113331120" "00000222202123332120" "00000000002122212120" "00000000002111111120" "00000000002222222220" "00000000000000000000", "00000000000000000000" "00022222022220000000" "00023332021122220000" "00023332221141120000" "00023333221411422200" "00022333322111411200" "00022233312214141200" "00021221111211411200" "00021122121222122220" "00021412124114111120" "00021141514111141120" "00021112141441412220" "00021122222211222000" "00021220000222200000" "00022200000000000000" "00000000000000000000", "00022222222220000000" "00021111111122220000" "00021222222121122000" "00021214141411412000" "00021111111241112000" "00022241144211222000" "00000211221214220000" "00000224211141520000" "00000021141412220000" "00000021211141120000" "00000021221112120000" "00000221122222120000" "00000211111111120000" "00000233333332220000" "00000233333332000000" "00000222222222000000", "00000000000000000000" "00000000000000000000" "00000000000000000000" "00000000002222000000" "00222222222112200000" "02211411111141222220" "02111221221112233320" "02124414144242233320" "02121111511211133320" "02114212224411133320" "02141144114122333320" "02224111111122222220" "00021122222220000000" "00022220000000000000" "00000000000000000000" "00000000000000000000", "00000222222222000000" "00000273727372000000" "00000237373732000000" "00000273737372000000" "00000237373732000000" "00000273737372000000" "00000222111222000000" "00000002111200000000" "00022222212222220000" "00021111111111120000" "00021414141414120000" "00022141414141220000" "00002414141414200000" "00002111454111200000" "00002112222211200000" "00002222000222200000", "00000000222200000000" "00000000211220000000" "00000000211122000000" "00000000214412200000" "00000022241141220000" "00022221111411120000" "02221121222221120000" "02111121233334120000" "02121114133332120000" "02114121237332120000" "02221122221222120000" "00022221541122422000" "00000022214111112000" "00000000211221112000" "00000000222222222000" "00000000000000000000", "00000022222222222200" "00000223311111111200" "00002233714111141200" "00022337321212412200" "00023373212121411200" "22223332112111121200" "21122121111111111200" "21541412221121212200" "21411141112121112000" "22244111212121212000" "00211141112121222220" "00214212222211111120" "00241112000211121120" "00211222000221111120" "00211200000021111220" "00222200000022222200", "22222222222222222220" "21111112221111211120" "21224141121441214120" "23213134121233212320" "23222232121212212120" "21111212111212112120" "21141212122212122120" "21121212123412121120" "21443212122112122120" "24121212112122112120" "21321212212121122120" "21111211212121221120" "22111221212121214320" "22212221432143214320" "22222221112111211520" "00000022222222222220" }; void load_level (int level_to_load) { int a = 0; int b = 0; int c = 0; current_spot=1; boxes_to_go = 0; /* 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++) { board[b][c] = levels[level_to_load][a] - '0'; a++; if (board[b][c]==5) { row = b; col = c; } if (board[b][c]==3) boxes_to_go++; } } return; } void update_screen(void) { 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++) { switch ( board[b][c] ) { case 0: /* this is a black space */ lcd_drawrect (c*4, b*4, 4, 4); lcd_drawrect (c*4+1, b*4+1, 2, 2); break; case 2: /* this is a wall */ 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; case 3: /* this is a home location */ lcd_drawrect (c*4+1, b*4+1, 2, 2); break; case 4: /* this is a box */ lcd_drawrect (c*4, b*4, 4, 4); break; case 5: /* this is you */ 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; case 7: /* this is a box on a home spot */ lcd_drawrect (c*4, b*4, 4, 4); lcd_drawrect (c*4+1, b*4+1, 2, 2); break; } } } snprintf (s, sizeof(s), "%d", current_level+1); lcd_putsxy (86, 22, s, 0); snprintf (s, sizeof(s), "%d", moves); lcd_putsxy (86, 54, s, 0); lcd_drawrect (80,0,32,32); lcd_drawrect (80,32,32,64); lcd_putsxy (81, 10, "Level", 0); lcd_putsxy (81, 42, "Moves", 0); /* print out the screen */ lcd_update(); } void sokoban_loop(void) { int ii = 0; moves = 0; current_level = 0; load_level(current_level); update_screen(); while(1) { bool idle = false; switch ( button_get(true) ) { case BUTTON_OFF: /* get out of here */ return; case BUTTON_F3: /* increase level */ boxes_to_go=0; idle=true; break; case BUTTON_F2: /* same level */ load_level(current_level); moves=0; idle=true; load_level(current_level); lcd_clear_display(); update_screen(); break; case BUTTON_F1: /* previous level */ if (current_level) current_level--; load_level(current_level); moves=0; idle=true; load_level(current_level); lcd_clear_display(); update_screen(); break; case BUTTON_LEFT: switch ( board[row][col-1] ) { case 1: /* if it is a blank spot */ board[row][col-1]=5; board[row][col]=current_spot; current_spot=1; break; case 3: /* if it is a home spot */ board[row][col-1]=5; board[row][col]=current_spot; current_spot=3; break; case 4: switch ( board[row][col-2] ) { case 1: /* if we are going from blank to blank */ board[row][col-2]=board[row][col-1]; board[row][col-1]=board[row][col]; board[row][col]=current_spot; current_spot=1; break; case 3: /* if we are going from a blank to home */ board[row][col-2]=7; board[row][col-1]=board[row][col]; board[row][col]=current_spot; current_spot=1; boxes_to_go--; break; default: idle = true; break; } break; case 7: switch ( board[row][col-2] ) { case 1: /* we are going from a home to a blank */ board[row][col-2]=4; board[row][col-1]=board[row][col]; board[row][col]=current_spot; current_spot=3; boxes_to_go++; break; case 3: /* if we are going from a home to home */ board[row][col-2]=7; board[row][col-1]=board[row][col]; board[row][col]=current_spot; current_spot=3; break; default: idle = true; break; } break; default: idle = true; break; } if (!idle) col--; break; case BUTTON_RIGHT: /* if it is a blank spot */ switch ( board[row][col+1] ) { case 1: board[row][col+1]=5; board[row][col]=current_spot; current_spot=1; break; case 3: /* if it is a home spot */ board[row][col+1]=5; board[row][col]=current_spot; current_spot=3; break; case 4: switch ( board[row][col+2] ) { case 1: /* if we are going from blank to blank */ board[row][col+2]=board[row][col+1]; board[row][col+1]=board[row][col]; board[row][col]=current_spot; current_spot=1; break; case 3: /* if we are going from a blank to home */ board[row][col+2]=7; board[row][col+1]=board[row][col]; board[row][col]=current_spot; current_spot=1; boxes_to_go--; break; default: idle = true; break; } break; case 7: switch ( board[row][col+2] ) { case 1: /* we are going from a home to a blank */ board[row][col+2]=4; board[row][col+1]=board[row][col]; board[row][col]=current_spot; current_spot=3; boxes_to_go++; break; case 3: board[row][col+2]=7; board[row][col+1]=board[row][col]; board[row][col]=current_spot; current_spot=3; break; default: idle = true; break; } break; default: idle = true; break; } if (!idle) col++; break; case BUTTON_UP: switch ( board[row-1][col] ) { case 1: /* if it is a blank spot */ board[row-1][col]=5; board[row][col]=current_spot; current_spot=1; break; case 3: /* if it is a home spot */ board[row-1][col]=5; board[row][col]=current_spot; current_spot=3; break; case 4: switch ( board[row-2][col] ) { case 1: /* if we are going from blank to blank */ board[row-2][col]=board[row-1][col]; board[row-1][col]=board[row][col]; board[row][col]=current_spot; current_spot=1; break; case 3: /* if we are going from a blank to home */ board[row-2][col]=7; board[row-1][col]=board[row][col]; board[row][col]=current_spot; current_spot=1; boxes_to_go--; break; default: idle = true; break; } break; case 7: switch ( board[row-2][col] ) { case 1: /* we are going from a home to a blank */ board[row-2][col]=4; board[row-1][col]=board[row][col]; board[row][col]=current_spot; current_spot=3; boxes_to_go++; break; case 3: /* if we are going from a home to home */ board[row-2][col]=7; board[row-1][col]=board[row][col]; board[row][col]=current_spot; current_spot=3; break; default: idle = true; break; } break; default: idle = true; break; } if (!idle) row--; break; case BUTTON_DOWN: switch ( board[row+1][col] ) { case 1: /* if it is a blank spot */ board[row+1][col]=5; board[row][col]=current_spot; current_spot=1; break; case 3: /* if it is a home spot */ board[row+1][col]=5; board[row][col]=current_spot; current_spot=3; break; case 4: switch ( board[row+2][col] ) { case 1: /* if we are going from blank to blank */ board[row+2][col]=board[row+1][col]; board[row+1][col]=board[row][col]; board[row][col]=current_spot; current_spot=1; break; case 3: /* if we are going from a blank to home */ board[row+2][col]=7; board[row+1][col]=board[row][col]; board[row][col]=current_spot; current_spot=1; boxes_to_go--; break; default: idle = true; break; } break; case 7: switch ( board[row+2][col] ) { case 1: /* we are going from a home to a blank */ board[row+2][col]=4; board[row+1][col]=board[row][col]; board[row][col]=current_spot; current_spot=3; boxes_to_go++; break; case 3: /* if we are going from a home to home */ board[row+2][col]=7; board[row+1][col]=board[row][col]; board[row][col]=current_spot; current_spot=3; break; default: idle = true; break; } break; default: idle = true; break; } if (!idle) row++; break; default: idle = true; break; } if (!idle) { moves++; lcd_clear_display(); update_screen(); } if (boxes_to_go==0) { moves=0; current_level++; if (current_level == NUM_LEVELS) { for(ii=0; ii<30 ; ii++) { lcd_clear_display(); lcd_putsxy(10, 20, "YOU WIN!!", 2); lcd_update(); lcd_invertrect(0,0,111,63); lcd_update(); if ( button_get(false) ) return; } return; } load_level(current_level); lcd_clear_display(); update_screen(); } } } Menu sokoban(void) { int w, h; int len = strlen(SOKOBAN_TITLE); lcd_getfontsize(SOKOBAN_TITLE_FONT, &w, &h); /* Get horizontel centering for text */ len *= w; 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(); lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SOKOBAN_TITLE, SOKOBAN_TITLE_FONT); lcd_update(); sleep(HZ*2); lcd_clear_display(); lcd_putsxy( 3,12, "[Off] to stop", 0); lcd_putsxy( 3,22, "[F1] - level",0); lcd_putsxy( 3,32, "[F2] same level",0); lcd_putsxy( 3,42, "[F3] + level",0); lcd_update(); sleep(HZ*2); lcd_clear_display(); sokoban_loop(); return MENU_OK; } #endif