2004-08-17 06:50:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-06-26 19:35:29 +00:00
|
|
|
* Copyright (C) 2004-2005 dionoea (Antoine Cellerier)
|
2004-08-17 06:50:14 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
Solitaire by dionoea
|
|
|
|
|
|
|
|
use arrows to move the cursor
|
2004-08-21 23:05:36 +00:00
|
|
|
use ON to select cards, move cards, reveal hidden cards, ...
|
2004-08-17 06:50:14 +00:00
|
|
|
use PLAY to move a card from the remains' stack to the top of the cursor
|
2005-10-06 12:42:19 +00:00
|
|
|
use F1 to put card under cursor on one of the 4 final stacks
|
2004-08-17 06:50:14 +00:00
|
|
|
use F2 to un-select card if a card was selected, else draw 3 new cards
|
|
|
|
out of the remains' stack
|
2005-10-06 12:42:19 +00:00
|
|
|
use F3 to put card on top of the remains' stack on one of the 4 final stacks
|
2004-08-17 06:50:14 +00:00
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
|
|
|
/* here is a global api struct pointer. while not strictly necessary,
|
|
|
|
it's nice not to have to pass the api pointer in all function calls
|
|
|
|
in the plugin */
|
|
|
|
static struct plugin_api* rb;
|
|
|
|
|
|
|
|
#define min(a,b) (a<b?a:b)
|
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define SOL_QUIT BUTTON_OFF
|
|
|
|
#define SOL_UP BUTTON_UP
|
|
|
|
#define SOL_DOWN BUTTON_DOWN
|
|
|
|
#define SOL_LEFT BUTTON_LEFT
|
|
|
|
#define SOL_RIGHT BUTTON_RIGHT
|
|
|
|
#define SOL_MOVE BUTTON_ON
|
|
|
|
#define SOL_DRAW BUTTON_F2
|
|
|
|
#define SOL_REM2CUR BUTTON_PLAY
|
|
|
|
#define SOL_CUR2STACK BUTTON_F1
|
|
|
|
#define SOL_REM2STACK BUTTON_F3
|
|
|
|
#define SOL_MENU_RUN BUTTON_RIGHT
|
|
|
|
#define SOL_MENU_RUN2 BUTTON_PLAY
|
|
|
|
#define SOL_MENU_INFO BUTTON_F1
|
|
|
|
#define SOL_MENU_INFO2 BUTTON_F2
|
|
|
|
#define SOL_MENU_INFO3 BUTTON_F3
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
#define SOL_QUIT BUTTON_OFF
|
|
|
|
#define SOL_UP_PRE BUTTON_UP
|
|
|
|
#define SOL_UP (BUTTON_UP | BUTTON_REL)
|
|
|
|
#define SOL_DOWN_PRE BUTTON_DOWN
|
|
|
|
#define SOL_DOWN (BUTTON_DOWN | BUTTON_REL)
|
|
|
|
#define SOL_LEFT_PRE BUTTON_LEFT
|
|
|
|
#define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
|
|
|
|
#define SOL_RIGHT_PRE BUTTON_RIGHT
|
|
|
|
#define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
|
|
|
|
#define SOL_MOVE_PRE BUTTON_MENU
|
|
|
|
#define SOL_MOVE (BUTTON_MENU | BUTTON_REL)
|
|
|
|
#define SOL_DRAW_PRE BUTTON_MENU
|
|
|
|
#define SOL_DRAW (BUTTON_MENU | BUTTON_REPEAT)
|
|
|
|
#define SOL_REM2CUR_PRE BUTTON_LEFT
|
|
|
|
#define SOL_REM2CUR (BUTTON_LEFT | BUTTON_REPEAT)
|
|
|
|
#define SOL_CUR2STACK_PRE BUTTON_RIGHT
|
|
|
|
#define SOL_CUR2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
|
|
|
|
#define SOL_REM2STACK_PRE BUTTON_UP
|
|
|
|
#define SOL_REM2STACK (BUTTON_UP | BUTTON_REPEAT)
|
|
|
|
#define SOL_MENU_RUN BUTTON_RIGHT
|
|
|
|
#define SOL_MENU_INFO BUTTON_MENU
|
|
|
|
|
2005-06-29 12:47:24 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2005-02-04 12:41:09 +00:00
|
|
|
#define SOL_QUIT BUTTON_OFF
|
|
|
|
#define SOL_UP BUTTON_UP
|
|
|
|
#define SOL_DOWN BUTTON_DOWN
|
|
|
|
#define SOL_LEFT BUTTON_LEFT
|
|
|
|
#define SOL_RIGHT BUTTON_RIGHT
|
2005-02-16 02:08:16 +00:00
|
|
|
#define SOL_MOVE_PRE BUTTON_SELECT
|
|
|
|
#define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
|
|
|
|
#define SOL_DRAW BUTTON_MODE
|
|
|
|
#define SOL_REM2CUR (BUTTON_LEFT | BUTTON_ON)
|
|
|
|
#define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
|
|
|
|
#define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_ON)
|
|
|
|
#define SOL_MENU_RUN BUTTON_SELECT
|
|
|
|
#define SOL_MENU_RUN2 BUTTON_RIGHT
|
|
|
|
#define SOL_MENU_INFO BUTTON_MODE
|
2005-02-04 12:41:09 +00:00
|
|
|
#define SOL_MENU_INFO2 BUTTON_REC
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* common help definitions */
|
|
|
|
#define HELP_SOL_UP "UP: Move the cursor up in the column."
|
|
|
|
#define HELP_SOL_DOWN "DOWN: Move the cursor down in the column."
|
|
|
|
#define HELP_SOL_LEFT "LEFT: Move the cursor to the previous column."
|
|
|
|
#define HELP_SOL_RIGHT "RIGHT: Move the cursor to the next column."
|
|
|
|
|
|
|
|
/* variable help definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define HELP_SOL_MOVE "ON: Select cards, Move cards, reveal hidden cards ..."
|
|
|
|
#define HELP_SOL_DRAW "F2: Un-select a card if it was selected. Else, draw 3 new cards out of the remains' stack."
|
|
|
|
#define HELP_SOL_REM2CUR "PLAY: Put the card on top of the remains' stack on top of the cursor."
|
2005-10-06 12:42:19 +00:00
|
|
|
#define HELP_SOL_CUR2STACK "F1: Put the card under the cursor on one of the 4 final stacks."
|
|
|
|
#define HELP_SOL_REM2STACK "F3: Put the card on top of the remains' stack on one of the 4 final stacks."
|
2004-10-20 23:54:53 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2004-12-26 14:56:05 +00:00
|
|
|
#define HELP_SOL_MOVE "MODE: Select cards, Move cards, reveal hidden cards ..."
|
|
|
|
#define HELP_SOL_DRAW "MODE..: Un-select a card if it was selected. Else, draw 3 new cards out of the remains' stack."
|
2004-10-20 23:54:53 +00:00
|
|
|
#define HELP_SOL_REM2CUR "LEFT..: Put the card on top of the remains' stack on top of the cursor."
|
2005-10-06 12:42:19 +00:00
|
|
|
#define HELP_SOL_CUR2STACK "RIGHT..: Put the card under the cursor on one of the 4 final stacks."
|
|
|
|
#define HELP_SOL_REM2STACK "UP..: Put the card on top of the remains' stack on one of the 4 final stacks."
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2005-06-29 12:47:24 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2005-02-16 02:08:16 +00:00
|
|
|
#define HELP_SOL_MOVE "SELECT: Select cards, Move cards, reveal hidden cards ..."
|
|
|
|
#define HELP_SOL_DRAW "REC: Un-select a card if it was selected. Else, draw 3 new cards out of the remains' stack."
|
|
|
|
#define HELP_SOL_REM2CUR "PLAY+LEFT: Put the card on top of the remains' stack on top of the cursor."
|
2005-10-06 12:42:19 +00:00
|
|
|
#define HELP_SOL_CUR2STACK "SELECT..: Put the card under the cursor on one of the 4 final stacks."
|
|
|
|
#define HELP_SOL_REM2STACK "PLAY+RIGHT: Put the card on top of the remains' stack on one of the 4 final stacks."
|
2005-02-16 02:08:16 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
#if LCD_DEPTH>1
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
static const unsigned struct rgb colors[4] = {
|
|
|
|
{ 0, 0, 0 }, { LCD_MAX_RED, 0, 0 }, { 0, 0, 0 }, { LCD_MAX_RED, 0, 0 }
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
static const int colors[4] = { LCD_BLACK, LCD_MAX_LEVEL/2, LCD_BLACK, LCD_MAX_LEVEL/2 };
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const unsigned char suits[4][8] = {
|
2004-08-18 12:06:10 +00:00
|
|
|
/* Spades */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x18, /* ...O.... */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x3e, /* .OOOOO.. */
|
|
|
|
0x1c, /* .OOOOO.. */
|
|
|
|
0x18, /* ...O.... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* Hearts */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x0c, /* ..O.O... */
|
|
|
|
0x1e, /* .OOOOO.. */
|
|
|
|
0x3c, /* .OOOOO.. */
|
|
|
|
0x1e, /* ..OOO... */
|
|
|
|
0x0c, /* ...O.... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* Clubs */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x18, /* ..OOO... */
|
|
|
|
0x0a, /* ...O.... */
|
|
|
|
0x3e, /* .OOOOO.. */
|
|
|
|
0x0a, /* .O.O.O.. */
|
|
|
|
0x18, /* ...O.... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* Diamonds */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x08, /* ...O.... */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x3e, /* .OOOOO.. */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x08, /* ...O.... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00} /* ........ */
|
2004-08-17 06:50:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char numbers[13][8] = {
|
2004-08-18 12:06:10 +00:00
|
|
|
/* Ace */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x38, /* ...O.... */
|
|
|
|
0x14, /* ..O.O... */
|
|
|
|
0x12, /* .O...O.. */
|
|
|
|
0x14, /* .OOOOO.. */
|
|
|
|
0x38, /* .O...O.. */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 2 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x24, /* ..OOO... */
|
|
|
|
0x32, /* .O...O.. */
|
|
|
|
0x32, /* ....O... */
|
|
|
|
0x2a, /* ..OO.... */
|
|
|
|
0x24, /* .OOOOO.. */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 3 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x22, /* .OOOO... */
|
|
|
|
0x2a, /* .....O.. */
|
|
|
|
0x2a, /* ..OOO... */
|
|
|
|
0x2a, /* .....O.. */
|
|
|
|
0x14, /* .OOOO... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 4 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x10, /* ....O... */
|
|
|
|
0x18, /* ...O.... */
|
|
|
|
0x34, /* ..O..... */
|
|
|
|
0x12, /* .OOOOO.. */
|
|
|
|
0x10, /* ...O.... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 5 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x2e, /* .OOOOO.. */
|
|
|
|
0x2a, /* .O...... */
|
|
|
|
0x2a, /* .OOOO... */
|
|
|
|
0x2a, /* .....O.. */
|
|
|
|
0x12, /* .OOOO... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 6 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x2a, /* .O...... */
|
|
|
|
0x2a, /* .OOOO... */
|
|
|
|
0x2a, /* .O...O.. */
|
|
|
|
0x10, /* ..OOO... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 7 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x22, /* .OOOOO.. */
|
|
|
|
0x12, /* ....O... */
|
|
|
|
0x0a, /* ...O.... */
|
|
|
|
0x06, /* ..O..... */
|
|
|
|
0x02, /* .O...... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 8 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x14, /* ..OOO... */
|
|
|
|
0x2a, /* .O...O.. */
|
|
|
|
0x2a, /* ..OOO... */
|
|
|
|
0x2a, /* .O...O.. */
|
|
|
|
0x14, /* ..OOO... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 9 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x04, /* ..OOO... */
|
|
|
|
0x2a, /* .O...O.. */
|
|
|
|
0x2a, /* ..OOOO.. */
|
|
|
|
0x2a, /* .....O.. */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* 10 */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x3e, /* .O..O... */
|
|
|
|
0x00, /* .O.O.O.. */
|
|
|
|
0x1c, /* .O.O.O.. */
|
|
|
|
0x22, /* .O.O.O.. */
|
|
|
|
0x1c, /* .O..O... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* Jack */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x12, /* .OOOOO.. */
|
|
|
|
0x22, /* ...O.... */
|
|
|
|
0x1e, /* ...O.... */
|
|
|
|
0x02, /* .O.O.... */
|
|
|
|
0x02, /* ..O..... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* Queen */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x22, /* .O...O.. */
|
|
|
|
0x32, /* .O...O.. */
|
|
|
|
0x22, /* .O.O.O.. */
|
|
|
|
0x1c, /* ..OOO... */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00},/* ........ */
|
|
|
|
/* King */
|
|
|
|
{0x00, /* ........ */
|
|
|
|
0x3e, /* .O...O.. */
|
|
|
|
0x08, /* .O..O... */
|
|
|
|
0x08, /* .OOO.... */
|
|
|
|
0x14, /* .O..O... */
|
|
|
|
0x22, /* .O...O.. */
|
|
|
|
0x00, /* ........ */
|
|
|
|
0x00} /* ........ */
|
2004-08-17 06:50:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NOT_A_CARD 255
|
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
/* number of cards per suit */
|
|
|
|
#define CARDS_PER_SUIT 13
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
/* number of suits */
|
|
|
|
#define SUITS 4
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* number of columns */
|
2004-08-17 06:50:14 +00:00
|
|
|
#define COL_NUM 7
|
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* pseudo column numbers to be used for cursor coordinates */
|
2005-10-06 12:42:19 +00:00
|
|
|
/* columns COL_NUM t COL_NUM + SUITS - 1 correspond to the final stacks */
|
2004-08-21 23:05:36 +00:00
|
|
|
#define STACKS_COL COL_NUM
|
2005-10-06 12:42:19 +00:00
|
|
|
/* column COL_NUM + SUITS corresponds to the remains' stack */
|
|
|
|
#define REM_COL (STACKS_COL + SUITS)
|
2004-08-21 23:05:36 +00:00
|
|
|
|
|
|
|
#define NOT_A_COL 255
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* number of cards that are drawn on the remains' stack (by pressing F2) */
|
2004-08-17 06:50:14 +00:00
|
|
|
#define CARDS_PER_DRAW 3
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* size of a card on the screen */
|
2004-08-17 06:50:14 +00:00
|
|
|
#define CARD_WIDTH 14
|
|
|
|
#define CARD_HEIGHT 10
|
|
|
|
|
|
|
|
typedef struct card {
|
2005-10-06 12:42:19 +00:00
|
|
|
unsigned char suit : 2;
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char num : 4;
|
|
|
|
unsigned char known : 1;
|
2004-08-18 12:06:10 +00:00
|
|
|
unsigned char used : 1;/* this is what is used when dealing cards */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char next;
|
|
|
|
} card;
|
|
|
|
|
|
|
|
unsigned char next_random_card(card *deck){
|
|
|
|
unsigned char i,r;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
r = rb->rand()%(SUITS * CARDS_PER_SUIT)+1;
|
2004-08-17 06:50:14 +00:00
|
|
|
i = 0;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
while(r>0){
|
2005-10-06 12:42:19 +00:00
|
|
|
i = (i + 1)%(SUITS * CARDS_PER_SUIT);
|
2004-08-17 06:50:14 +00:00
|
|
|
if(!deck[i].used) r--;
|
|
|
|
}
|
|
|
|
|
|
|
|
deck[i].used = 1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
#define HELP_QUIT 0
|
|
|
|
#define HELP_USB 1
|
2004-08-21 23:05:36 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
/* help for the not so intuitive interface */
|
|
|
|
int solitaire_help(void){
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
int button;
|
|
|
|
int lastbutton = BUTTON_NONE;
|
2004-08-17 06:50:14 +00:00
|
|
|
|
|
|
|
while(1){
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
rb->lcd_clear_display();
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
rb->lcd_putsxy(0, 0, "Press a key to see");
|
|
|
|
rb->lcd_putsxy(0, 7, "it's role.");
|
|
|
|
rb->lcd_putsxy(0, 21, "Press OFF to");
|
|
|
|
rb->lcd_putsxy(0, 28, "return to menu.");
|
|
|
|
rb->lcd_putsxy(0, 42, "All actions can");
|
|
|
|
rb->lcd_putsxy(0, 49, "be done using");
|
|
|
|
rb->lcd_putsxy(0, 56, "arrows, ON and F2.");
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2004-12-26 14:56:05 +00:00
|
|
|
rb->lcd_putsxy(0, 0, "Press a key short");
|
|
|
|
rb->lcd_putsxy(0, 7, "or long to see it's");
|
|
|
|
rb->lcd_putsxy(0, 21, "role. Press OFF to");
|
2004-10-20 23:54:53 +00:00
|
|
|
rb->lcd_putsxy(0, 28, "return to menu.");
|
|
|
|
rb->lcd_putsxy(0, 42, "All actions can be");
|
2004-12-26 14:56:05 +00:00
|
|
|
rb->lcd_putsxy(0, 49, "done using arrows,");
|
|
|
|
rb->lcd_putsxy(0, 56, "short & long MODE.");
|
2005-02-16 02:08:16 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H100_PAD
|
|
|
|
rb->lcd_putsxy(20, 8, "Press a key or key");
|
|
|
|
rb->lcd_putsxy(20, 16, "combo to see it's");
|
|
|
|
rb->lcd_putsxy(20, 24, "role. Press STOP to");
|
|
|
|
rb->lcd_putsxy(20, 32, "return to menu.");
|
|
|
|
rb->lcd_putsxy(20, 48, "All actions can be");
|
|
|
|
rb->lcd_putsxy(20, 56, "done using the");
|
|
|
|
rb->lcd_putsxy(20, 64, "joystick and RECORD.");
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rb->lcd_update();
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
button = rb->button_get(true);
|
|
|
|
switch(button){
|
|
|
|
case SOL_UP:
|
|
|
|
#ifdef SOL_UP_PRE
|
|
|
|
if(lastbutton != SOL_UP_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_UP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_DOWN:
|
|
|
|
#ifdef SOL_DOWN_PRE
|
|
|
|
if(lastbutton != SOL_DOWN_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_DOWN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_LEFT:
|
|
|
|
#ifdef SOL_LEFT_PRE
|
|
|
|
if(lastbutton != SOL_LEFT_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_LEFT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_RIGHT:
|
|
|
|
#ifdef SOL_RIGHT_PRE
|
|
|
|
if(lastbutton != SOL_RIGHT_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_RIGHT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_MOVE:
|
|
|
|
#ifdef SOL_MOVE_PRE
|
|
|
|
if(lastbutton != SOL_MOVE_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_MOVE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_DRAW:
|
|
|
|
#ifdef SOL_DRAW_PRE
|
|
|
|
if(lastbutton != SOL_DRAW_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_DRAW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_CUR2STACK:
|
|
|
|
#ifdef SOL_CUR2STACK_PRE
|
|
|
|
if(lastbutton != SOL_CUR2STACK_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_CUR2STACK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_REM2STACK:
|
|
|
|
#ifdef SOL_REM2STACK_PRE
|
|
|
|
if(lastbutton != SOL_REM2STACK_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_REM2STACK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_REM2CUR:
|
|
|
|
#ifdef SOL_REM2CUR_PRE
|
|
|
|
if(lastbutton != SOL_REM2CUR_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
rb->splash(HZ*2, true, HELP_SOL_REM2CUR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_QUIT:
|
|
|
|
return HELP_QUIT;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
default:
|
|
|
|
if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
return HELP_USB;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-10-20 23:54:53 +00:00
|
|
|
if(button != BUTTON_NONE)
|
|
|
|
lastbutton = button;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* menu return codes */
|
2004-08-17 06:50:14 +00:00
|
|
|
#define MENU_RESUME 0
|
|
|
|
#define MENU_RESTART 1
|
|
|
|
#define MENU_HELP 2
|
|
|
|
#define MENU_QUIT 3
|
2004-10-20 23:54:53 +00:00
|
|
|
#define MENU_USB 4
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* menu item number */
|
2004-08-17 06:50:14 +00:00
|
|
|
#define MENU_LENGTH 4
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* different menu behaviors */
|
2004-08-17 06:50:14 +00:00
|
|
|
#define MENU_BEFOREGAME 0
|
|
|
|
#define MENU_DURINGGAME 1
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the menu */
|
|
|
|
/* text displayed changes depending on the 'when' parameter */
|
2005-06-09 21:19:38 +00:00
|
|
|
int solitaire_menu(unsigned char when)
|
|
|
|
{
|
2005-06-26 19:35:29 +00:00
|
|
|
static char menu[2][MENU_LENGTH][13] =
|
2004-08-18 12:06:10 +00:00
|
|
|
{ { "Start Game",
|
|
|
|
"",
|
|
|
|
"Help",
|
|
|
|
"Quit" },
|
|
|
|
{ "Resume Game",
|
|
|
|
"Restart Game",
|
|
|
|
"Help",
|
|
|
|
"Quit"}
|
|
|
|
};
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
int i;
|
|
|
|
int cursor=0;
|
2004-10-20 23:54:53 +00:00
|
|
|
int button;
|
2005-06-09 21:19:38 +00:00
|
|
|
int fh;
|
|
|
|
|
|
|
|
rb->lcd_getstringsize("A", NULL, &fh);
|
|
|
|
fh++;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
if(when!=MENU_BEFOREGAME && when!=MENU_DURINGGAME)
|
|
|
|
when = MENU_DURINGGAME;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
while(1){
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
rb->lcd_putsxy(20, 1, "Solitaire");
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
for(i = 0; i<MENU_LENGTH; i++){
|
2005-06-09 21:19:38 +00:00
|
|
|
rb->lcd_putsxy(1, 17+fh*i, menu[when][i]);
|
2005-06-24 22:33:21 +00:00
|
|
|
if(cursor == i) {
|
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
rb->lcd_fillrect(0,17+fh*i, LCD_WIDTH, fh);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
button = rb->button_get(true);
|
|
|
|
switch(button){
|
2004-08-17 06:50:14 +00:00
|
|
|
case BUTTON_UP:
|
|
|
|
cursor = (cursor + MENU_LENGTH - 1)%MENU_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
cursor = (cursor + 1)%MENU_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
return MENU_RESUME;
|
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_MENU_RUN:
|
|
|
|
#ifdef SOL_MENU_RUN2
|
|
|
|
case SOL_MENU_RUN2:
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
switch(cursor){
|
|
|
|
case MENU_RESUME:
|
|
|
|
case MENU_RESTART:
|
|
|
|
case MENU_QUIT:
|
|
|
|
return cursor;
|
|
|
|
|
|
|
|
case MENU_HELP:
|
2004-10-20 23:54:53 +00:00
|
|
|
if(solitaire_help() == HELP_USB)
|
|
|
|
return MENU_USB;
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_MENU_INFO:
|
|
|
|
#if defined(SOL_MENU_INFO2) && defined(SOL_MENU_INFO3)
|
|
|
|
case SOL_MENU_INFO2:
|
|
|
|
case SOL_MENU_INFO3:
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
rb->splash(HZ, true, "Solitaire for Rockbox by dionoea");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_OFF:
|
|
|
|
return MENU_QUIT;
|
|
|
|
|
|
|
|
default:
|
2004-10-20 23:54:53 +00:00
|
|
|
if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
return MENU_USB;
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* player's cursor */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char cur_card;
|
2004-08-18 12:06:10 +00:00
|
|
|
/* player's cursor column num */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char cur_col;
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* selected card */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char sel_card;
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the deck */
|
2005-10-06 12:42:19 +00:00
|
|
|
card deck[SUITS * CARDS_PER_SUIT];
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the remaining cards */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char rem;
|
|
|
|
unsigned char cur_rem;
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the 7 game columns */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char cols[COL_NUM];
|
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
/* the 4 final stacks */
|
|
|
|
unsigned char stacks[SUITS];
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* initialize the game */
|
2004-08-17 06:50:14 +00:00
|
|
|
void solitaire_init(void){
|
|
|
|
unsigned char c;
|
|
|
|
int i,j;
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* init deck */
|
2005-10-06 12:42:19 +00:00
|
|
|
for(i=0;i<SUITS;i++){
|
|
|
|
for(j=0;j<CARDS_PER_SUIT;j++){
|
|
|
|
deck[i*CARDS_PER_SUIT+j].suit = i;
|
|
|
|
deck[i*CARDS_PER_SUIT+j].num = j;
|
|
|
|
deck[i*CARDS_PER_SUIT+j].known = 1;
|
|
|
|
deck[i*CARDS_PER_SUIT+j].used = 0;
|
|
|
|
deck[i*CARDS_PER_SUIT+j].next = NOT_A_CARD;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* deal the cards ... */
|
|
|
|
/* ... in the columns */
|
2004-08-17 06:50:14 +00:00
|
|
|
for(i=0; i<COL_NUM; i++){
|
|
|
|
c = NOT_A_CARD;
|
|
|
|
for(j=0; j<=i; j++){
|
|
|
|
if(c == NOT_A_CARD){
|
|
|
|
cols[i] = next_random_card(deck);
|
|
|
|
c = cols[i];
|
|
|
|
} else {
|
|
|
|
deck[c].next = next_random_card(deck);
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
if(j<i) deck[c].known = 0;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* ... shuffle what's left of the deck */
|
2004-08-17 06:50:14 +00:00
|
|
|
rem = next_random_card(deck);
|
|
|
|
c = rem;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
for(i=1; i<SUITS * CARDS_PER_SUIT - COL_NUM * (COL_NUM + 1)/2; i++){
|
2004-08-17 06:50:14 +00:00
|
|
|
deck[c].next = next_random_card(deck);
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* we now finished dealing the cards. The game can start ! (at last) */
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* init the stack */
|
2005-10-06 12:42:19 +00:00
|
|
|
for(i = 0; i<SUITS; i++){
|
2004-08-17 06:50:14 +00:00
|
|
|
stacks[i] = NOT_A_CARD;
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the cursor starts on upper left card */
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_card = cols[0];
|
|
|
|
cur_col = 0;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* no card is selected */
|
2004-08-17 06:50:14 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* init the remainder */
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_rem = NOT_A_CARD;
|
2005-06-26 19:35:29 +00:00
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* find the column number in which 'card' can be found */
|
|
|
|
unsigned char find_card_col(unsigned char card){
|
|
|
|
int i;
|
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
if(card == NOT_A_CARD) return NOT_A_COL;
|
|
|
|
|
|
|
|
for(i=0; i<COL_NUM; i++){
|
|
|
|
c = cols[i];
|
|
|
|
while(c!=NOT_A_CARD){
|
|
|
|
if(c == card) return i;
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
for(i=0; i<SUITS; i++){
|
2004-08-21 23:05:36 +00:00
|
|
|
c = stacks[i];
|
|
|
|
while(c!=NOT_A_CARD){
|
|
|
|
if(c == card) return STACKS_COL + i;
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return REM_COL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the card preceding 'card' */
|
|
|
|
/* if it doesn't exist, return NOT_A_CARD */
|
|
|
|
unsigned char find_prev_card(unsigned char card){
|
|
|
|
int i;
|
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
for(i=0; i<SUITS*CARDS_PER_SUIT; i++){
|
2004-08-21 23:05:36 +00:00
|
|
|
if(deck[i].next == card) return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOT_A_CARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the last card of a given column */
|
|
|
|
unsigned char find_last_card(unsigned char col){
|
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
if(col < COL_NUM){
|
|
|
|
c = cols[col];
|
|
|
|
} else if(col < REM_COL){
|
|
|
|
c = stacks[col - STACKS_COL];
|
|
|
|
} else {
|
|
|
|
c = rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c == NOT_A_CARD)
|
|
|
|
return c;
|
|
|
|
else {
|
|
|
|
while(deck[c].next != NOT_A_CARD){
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MOVE_OK 0
|
|
|
|
#define MOVE_NOT_OK 1
|
|
|
|
unsigned char move_card(unsigned char dest_col, unsigned char src_card){
|
|
|
|
/* the column on which to take src_card */
|
|
|
|
unsigned char src_col;
|
|
|
|
|
|
|
|
/* the last card of dest_col */
|
|
|
|
unsigned char dest_card;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* the card under src_card */
|
|
|
|
unsigned char src_card_prev;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* you can't move no card (at least, it doesn't have any consequence) */
|
|
|
|
if(src_card == NOT_A_CARD) return MOVE_NOT_OK;
|
|
|
|
/* you can't put a card back on the remains' stack */
|
|
|
|
if(dest_col == REM_COL) return MOVE_NOT_OK;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
src_col = find_card_col(src_card);
|
|
|
|
dest_card = find_last_card(dest_col);
|
|
|
|
src_card_prev = find_prev_card(src_card);
|
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
/* you can't move more than one card at a time from the final stack */
|
2004-08-21 23:05:36 +00:00
|
|
|
/* to the rest of the game */
|
|
|
|
if(src_col >= COL_NUM && src_col < REM_COL
|
|
|
|
&& deck[src_card].next != NOT_A_CARD){
|
|
|
|
return MOVE_NOT_OK;
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* if we (that means dest) are on one of the 7 columns ... */
|
|
|
|
if(dest_col < COL_NUM){
|
|
|
|
/* ... check is we are on an empty color and that the src is a king */
|
|
|
|
if(dest_card == NOT_A_CARD
|
2005-10-06 12:42:19 +00:00
|
|
|
&& deck[src_card].num == CARDS_PER_SUIT - 1){
|
2004-08-21 23:05:36 +00:00
|
|
|
/* this is a winning combination */
|
|
|
|
cols[dest_col] = src_card;
|
|
|
|
}
|
2005-10-06 12:42:19 +00:00
|
|
|
/* ... or check if the cards follow one another and have same suit */
|
|
|
|
else if((deck[dest_card].suit + deck[src_card].suit)%2==1
|
2004-08-21 23:05:36 +00:00
|
|
|
&& deck[dest_card].num == deck[src_card].num + 1){
|
|
|
|
/* this is a winning combination */
|
|
|
|
deck[dest_card].next = src_card;
|
|
|
|
}
|
|
|
|
/* ... or, humpf, well that's not good news */
|
|
|
|
else {
|
|
|
|
/* this is not a winning combination */
|
|
|
|
return MOVE_NOT_OK;
|
|
|
|
}
|
|
|
|
}
|
2005-10-06 12:42:19 +00:00
|
|
|
/* if we are on one of the 4 final stacks ... */
|
2004-08-21 23:05:36 +00:00
|
|
|
else if(dest_col < REM_COL){
|
|
|
|
/* ... check if we are on an empty stack, that the src is an
|
2005-10-06 12:42:19 +00:00
|
|
|
* ace and that this is the good final stack */
|
2004-08-21 23:05:36 +00:00
|
|
|
if(dest_card == NOT_A_CARD
|
|
|
|
&& deck[src_card].num == 0
|
2005-10-06 12:42:19 +00:00
|
|
|
&& deck[src_card].suit == dest_col - STACKS_COL){
|
2004-08-21 23:05:36 +00:00
|
|
|
/* this is a winning combination */
|
|
|
|
stacks[dest_col - STACKS_COL] = src_card;
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
/* ... or check if the cards follow one another, have the same
|
2005-10-06 12:42:19 +00:00
|
|
|
* suit and {that src has no .next element or is from the remains'
|
2004-08-21 23:05:36 +00:00
|
|
|
* stack} */
|
2005-10-06 12:42:19 +00:00
|
|
|
else if(deck[dest_card].suit == deck[src_card].suit
|
2004-08-21 23:05:36 +00:00
|
|
|
&& deck[dest_card].num + 1 == deck[src_card].num
|
|
|
|
&& (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) ){
|
|
|
|
/* this is a winning combination */
|
|
|
|
deck[dest_card].next = src_card;
|
|
|
|
}
|
|
|
|
/* ... or, well that's not good news */
|
|
|
|
else {
|
|
|
|
/* this is not a winnong combination */
|
|
|
|
return MOVE_NOT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if we are on the remains' stack */
|
|
|
|
else {
|
|
|
|
/* you can't move a card back to the remains' stack */
|
|
|
|
return MOVE_NOT_OK;
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* if the src card is from the remains' stack, we don't want to take
|
|
|
|
* the following cards */
|
|
|
|
if(src_col == REM_COL){
|
|
|
|
/* if src card is the first card from the stack */
|
|
|
|
if(src_card_prev == NOT_A_CARD){
|
|
|
|
rem = deck[src_card].next;
|
|
|
|
}
|
|
|
|
/* if src card is not the first card from the stack */
|
|
|
|
else {
|
|
|
|
deck[src_card_prev].next = deck[src_card].next;
|
|
|
|
}
|
|
|
|
cur_rem = src_card_prev;
|
|
|
|
deck[src_card].next = NOT_A_CARD;
|
|
|
|
}
|
|
|
|
/* if the src card is from somewhere else, just take everything */
|
|
|
|
else {
|
|
|
|
if(src_card_prev == NOT_A_CARD){
|
|
|
|
if(src_col < COL_NUM){
|
|
|
|
cols[src_col] = NOT_A_CARD;
|
|
|
|
} else {
|
|
|
|
stacks[src_col - STACKS_COL] = NOT_A_CARD;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deck[src_card_prev].next = NOT_A_CARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tada ! */
|
|
|
|
return MOVE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SOLITAIRE_WIN 0
|
|
|
|
#define SOLITAIRE_QUIT 1
|
2004-10-20 23:54:53 +00:00
|
|
|
#define SOLITAIRE_USB 2
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2005-06-26 20:12:56 +00:00
|
|
|
#if ( LCD_WIDTH > ( CARD_WIDTH * 8 ) )
|
|
|
|
# define BIG_SCREEN 1
|
|
|
|
#else
|
|
|
|
# define BIG_SCREEN 0
|
|
|
|
#endif
|
|
|
|
#define LCD_WIDTH2 (LCD_WIDTH - BIG_SCREEN)
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the game */
|
2004-08-21 23:05:36 +00:00
|
|
|
int solitaire(void){
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
int i,j;
|
2004-10-20 23:54:53 +00:00
|
|
|
int button, lastbutton = 0;
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char c;
|
|
|
|
int biggest_col_length;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->srand( *rb->current_tick );
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
switch(solitaire_menu(MENU_BEFOREGAME)) {
|
|
|
|
case MENU_QUIT:
|
|
|
|
return SOLITAIRE_QUIT;
|
|
|
|
|
|
|
|
case MENU_USB:
|
|
|
|
return SOLITAIRE_USB;
|
|
|
|
}
|
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
solitaire_init();
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
while(true){
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* get the biggest column length so that display can be "optimized" */
|
2004-08-17 06:50:14 +00:00
|
|
|
biggest_col_length = 0;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
for(i=0;i<COL_NUM;i++){
|
|
|
|
j = 0;
|
|
|
|
c = cols[i];
|
|
|
|
while(c != NOT_A_CARD){
|
|
|
|
j++;
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
if(j>biggest_col_length) biggest_col_length = j;
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* check if there are cards remaining in the game. */
|
|
|
|
/* if there aren't any, that means you won :) */
|
2004-08-17 06:50:14 +00:00
|
|
|
if(biggest_col_length == 0 && rem == NOT_A_CARD){
|
|
|
|
rb->splash(HZ*2, true, "You Won :)");
|
2004-08-21 23:05:36 +00:00
|
|
|
return SOLITAIRE_WIN;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw the columns */
|
2004-08-17 06:50:14 +00:00
|
|
|
for(i=0;i<COL_NUM;i++){
|
|
|
|
c = cols[i];
|
|
|
|
j = 0;
|
|
|
|
while(true){
|
2004-08-21 23:05:36 +00:00
|
|
|
if(c==NOT_A_CARD) {
|
|
|
|
/* draw the cursor on empty columns */
|
|
|
|
if(cur_col == i){
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
rb->lcd_fillrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+2, 2, CARD_WIDTH-3, CARD_HEIGHT-1);
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-18 12:06:10 +00:00
|
|
|
/* clear the card's spot */
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
|
|
|
rb->lcd_fillrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM, j+1, CARD_WIDTH, CARD_HEIGHT-1);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2004-08-18 12:06:10 +00:00
|
|
|
/* known card */
|
2004-08-21 23:05:36 +00:00
|
|
|
if(deck[c].known){
|
2005-10-06 12:42:19 +00:00
|
|
|
#if LCD_DEPTH>1
|
|
|
|
rb->lcd_set_foreground(colors[deck[c].suit]);
|
|
|
|
#endif
|
2005-07-06 22:58:02 +00:00
|
|
|
rb->lcd_mono_bitmap(numbers[deck[c].num], i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j, 8, 8);
|
2005-10-06 12:42:19 +00:00
|
|
|
rb->lcd_mono_bitmap(suits[deck[c].suit], i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+7, j, 8, 8);
|
|
|
|
#if LCD_DEPTH>1
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw top line of the card */
|
2004-08-21 23:05:36 +00:00
|
|
|
rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,j,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH-1,j);
|
2004-08-18 12:06:10 +00:00
|
|
|
/* selected card */
|
2004-08-17 06:50:14 +00:00
|
|
|
if(c == sel_card && sel_card != NOT_A_CARD){
|
2004-08-21 23:05:36 +00:00
|
|
|
rb->lcd_drawrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j+1, CARD_WIDTH-1, CARD_HEIGHT-1);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-18 12:06:10 +00:00
|
|
|
/* cursor (or not) */
|
2004-08-17 06:50:14 +00:00
|
|
|
if(c == cur_card){
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
rb->lcd_fillrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j+1, CARD_WIDTH-1, CARD_HEIGHT-1);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2004-08-18 12:06:10 +00:00
|
|
|
/* go to the next card */
|
2004-08-17 06:50:14 +00:00
|
|
|
c = deck[c].next;
|
2004-08-21 23:05:36 +00:00
|
|
|
if(c == NOT_A_CARD) break;
|
2004-08-17 06:50:14 +00:00
|
|
|
j += CARD_HEIGHT - 2;
|
2004-08-21 23:05:36 +00:00
|
|
|
} else {
|
2004-08-18 12:06:10 +00:00
|
|
|
/* go to the next card */
|
2004-08-17 06:50:14 +00:00
|
|
|
c = deck[c].next;
|
2004-08-21 23:05:36 +00:00
|
|
|
if(c == NOT_A_CARD) break;
|
|
|
|
j += min(CARD_HEIGHT - 2, (LCD_HEIGHT - CARD_HEIGHT)/biggest_col_length);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cols[i]!=NOT_A_CARD){
|
|
|
|
/* draw line to the left of the column */
|
|
|
|
rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,j+CARD_HEIGHT-1);
|
|
|
|
/* draw line to the right of the column */
|
|
|
|
rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH,1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH,j+CARD_HEIGHT-1);
|
|
|
|
/* draw bottom of the last card */
|
|
|
|
rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,j+CARD_HEIGHT,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH-1,j+CARD_HEIGHT);
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw the stacks */
|
2005-10-06 12:42:19 +00:00
|
|
|
for(i=0; i<SUITS; i++){
|
2004-08-17 06:50:14 +00:00
|
|
|
c = stacks[i];
|
|
|
|
if(c!=NOT_A_CARD){
|
|
|
|
while(deck[c].next != NOT_A_CARD){
|
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
}
|
2005-10-06 12:42:19 +00:00
|
|
|
#if LCD_DEPTH>1
|
|
|
|
rb->lcd_set_foreground(colors[i]);
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
if(c != NOT_A_CARD) {
|
2005-07-06 22:58:02 +00:00
|
|
|
rb->lcd_mono_bitmap(numbers[deck[c].num], LCD_WIDTH2 - CARD_WIDTH+1, i*CARD_HEIGHT, 8, 8);
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
2005-10-06 12:42:19 +00:00
|
|
|
rb->lcd_mono_bitmap(suits[i], LCD_WIDTH2 - CARD_WIDTH+7, i*CARD_HEIGHT, 8, 8);
|
|
|
|
#if LCD_DEPTH>1
|
|
|
|
rb->lcd_set_foreground(colors[deck[c].suit]);
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
/* draw a selected card */
|
|
|
|
if(c != NOT_A_CARD) {
|
|
|
|
if(sel_card == c){
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->lcd_drawrect(LCD_WIDTH2 - CARD_WIDTH+1, i*CARD_HEIGHT + 1, CARD_WIDTH-1, CARD_HEIGHT-1);
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->lcd_drawline(LCD_WIDTH2 - CARD_WIDTH+1, i*CARD_HEIGHT,LCD_WIDTH2 - 1,i*CARD_HEIGHT);
|
|
|
|
rb->lcd_drawline(LCD_WIDTH2 - CARD_WIDTH,i*CARD_HEIGHT+1,LCD_WIDTH2 - CARD_WIDTH,(i+1)*CARD_HEIGHT-1);
|
|
|
|
rb->lcd_drawline(LCD_WIDTH2 - CARD_WIDTH+1,(i+1)*CARD_HEIGHT,LCD_WIDTH2 - 1,(i+1)*CARD_HEIGHT);
|
|
|
|
#if BIG_SCREEN
|
|
|
|
rb->lcd_drawline(LCD_WIDTH2,i*CARD_HEIGHT+1,LCD_WIDTH2,(i+1)*CARD_HEIGHT-1);
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
/* draw the cursor on one of the stacks */
|
|
|
|
if(cur_col == STACKS_COL + i){
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->lcd_fillrect(LCD_WIDTH2 - CARD_WIDTH+1, i*CARD_HEIGHT + 1, CARD_WIDTH-1, CARD_HEIGHT-1);
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw the remains */
|
2004-08-21 23:05:36 +00:00
|
|
|
if(rem != NOT_A_CARD) {
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->lcd_drawline(LCD_WIDTH2 - CARD_WIDTH+1,LCD_HEIGHT-CARD_HEIGHT-1,LCD_WIDTH2 - 1,LCD_HEIGHT-CARD_HEIGHT-1);
|
|
|
|
rb->lcd_drawline(LCD_WIDTH2 - CARD_WIDTH,LCD_HEIGHT-CARD_HEIGHT,LCD_WIDTH2 - CARD_WIDTH,LCD_HEIGHT-2);
|
|
|
|
rb->lcd_drawline(LCD_WIDTH2 - CARD_WIDTH+1,LCD_HEIGHT-1,LCD_WIDTH2 - 1,LCD_HEIGHT-1);
|
|
|
|
#if BIG_SCREEN
|
|
|
|
rb->lcd_drawline(LCD_WIDTH2,LCD_HEIGHT-CARD_HEIGHT,LCD_WIDTH2,LCD_HEIGHT-2);
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_rem != NOT_A_CARD){
|
2005-10-06 12:42:19 +00:00
|
|
|
#if LCD_DEPTH>1
|
|
|
|
rb->lcd_set_foreground(colors[deck[cur_rem].suit]);
|
|
|
|
#endif
|
2005-07-06 22:58:02 +00:00
|
|
|
rb->lcd_mono_bitmap(numbers[deck[cur_rem].num], LCD_WIDTH2 - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT, 8, 8);
|
2005-10-06 12:42:19 +00:00
|
|
|
rb->lcd_mono_bitmap(suits[deck[cur_rem].suit], LCD_WIDTH2 - CARD_WIDTH+7, LCD_HEIGHT-CARD_HEIGHT, 8, 8);
|
2005-06-24 22:33:21 +00:00
|
|
|
/* draw a selected card */
|
2005-10-06 12:42:19 +00:00
|
|
|
#if LCD_DEPTH>1
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
#endif
|
2005-06-24 22:33:21 +00:00
|
|
|
if(sel_card == cur_rem){
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->lcd_drawrect(LCD_WIDTH2 - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT,CARD_WIDTH-1, CARD_HEIGHT-1);
|
2005-06-24 22:33:21 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
/* draw the cursor */
|
|
|
|
if(cur_col == REM_COL){
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->lcd_fillrect(LCD_WIDTH2 - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT,CARD_WIDTH-1, CARD_HEIGHT-1);
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
|
|
|
|
rb->lcd_update();
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* what to do when a key is pressed ... */
|
2004-10-20 23:54:53 +00:00
|
|
|
button = rb->button_get(true);
|
|
|
|
switch(button){
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* move cursor to the last card of the previous column */
|
2005-10-06 12:42:19 +00:00
|
|
|
/* or to the previous final stack */
|
2004-08-21 23:05:36 +00:00
|
|
|
/* or to the remains stack */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_RIGHT:
|
|
|
|
#ifdef SOL_RIGHT_PRE
|
|
|
|
if(lastbutton != SOL_RIGHT_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col >= COL_NUM){
|
|
|
|
cur_col = 0;
|
|
|
|
} else if(cur_col == COL_NUM - 1){
|
|
|
|
cur_col = REM_COL;
|
|
|
|
} else {
|
|
|
|
cur_col = (cur_col+1)%(REM_COL+1);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col == REM_COL){
|
|
|
|
cur_card = cur_rem;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur_card = find_last_card(cur_col);
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* move cursor to the last card of the next column */
|
2005-10-06 12:42:19 +00:00
|
|
|
/* or to the next final stack */
|
2004-08-21 23:05:36 +00:00
|
|
|
/* or to the remains stack */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_LEFT:
|
|
|
|
#ifdef SOL_LEFT_PRE
|
|
|
|
if(lastbutton != SOL_LEFT_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col == 0){
|
|
|
|
cur_col = REM_COL;
|
|
|
|
} else if(cur_col >= COL_NUM) {
|
|
|
|
cur_col = COL_NUM - 1;
|
|
|
|
} else {
|
|
|
|
cur_col = (cur_col + REM_COL)%(REM_COL+1);
|
|
|
|
}
|
|
|
|
if(cur_col == REM_COL){
|
|
|
|
cur_card = cur_rem;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_card = find_last_card(cur_col);
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* move cursor to card that's bellow */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_DOWN:
|
|
|
|
#ifdef SOL_DOWN_PRE
|
|
|
|
if(lastbutton != SOL_DOWN_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col >= COL_NUM) {
|
2005-10-06 12:42:19 +00:00
|
|
|
cur_col = (cur_col - COL_NUM + 1)%(SUITS + 1) + COL_NUM;
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col == REM_COL){
|
|
|
|
cur_card = cur_rem;
|
|
|
|
} else {
|
|
|
|
cur_card = find_last_card(cur_col);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
if(cur_card == NOT_A_CARD) break;
|
|
|
|
if(deck[cur_card].next != NOT_A_CARD){
|
|
|
|
cur_card = deck[cur_card].next;
|
|
|
|
} else {
|
|
|
|
cur_card = cols[cur_col];
|
2004-08-21 23:05:36 +00:00
|
|
|
while(deck[cur_card].known == 0
|
|
|
|
&& deck[cur_card].next != NOT_A_CARD){
|
|
|
|
cur_card = deck[cur_card].next;
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* move cursor to card that's above */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_UP:
|
|
|
|
#ifdef SOL_UP_PRE
|
|
|
|
if(lastbutton != SOL_UP_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col >= COL_NUM) {
|
2005-10-06 12:42:19 +00:00
|
|
|
cur_col = (cur_col - COL_NUM + SUITS)%(SUITS + 1) + COL_NUM;
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_col == REM_COL){
|
|
|
|
cur_card = cur_rem;
|
|
|
|
} else {
|
|
|
|
cur_card = find_last_card(cur_col);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_card == NOT_A_CARD) break;
|
|
|
|
do{
|
|
|
|
cur_card = find_prev_card(cur_card);
|
|
|
|
if(cur_card == NOT_A_CARD){
|
|
|
|
cur_card = find_last_card(cur_col);
|
|
|
|
}
|
|
|
|
} while (deck[cur_card].next != NOT_A_CARD
|
|
|
|
&& deck[cur_card].known == 0);
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* Try to put card under cursor on one of the stacks */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_CUR2STACK:
|
|
|
|
#ifdef SOL_CUR2STACK_PRE
|
|
|
|
if(lastbutton != SOL_CUR2STACK_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
if(cur_card != NOT_A_CARD){
|
2005-10-06 12:42:19 +00:00
|
|
|
move_card(deck[cur_card].suit + STACKS_COL, cur_card);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* Move cards arround, Uncover cards, ... */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_MOVE:
|
|
|
|
#ifdef SOL_MOVE_PRE
|
|
|
|
if(lastbutton != SOL_MOVE_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
if(sel_card == NOT_A_CARD) {
|
2004-08-21 23:05:36 +00:00
|
|
|
if(cur_card != NOT_A_CARD){
|
|
|
|
/* reveal a hidden card */
|
|
|
|
if(deck[cur_card].next == NOT_A_CARD && deck[cur_card].known==0){
|
|
|
|
deck[cur_card].known = 1;
|
|
|
|
/* select a card */
|
|
|
|
} else {
|
|
|
|
sel_card = cur_card;
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
/* unselect card or try putting card on one of the 4 stacks */
|
2004-08-17 06:50:14 +00:00
|
|
|
} else if(sel_card == cur_card) {
|
2005-10-06 12:42:19 +00:00
|
|
|
move_card(deck[sel_card].suit + COL_NUM, sel_card);
|
2004-08-17 06:50:14 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
2004-08-21 23:05:36 +00:00
|
|
|
/* try moving cards */
|
|
|
|
} else {
|
|
|
|
if(move_card(cur_col, sel_card) == MOVE_OK){
|
2004-08-17 06:50:14 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* If the card on the top of the remains can be put where */
|
|
|
|
/* the cursor is, go ahead */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_REM2CUR:
|
|
|
|
#ifdef SOL_REM2CUR_PRE
|
|
|
|
if(lastbutton != SOL_REM2CUR_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-21 23:05:36 +00:00
|
|
|
move_card(cur_col, cur_rem);
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* If the card on top of the remains can be put on one */
|
|
|
|
/* of the stacks, do so */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_REM2STACK:
|
|
|
|
#ifdef SOL_REM2STACK_PRE
|
|
|
|
if(lastbutton != SOL_REM2STACK_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
if(cur_rem != NOT_A_CARD){
|
2005-10-06 12:42:19 +00:00
|
|
|
move_card(deck[cur_rem].suit + COL_NUM, cur_rem);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
break;
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* unselect selected card or ... */
|
|
|
|
/* draw new cards from the remains of the deck */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_DRAW:
|
|
|
|
#ifdef SOL_DRAW_PRE
|
|
|
|
if(lastbutton != SOL_DRAW_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
if(sel_card != NOT_A_CARD){
|
2004-08-18 12:06:10 +00:00
|
|
|
/* unselect selected card */
|
2004-08-17 06:50:14 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
2004-08-21 23:05:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(rem != NOT_A_CARD) {
|
2005-06-26 19:35:29 +00:00
|
|
|
int cur_rem_old = cur_rem;
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw new cards form the remains of the deck */
|
2004-08-17 06:50:14 +00:00
|
|
|
if(cur_rem == NOT_A_CARD){
|
|
|
|
cur_rem = rem;
|
|
|
|
i = CARDS_PER_DRAW - 1;
|
|
|
|
} else {
|
|
|
|
i = CARDS_PER_DRAW;
|
|
|
|
}
|
|
|
|
while(i>0 && deck[cur_rem].next != NOT_A_CARD){
|
|
|
|
cur_rem = deck[cur_rem].next;
|
|
|
|
i--;
|
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
/* test if any cards are really left on */
|
|
|
|
/* the remains' stack */
|
2004-08-17 06:50:14 +00:00
|
|
|
if(i == CARDS_PER_DRAW){
|
|
|
|
cur_rem = NOT_A_CARD;
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
/* if cursor was on remains' stack when new cards were
|
|
|
|
* drawn, put cursor on top of remains' stack */
|
|
|
|
if(cur_col == REM_COL && cur_card == cur_rem_old)
|
|
|
|
cur_card = cur_rem;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-21 23:05:36 +00:00
|
|
|
/* Show the menu */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_QUIT:
|
2004-08-17 06:50:14 +00:00
|
|
|
switch(solitaire_menu(MENU_DURINGGAME)){
|
|
|
|
case MENU_QUIT:
|
2004-08-21 23:05:36 +00:00
|
|
|
return SOLITAIRE_QUIT;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
case MENU_USB:
|
|
|
|
return SOLITAIRE_USB;
|
2004-08-17 06:50:14 +00:00
|
|
|
|
|
|
|
case MENU_RESTART:
|
|
|
|
solitaire_init();
|
|
|
|
break;
|
|
|
|
}
|
2004-10-20 23:54:53 +00:00
|
|
|
default:
|
|
|
|
if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
return SOLITAIRE_USB;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
if(button != BUTTON_NONE)
|
|
|
|
lastbutton = button;
|
2004-08-21 23:05:36 +00:00
|
|
|
|
|
|
|
/* fix incoherences concerning cur_col and cur_card */
|
|
|
|
c = find_card_col(cur_card);
|
|
|
|
if(c != NOT_A_COL && c != cur_col)
|
|
|
|
cur_card = find_last_card(cur_col);
|
2005-06-26 19:35:29 +00:00
|
|
|
|
|
|
|
if(cur_card == NOT_A_CARD && find_last_card(cur_col) != NOT_A_CARD)
|
|
|
|
cur_card = find_last_card(cur_col);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
2004-10-20 23:54:53 +00:00
|
|
|
int result;
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* plugin init */
|
2004-08-17 06:50:14 +00:00
|
|
|
TEST_PLUGIN_API(api);
|
|
|
|
(void)parameter;
|
|
|
|
rb = api;
|
2004-08-18 12:06:10 +00:00
|
|
|
/* end of plugin init */
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* Welcome to Solitaire ! */
|
2004-08-17 06:50:14 +00:00
|
|
|
rb->splash(HZ*2, true, "Welcome to Solitaire !");
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* play the game :) */
|
2004-08-21 23:05:36 +00:00
|
|
|
/* Keep playing if a game was won (that means display the menu after */
|
|
|
|
/* winning instead of quiting) */
|
2004-10-20 23:54:53 +00:00
|
|
|
while((result = solitaire()) == SOLITAIRE_WIN);
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* Exit the plugin */
|
2004-10-20 23:54:53 +00:00
|
|
|
return (result == SOLITAIRE_USB) ? PLUGIN_USB_CONNECTED : PLUGIN_OK;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|