2004-08-17 06:50:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-08-02 22:17:21 +00:00
|
|
|
* Copyright (C) 2004-2006 Antoine Cellerier <dionoea @t videolan d.t org>
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
Solitaire by dionoea
|
2005-12-20 22:57:04 +00:00
|
|
|
Graphics & Fix Bugs by Ben Basha
|
2004-08-17 06:50:14 +00:00
|
|
|
|
|
|
|
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"
|
2005-12-20 22:57:04 +00:00
|
|
|
#include "configfile.h"
|
2004-08-17 06:50:14 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
static struct plugin_api* rb;
|
|
|
|
#define min(a,b) (a<b?a:b)
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* Key definitions
|
|
|
|
*/
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2006-08-02 22:17:21 +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
|
|
|
|
# define SOL_MOVE BUTTON_ON
|
2006-09-17 22:14:18 +00:00
|
|
|
# define SOL_DRAW BUTTON_F1
|
2006-08-02 22:17:21 +00:00
|
|
|
# define SOL_REM2CUR BUTTON_PLAY
|
2006-09-17 22:14:18 +00:00
|
|
|
# define SOL_CUR2STACK BUTTON_F2
|
2006-08-02 22:17:21 +00:00
|
|
|
# define SOL_REM2STACK BUTTON_F3
|
|
|
|
# define HK_MOVE "ON"
|
2006-09-17 22:14:18 +00:00
|
|
|
# define HK_DRAW "F1"
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_REM2CUR "PLAY"
|
2006-09-17 22:14:18 +00:00
|
|
|
# define HK_CUR2STACK "F2"
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_REM2STACK "F3"
|
2004-10-20 23:54:53 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2006-08-02 22:17:21 +00:00
|
|
|
# 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)
|
2006-09-17 22:14:18 +00:00
|
|
|
# define SOL_REM2CUR_PRE BUTTON_DOWN
|
|
|
|
# define SOL_REM2CUR (BUTTON_DOWN | BUTTON_REPEAT)
|
|
|
|
# define SOL_CUR2STACK_PRE BUTTON_UP
|
|
|
|
# define SOL_CUR2STACK (BUTTON_UP | BUTTON_REPEAT)
|
|
|
|
# define SOL_REM2STACK_PRE BUTTON_RIGHT
|
|
|
|
# define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_MOVE "MODE"
|
|
|
|
# define HK_DRAW "MODE.."
|
2006-09-17 22:14:18 +00:00
|
|
|
# define HK_REM2CUR "DOWN.."
|
|
|
|
# define HK_CUR2STACK "UP.."
|
|
|
|
# define HK_REM2STACK "RIGHT.."
|
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)
|
2006-08-02 22:17:21 +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
|
|
|
|
# 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_REM BUTTON_REC
|
|
|
|
# define SOL_RC_QUIT BUTTON_RC_STOP
|
2006-09-06 08:28:13 +00:00
|
|
|
# define HK_MOVE "NAVI"
|
|
|
|
# define HK_DRAW "A-B"
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_REM2CUR "PLAY+LEFT"
|
2006-09-17 22:14:18 +00:00
|
|
|
# define HK_CUR2STACK "NAVI.."
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_REM2STACK "PLAY+RIGHT"
|
2005-02-16 02:08:16 +00:00
|
|
|
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) ||(CONFIG_KEYPAD == IPOD_3G_PAD)
|
2006-08-02 22:17:21 +00:00
|
|
|
# define SOL_QUIT (BUTTON_SELECT | BUTTON_MENU)
|
2006-09-17 22:14:18 +00:00
|
|
|
# define SOL_UP BUTTON_SCROLL_BACK
|
|
|
|
# define SOL_DOWN BUTTON_SCROLL_FWD
|
|
|
|
# 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_SELECT
|
|
|
|
# define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
|
|
|
|
# define SOL_DRAW_PRE BUTTON_MENU
|
|
|
|
# define SOL_DRAW (BUTTON_MENU | BUTTON_REL)
|
|
|
|
# define SOL_REM2CUR BUTTON_PLAY
|
|
|
|
# define SOL_CUR2STACK_PRE BUTTON_MENU
|
|
|
|
# define SOL_CUR2STACK (BUTTON_MENU | BUTTON_REPEAT)
|
|
|
|
# define SOL_REM2STACK_PRE BUTTON_RIGHT
|
|
|
|
# define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
|
2006-09-18 00:36:09 +00:00
|
|
|
# define HK_UD "SCROLL U/D"
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_MOVE "SELECT"
|
2006-09-17 22:14:18 +00:00
|
|
|
# define HK_DRAW "MENU"
|
|
|
|
# define HK_REM2CUR "PLAY"
|
|
|
|
# define HK_CUR2STACK "MENU.."
|
|
|
|
# define HK_REM2STACK "RIGHT.."
|
2006-07-11 21:38:27 +00:00
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
|
2006-08-02 22:17:21 +00:00
|
|
|
# define SOL_QUIT BUTTON_POWER
|
|
|
|
# define SOL_UP BUTTON_UP
|
|
|
|
# define SOL_DOWN BUTTON_DOWN
|
|
|
|
# define SOL_LEFT BUTTON_LEFT
|
|
|
|
# define SOL_RIGHT BUTTON_RIGHT
|
|
|
|
# define SOL_MOVE BUTTON_SELECT
|
|
|
|
# define SOL_DRAW BUTTON_PLAY
|
|
|
|
# define SOL_REM2CUR (BUTTON_REC | BUTTON_LEFT)
|
|
|
|
# define SOL_CUR2STACK (BUTTON_REC | BUTTON_UP)
|
|
|
|
# define SOL_REM2STACK (BUTTON_REC | BUTTON_DOWN)
|
|
|
|
# define HK_MOVE "MENU"
|
|
|
|
# define HK_DRAW "PLAY"
|
|
|
|
# define HK_REM2CUR "REC+LEFT"
|
2006-09-17 22:14:18 +00:00
|
|
|
# define HK_CUR2STACK "REC+UP"
|
2006-08-02 22:17:21 +00:00
|
|
|
# define HK_REM2STACK "REC+DOWN"
|
2006-02-24 15:42:52 +00:00
|
|
|
|
2006-07-11 21:38:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
2006-08-02 22:17:21 +00:00
|
|
|
# define SOL_QUIT BUTTON_A
|
|
|
|
# define SOL_UP BUTTON_UP
|
|
|
|
# define SOL_DOWN BUTTON_DOWN
|
|
|
|
# define SOL_LEFT BUTTON_LEFT
|
|
|
|
# define SOL_RIGHT BUTTON_RIGHT
|
|
|
|
# define SOL_MOVE_PRE BUTTON_SELECT
|
|
|
|
# define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
|
|
|
|
# define SOL_DRAW BUTTON_MENU
|
|
|
|
# define SOL_REM2CUR (BUTTON_LEFT | BUTTON_POWER)
|
|
|
|
# define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
|
|
|
|
# define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_POWER)
|
|
|
|
# define HK_MOVE "SELECT"
|
|
|
|
# define HK_DRAW "MENU"
|
|
|
|
# define HK_REM2CUR "POWER+LEFT"
|
|
|
|
# define HK_CUR2STACK "SELECT.."
|
|
|
|
# define HK_REM2STACK "POWER+RIGHT"
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2006-08-11 08:35:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
|
2006-08-11 09:05:58 +00:00
|
|
|
# define SOL_QUIT BUTTON_POWER
|
|
|
|
# define SOL_UP BUTTON_SCROLL_UP
|
|
|
|
# define SOL_DOWN BUTTON_SCROLL_DOWN
|
|
|
|
# define SOL_LEFT BUTTON_LEFT
|
|
|
|
# define SOL_RIGHT BUTTON_RIGHT
|
|
|
|
# define SOL_MOVE BUTTON_REW
|
|
|
|
# define SOL_DRAW BUTTON_PLAY
|
|
|
|
# define SOL_REM2CUR (BUTTON_FF | BUTTON_LEFT)
|
|
|
|
# define SOL_CUR2STACK (BUTTON_FF | BUTTON_SCROLL_UP)
|
|
|
|
# define SOL_REM2STACK (BUTTON_FF | BUTTON_SCROLL_DOWN)
|
|
|
|
# define HK_MOVE "REW"
|
|
|
|
# define HK_DRAW "PLAY"
|
|
|
|
# define HK_REM2CUR "REW+LEFT"
|
|
|
|
# define HK_CUR2STACK "REW+UP.."
|
|
|
|
# define HK_REM2STACK "REW+DOWN"
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2005-10-06 12:42:19 +00:00
|
|
|
#else
|
2006-08-02 22:17:21 +00:00
|
|
|
# error "Unknown keypad"
|
2005-10-06 12:42:19 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-17 22:14:18 +00:00
|
|
|
#define HK_LR "LEFT/RIGHT"
|
|
|
|
#ifndef HK_UD
|
|
|
|
# define HK_UD "UP/DOWN"
|
|
|
|
#endif
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* Help strings
|
|
|
|
*/
|
|
|
|
|
2006-09-17 22:14:18 +00:00
|
|
|
static int helplines;
|
|
|
|
static int displaylines;
|
|
|
|
|
|
|
|
static char helptext[] =
|
|
|
|
/* Use single spaces only! Close each line with one \0. */
|
|
|
|
"-- Navigation --\0"
|
|
|
|
HK_LR ": Move the cursor to the previous/ next column.\0"
|
|
|
|
HK_UD ": Move the cursor up/ down in the column.\0"
|
|
|
|
HK_MOVE ": Select cards, move cards, reveal hidden cards...\0"
|
|
|
|
HK_DRAW ": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0"
|
|
|
|
"-- Shortcuts --\0"
|
|
|
|
HK_REM2CUR ": Put the card on top of the remains stack on top of the cursor.\0"
|
|
|
|
HK_CUR2STACK ": Put the card under the cursor on one of the 4 final stacks.\0"
|
|
|
|
HK_REM2STACK ": Put the card on top of the remains stack on one of the 4 final stacks.\0"
|
|
|
|
;
|
2006-08-02 22:17:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Misc constants, graphics and other defines
|
|
|
|
*/
|
2006-02-05 01:58:10 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* size of a card on the screen */
|
2006-03-20 22:07:35 +00:00
|
|
|
#if (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176)
|
2006-09-06 01:33:26 +00:00
|
|
|
# define CARD_WIDTH 28
|
|
|
|
# define CARD_HEIGHT 35
|
2006-08-02 22:17:21 +00:00
|
|
|
#elif LCD_HEIGHT > 64
|
2006-09-06 01:33:26 +00:00
|
|
|
# define CARD_WIDTH 20
|
|
|
|
# define CARD_HEIGHT 25
|
2006-03-20 22:07:35 +00:00
|
|
|
#else
|
2006-09-06 01:33:26 +00:00
|
|
|
# define CARD_WIDTH 15
|
|
|
|
# define CARD_HEIGHT 13
|
2006-03-20 22:07:35 +00:00
|
|
|
#endif
|
2006-02-05 01:58:10 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* where the cards start */
|
2006-08-03 19:57:33 +00:00
|
|
|
#if LCD_HEIGHT > 64
|
2006-09-03 14:16:03 +00:00
|
|
|
# define MARGIN 2
|
2006-09-06 01:33:26 +00:00
|
|
|
# define CARD_START ( CARD_HEIGHT + 3 )
|
2006-08-03 19:57:33 +00:00
|
|
|
#else
|
|
|
|
/* The screen is *small* */
|
2006-09-03 14:16:03 +00:00
|
|
|
# define MARGIN 0
|
2006-09-06 01:33:26 +00:00
|
|
|
# define CARD_START ( CARD_HEIGHT )
|
2006-08-03 19:57:33 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-06 01:33:26 +00:00
|
|
|
#include "solitaire_numbers.h"
|
|
|
|
#include "solitaire_suits.h"
|
|
|
|
#include "solitaire_suitsi.h"
|
2006-08-02 22:17:21 +00:00
|
|
|
|
2006-09-06 01:33:26 +00:00
|
|
|
#define NUMBER_HEIGHT (BMPHEIGHT_solitaire_numbers/13)
|
|
|
|
#define NUMBER_WIDTH BMPWIDTH_solitaire_numbers
|
|
|
|
#define NUMBER_STRIDE BMPWIDTH_solitaire_numbers
|
|
|
|
#define SUIT_HEIGHT (BMPHEIGHT_solitaire_suits/4)
|
|
|
|
#define SUIT_WIDTH BMPWIDTH_solitaire_suits
|
|
|
|
#define SUIT_STRIDE BMPWIDTH_solitaire_suits
|
|
|
|
#define SUITI_HEIGHT (BMPHEIGHT_solitaire_suitsi/4)
|
|
|
|
#define SUITI_WIDTH BMPWIDTH_solitaire_suitsi
|
|
|
|
#define SUITI_STRIDE BMPWIDTH_solitaire_suitsi
|
2006-08-02 22:17:21 +00:00
|
|
|
|
|
|
|
#define draw_number( num, x, y ) \
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_mono_bitmap_part( solitaire_numbers, 0, num * NUMBER_HEIGHT, \
|
|
|
|
NUMBER_STRIDE, x, y, NUMBER_WIDTH, NUMBER_HEIGHT );
|
2006-08-02 22:17:21 +00:00
|
|
|
|
|
|
|
#define draw_suit( num, x, y ) \
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_mono_bitmap_part( solitaire_suits, 0, num * SUIT_HEIGHT, \
|
|
|
|
SUIT_STRIDE, x, y, SUIT_WIDTH, SUIT_HEIGHT );
|
|
|
|
|
|
|
|
#define draw_suiti( num, x, y ) \
|
|
|
|
rb->lcd_mono_bitmap_part( solitaire_suitsi, 0, num * SUITI_HEIGHT, \
|
|
|
|
SUITI_STRIDE, x, y, SUITI_WIDTH, SUITI_HEIGHT );
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2006-09-06 01:33:26 +00:00
|
|
|
#include "solitaire_cardback.h"
|
|
|
|
#define CARDBACK_HEIGHT BMPHEIGHT_solitaire_cardback
|
|
|
|
#define CARDBACK_WIDTH BMPWIDTH_solitaire_cardback
|
2006-08-02 22:17:21 +00:00
|
|
|
#endif
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-09-02 22:45:27 +00:00
|
|
|
#if HAVE_LCD_COLOR
|
|
|
|
static const unsigned colors[4] = {
|
|
|
|
LCD_BLACK, LCD_RGBPACK(255, 0, 0), LCD_BLACK, LCD_RGBPACK(255, 0, 0)
|
|
|
|
};
|
|
|
|
#elif LCD_DEPTH > 1
|
|
|
|
static const unsigned colors[4] = {
|
|
|
|
LCD_BLACK, LCD_BRIGHTNESS(127), LCD_BLACK, LCD_BRIGHTNESS(127)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
#define CONFIG_FILENAME "sol.cfg"
|
2005-12-20 22:57:04 +00:00
|
|
|
|
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
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
#define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
|
|
|
|
|
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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
/* columns COL_NUM to 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
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* background color */
|
|
|
|
#define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
#if LCD_DEPTH > 1 && !defined( LCD_WHITE )
|
|
|
|
# define LCD_WHITE LCD_DEFAULT_BG
|
2005-12-20 22:57:04 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
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;
|
2006-08-02 22:17:21 +00:00
|
|
|
} card_t;
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* LCD card drawing routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void draw_cursor( int x, int y )
|
|
|
|
{
|
|
|
|
rb->lcd_set_drawmode( DRMODE_COMPLEMENT );
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_fillrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
|
2006-08-02 22:17:21 +00:00
|
|
|
rb->lcd_set_drawmode( DRMODE_SOLID );
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* Draw a card's border, select it if it's selected and draw the cursor
|
|
|
|
* is the cursor is currently over the card */
|
|
|
|
static void draw_card_ext( int x, int y, bool selected, bool cursor )
|
|
|
|
{
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground( LCD_BLACK );
|
|
|
|
#endif
|
|
|
|
/* draw a rectangle omiting the corner pixels, which is why we don't
|
|
|
|
* use drawrect */
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_hline( x+1, x+CARD_WIDTH-2, y );
|
|
|
|
rb->lcd_hline( x+1, x+CARD_WIDTH-2, y+CARD_HEIGHT-1 );
|
|
|
|
rb->lcd_vline( x, y+1, y+CARD_HEIGHT-2 );
|
|
|
|
rb->lcd_vline( x+CARD_WIDTH-1, y+1, y+CARD_HEIGHT-2 );
|
2006-08-02 22:17:21 +00:00
|
|
|
|
|
|
|
if( selected )
|
|
|
|
{
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_drawrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cursor )
|
|
|
|
{
|
|
|
|
draw_cursor( x, y );
|
|
|
|
}
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* Draw a card's inner graphics */
|
|
|
|
static void draw_card( card_t card, int x, int y,
|
|
|
|
bool selected, bool cursor, bool leftstyle )
|
|
|
|
{
|
|
|
|
#ifndef HAVE_LCD_COLOR
|
|
|
|
/* On Black&White or Greyscale LCDs we don't have a card back.
|
|
|
|
* We thus need to clear the card area even if the card isn't
|
|
|
|
* known. */
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground( LCD_WHITE );
|
|
|
|
#else
|
|
|
|
rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID );
|
|
|
|
#endif
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_fillrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
|
2006-08-02 22:17:21 +00:00
|
|
|
#if LCD_DEPTH == 1
|
|
|
|
rb->lcd_set_drawmode( DRMODE_SOLID );
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if( card.known )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
/* On Color LCDs we have a card back so we only need to clear
|
|
|
|
* the card area when it's known*/
|
|
|
|
rb->lcd_set_foreground( LCD_WHITE );
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_fillrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
|
2006-08-02 22:17:21 +00:00
|
|
|
#endif
|
2006-09-02 22:45:27 +00:00
|
|
|
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground( colors[card.suit] );
|
|
|
|
#endif
|
2006-08-02 22:17:21 +00:00
|
|
|
if( leftstyle )
|
|
|
|
{
|
2006-09-03 14:16:03 +00:00
|
|
|
#if MARGIN > 0
|
2006-08-02 22:17:21 +00:00
|
|
|
draw_suit( card.suit, x+1, y+2+NUMBER_HEIGHT );
|
2006-08-03 19:57:33 +00:00
|
|
|
draw_number( card.num, x+1, y+1 );
|
|
|
|
#else
|
2006-08-03 20:58:35 +00:00
|
|
|
draw_suit( card.suit, x+1, y+NUMBER_HEIGHT );
|
|
|
|
draw_number( card.num, x+1, y );
|
2006-08-03 19:57:33 +00:00
|
|
|
#endif
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-03 14:16:03 +00:00
|
|
|
#if MARGIN > 0
|
2006-08-02 22:17:21 +00:00
|
|
|
draw_suit( card.suit, x+2+NUMBER_WIDTH, y+1 );
|
2006-09-02 23:10:28 +00:00
|
|
|
#else
|
|
|
|
draw_suit( card.suit, x+1+NUMBER_WIDTH, y+1 );
|
|
|
|
#endif
|
2006-08-03 19:57:33 +00:00
|
|
|
draw_number( card.num, x+1, y+1 );
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_bitmap( solitaire_cardback, x+1, y+1,
|
|
|
|
CARDBACK_WIDTH, CARDBACK_HEIGHT );
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
draw_card_ext( x, y, selected, cursor );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw an empty stack */
|
|
|
|
static void draw_empty_stack( int s, int x, int y, bool cursor )
|
|
|
|
{
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground( LCD_WHITE );
|
|
|
|
#else
|
|
|
|
rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID );
|
|
|
|
#endif
|
2006-09-06 01:33:26 +00:00
|
|
|
rb->lcd_fillrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
|
2006-08-02 22:17:21 +00:00
|
|
|
#if LCD_DEPTH == 1
|
|
|
|
rb->lcd_set_drawmode( DRMODE_SOLID );
|
|
|
|
#endif
|
2006-09-02 22:45:27 +00:00
|
|
|
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground( colors[s] );
|
|
|
|
#endif
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
draw_suiti( s, x+(CARD_WIDTH-SUITI_WIDTH)/2,
|
|
|
|
y+(CARD_HEIGHT-SUITI_HEIGHT)/2 );
|
|
|
|
|
|
|
|
draw_card_ext( x, y, false, cursor );
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* Help
|
|
|
|
*/
|
|
|
|
|
2006-09-17 22:14:18 +00:00
|
|
|
static void init_help(void)
|
|
|
|
{
|
|
|
|
int lines = 0;
|
|
|
|
int w_space, w, h;
|
|
|
|
int para_len;
|
|
|
|
char *para = helptext;
|
|
|
|
|
|
|
|
rb->lcd_getstringsize(" ", &w_space, &h);
|
|
|
|
displaylines = LCD_HEIGHT / h;
|
|
|
|
para_len = rb->strlen(para);
|
|
|
|
|
|
|
|
while (para_len)
|
|
|
|
{
|
|
|
|
bool first = true;
|
|
|
|
int x = 0;
|
|
|
|
char *next, *store;
|
|
|
|
|
|
|
|
next = rb->strtok_r(para, " ", &store);
|
|
|
|
while (next)
|
|
|
|
{
|
|
|
|
rb->lcd_getstringsize(next, &w, NULL);
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
if (x + w > LCD_WIDTH)
|
|
|
|
{
|
|
|
|
lines++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
next[-1] = ' '; /* re-concatenate string */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
x += w + w_space;
|
|
|
|
next = rb->strtok_r(NULL, " ", &store);
|
|
|
|
}
|
|
|
|
|
|
|
|
lines++;
|
|
|
|
para += para_len + 1;
|
|
|
|
para_len = rb->strlen(para);
|
|
|
|
}
|
|
|
|
helplines = lines;
|
|
|
|
}
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
enum help { HELP_QUIT, HELP_USB };
|
2004-08-21 23:05:36 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
/* help for the not so intuitive interface */
|
2006-08-02 22:17:21 +00:00
|
|
|
enum help solitaire_help( void )
|
|
|
|
{
|
2006-09-17 22:14:18 +00:00
|
|
|
int start = 0;
|
2004-10-20 23:54:53 +00:00
|
|
|
int button;
|
|
|
|
int lastbutton = BUTTON_NONE;
|
2006-09-17 22:14:18 +00:00
|
|
|
bool fixed = (displaylines >= helplines);
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
while( true )
|
|
|
|
{
|
2006-09-17 22:14:18 +00:00
|
|
|
char *text = helptext;
|
|
|
|
int line = fixed ? (displaylines - helplines) / 2 : 0;
|
|
|
|
int i;
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-09-17 22:14:18 +00:00
|
|
|
rb->lcd_clear_display();
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2006-09-17 22:14:18 +00:00
|
|
|
for (i = 0; i < start + displaylines; i++)
|
|
|
|
{
|
|
|
|
if (i >= start)
|
|
|
|
rb->lcd_puts(0, line++, text);
|
|
|
|
text += rb->strlen(text) + 1;
|
|
|
|
}
|
2004-10-20 23:54:53 +00:00
|
|
|
rb->lcd_update();
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
button = rb->button_get( true );
|
|
|
|
switch( button )
|
|
|
|
{
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_UP:
|
|
|
|
#ifdef SOL_UP_PRE
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_UP_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
2006-09-17 22:14:18 +00:00
|
|
|
#else
|
|
|
|
case SOL_UP|BUTTON_REPEAT:
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
2006-09-17 22:14:18 +00:00
|
|
|
if (!fixed && start > 0)
|
|
|
|
start--;
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_DOWN:
|
|
|
|
#ifdef SOL_DOWN_PRE
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_DOWN_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
2006-09-17 22:14:18 +00:00
|
|
|
#else
|
|
|
|
case SOL_DOWN|BUTTON_REPEAT:
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
2006-09-17 22:14:18 +00:00
|
|
|
if (!fixed && start < helplines - displaylines)
|
|
|
|
start++;
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef SOL_RC_QUIT
|
|
|
|
case SOL_RC_QUIT:
|
|
|
|
#endif
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_QUIT:
|
|
|
|
return HELP_QUIT;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
default:
|
2006-08-02 22:17:21 +00:00
|
|
|
if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
|
2004-10-20 23:54:53 +00:00
|
|
|
return HELP_USB;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( button != BUTTON_NONE )
|
2004-10-20 23:54:53 +00:00
|
|
|
lastbutton = button;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom menu / options
|
|
|
|
*/
|
2006-09-15 06:24:36 +00:00
|
|
|
|
2005-12-20 22:57:04 +00:00
|
|
|
#define CFGFILE_VERSION 0
|
2006-09-15 06:24:36 +00:00
|
|
|
|
|
|
|
/* introduce a struct if there's more than one setting */
|
|
|
|
int draw_type_disk = 0;
|
|
|
|
int draw_type;
|
2005-12-20 22:57:04 +00:00
|
|
|
|
|
|
|
static struct configdata config[] = {
|
2006-09-15 06:24:36 +00:00
|
|
|
{ TYPE_INT, 0, 1, &draw_type_disk, "draw_type", NULL, NULL }
|
2005-12-20 22:57:04 +00:00
|
|
|
};
|
2004-08-17 06:50:14 +00:00
|
|
|
|
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
char draw_option_string[32];
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
static void create_draw_option_string(void)
|
2005-06-09 21:19:38 +00:00
|
|
|
{
|
2006-09-18 00:36:09 +00:00
|
|
|
if (draw_type == 0)
|
|
|
|
rb->strcpy(draw_option_string, "Draw Three Cards");
|
|
|
|
else
|
|
|
|
rb->strcpy(draw_option_string, "Draw One Card");
|
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
void solitaire_init(void);
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
/* menu return codes */
|
|
|
|
enum { MENU_RESUME, MENU_QUIT, MENU_USB };
|
|
|
|
|
|
|
|
int solitaire_menu(bool in_game)
|
|
|
|
{
|
|
|
|
int m;
|
|
|
|
int result = -1;
|
|
|
|
int i = 0;
|
2006-08-02 22:17:21 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
struct menu_item items[4];
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-09-19 06:14:56 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(LCD_DEFAULT_FG);
|
|
|
|
rb->lcd_set_background(LCD_DEFAULT_BG);
|
|
|
|
#endif
|
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
if (in_game)
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2006-09-18 00:36:09 +00:00
|
|
|
items[i++].desc = "Resume Game";
|
|
|
|
items[i++].desc = "Restart Game";
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
2006-09-18 00:36:09 +00:00
|
|
|
else
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2006-09-18 00:36:09 +00:00
|
|
|
items[i++].desc = "Start Game";
|
|
|
|
items[i++].desc = draw_option_string;
|
|
|
|
}
|
|
|
|
items[i++].desc = "Help";
|
|
|
|
items[i++].desc = "Quit";
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
create_draw_option_string();
|
|
|
|
m = rb->menu_init(items, i, NULL, NULL, NULL, NULL);
|
|
|
|
while (result < 0)
|
|
|
|
{
|
|
|
|
switch (rb->menu_show(m))
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2006-09-18 00:36:09 +00:00
|
|
|
case MENU_SELECTED_EXIT:
|
|
|
|
result = MENU_RESUME;
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
result = MENU_USB;
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
case 0:
|
|
|
|
result = MENU_RESUME;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
case 1:
|
|
|
|
if (in_game)
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2006-09-18 00:36:09 +00:00
|
|
|
solitaire_init();
|
|
|
|
result = MENU_RESUME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
draw_type = (draw_type + 1) % 2;
|
|
|
|
create_draw_option_string();
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
case 2:
|
|
|
|
rb->lcd_setmargins(0, 0);
|
|
|
|
if (solitaire_help() == HELP_USB)
|
|
|
|
result = MENU_USB;
|
|
|
|
break;
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2006-09-18 00:36:09 +00:00
|
|
|
case 3:
|
|
|
|
result = MENU_QUIT;
|
2004-08-17 06:50:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-18 00:36:09 +00:00
|
|
|
rb->menu_exit(m);
|
|
|
|
rb->lcd_setmargins(0, 0);
|
|
|
|
return result;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
|
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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
card_t deck[ NUM_CARDS ];
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* the remaining cards */
|
2006-09-04 19:36:09 +00:00
|
|
|
/* first card of the remains' stack */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char rem;
|
2006-09-04 19:36:09 +00:00
|
|
|
/* upper visible card from the remains' stack */
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char cur_rem;
|
2006-09-04 19:36:09 +00:00
|
|
|
/* number of cards drawn from the remains stack - 1 */
|
2006-09-10 20:39:46 +00:00
|
|
|
signed char count_rem;
|
2006-09-04 19:36:09 +00:00
|
|
|
/* number of cards per draw of the remains' stack */
|
2006-09-10 20:39:46 +00:00
|
|
|
signed char cards_per_draw;
|
2004-08-17 06:50:14 +00:00
|
|
|
|
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
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* Card handling routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned char next_random_card( card_t *deck )
|
|
|
|
{
|
|
|
|
unsigned char i,r;
|
|
|
|
|
|
|
|
r = rb->rand()%(NUM_CARDS)+1;
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
while( r>0 )
|
|
|
|
{
|
|
|
|
i = (i + 1)%(NUM_CARDS);
|
|
|
|
if( !deck[i].used ) r--;
|
|
|
|
}
|
|
|
|
|
|
|
|
deck[i].used = 1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* initialize the game */
|
2006-08-02 22:17:21 +00:00
|
|
|
void solitaire_init( void )
|
|
|
|
{
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2004-08-17 06:50:14 +00:00
|
|
|
unsigned char c;
|
2006-08-02 22:17:21 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* number of cards that are drawn on the remains' stack (by pressing F2) */
|
|
|
|
if( draw_type == 0 )
|
|
|
|
{
|
|
|
|
cards_per_draw = 3;
|
2005-12-20 22:57:04 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cards_per_draw = 1;
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* init deck */
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i=0; i<SUITS; i++ )
|
|
|
|
{
|
|
|
|
for( j=0; j<CARDS_PER_SUIT; j++ )
|
|
|
|
{
|
|
|
|
#define card deck[i*CARDS_PER_SUIT+j]
|
|
|
|
card.suit = i;
|
|
|
|
card.num = j;
|
|
|
|
card.known = 1;
|
|
|
|
card.used = 0;
|
|
|
|
card.next = NOT_A_CARD;
|
|
|
|
#undef 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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i=0; i<COL_NUM; i++ )
|
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
c = NOT_A_CARD;
|
2006-08-02 22:17:21 +00:00
|
|
|
for( j=0; j<=i; j++ )
|
|
|
|
{
|
|
|
|
if( c == NOT_A_CARD )
|
|
|
|
{
|
|
|
|
cols[i] = next_random_card( deck );
|
2004-08-17 06:50:14 +00:00
|
|
|
c = cols[i];
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deck[c].next = next_random_card( deck );
|
2004-08-17 06:50:14 +00:00
|
|
|
c = deck[c].next;
|
|
|
|
}
|
2006-08-02 22:17:21 +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
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i=1; i < NUM_CARDS - COL_NUM * (COL_NUM + 1)/2; i++ )
|
|
|
|
{
|
|
|
|
deck[c].next = next_random_card( deck );
|
2004-08-17 06:50:14 +00:00
|
|
|
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 */
|
2006-08-02 22:17:21 +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;
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2006-09-04 19:36:09 +00:00
|
|
|
count_rem=-1;
|
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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
unsigned char find_card_col( unsigned char card )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
int i;
|
|
|
|
unsigned char c;
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
if( card == NOT_A_CARD ) return NOT_A_COL;
|
2004-08-21 23:05:36 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i=0; i<COL_NUM; i++ )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
c = cols[i];
|
2006-08-02 22:17:21 +00:00
|
|
|
while( c != NOT_A_CARD )
|
|
|
|
{
|
|
|
|
if( c == card ) return i;
|
2004-08-21 23:05:36 +00:00
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i=0; i<SUITS; i++ )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
c = stacks[i];
|
2006-08-02 22:17:21 +00:00
|
|
|
while( c != NOT_A_CARD )
|
|
|
|
{
|
|
|
|
if( c == card ) return STACKS_COL + i;
|
2004-08-21 23:05:36 +00:00
|
|
|
c = deck[c].next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return REM_COL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the card preceding 'card' */
|
|
|
|
/* if it doesn't exist, return NOT_A_CARD */
|
2006-08-02 22:17:21 +00:00
|
|
|
unsigned char find_prev_card( unsigned char card ){
|
2004-08-21 23:05:36 +00:00
|
|
|
int i;
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i=0; i < NUM_CARDS; i++ )
|
|
|
|
{
|
|
|
|
if( deck[i].next == card ) return i;
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NOT_A_CARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the last card of a given column */
|
2006-08-02 22:17:21 +00:00
|
|
|
unsigned char find_last_card( unsigned char col )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
unsigned char c;
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
if( col < COL_NUM )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
c = cols[col];
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else if( col < REM_COL )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
c = stacks[col - STACKS_COL];
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-03 16:54:42 +00:00
|
|
|
c = cur_rem;
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(c == NOT_A_CARD)
|
|
|
|
return c;
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while(deck[c].next != NOT_A_CARD)
|
2004-08-21 23:05:36 +00:00
|
|
|
c = deck[c].next;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
enum move { MOVE_OK, MOVE_NOT_OK };
|
|
|
|
|
|
|
|
enum move move_card( unsigned char dest_col, unsigned char src_card )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* 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) */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( src_card == NOT_A_CARD ) return MOVE_NOT_OK;
|
2004-08-21 23:05:36 +00:00
|
|
|
/* you can't put a card back on the remains' stack */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( dest_col == REM_COL ) return MOVE_NOT_OK;
|
2006-09-04 21:33:08 +00:00
|
|
|
/* you can't move an unknown card */
|
|
|
|
if( !deck[src_card].known ) return MOVE_NOT_OK;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
src_col = find_card_col( src_card );
|
|
|
|
dest_card = find_last_card( dest_col );
|
|
|
|
src_card_prev = find_prev_card( src_card );
|
2004-08-21 23:05:36 +00:00
|
|
|
|
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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( src_col >= COL_NUM && src_col < REM_COL
|
|
|
|
&& deck[src_card].next != NOT_A_CARD )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
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 ... */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( dest_col < COL_NUM )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* ... check is we are on an empty color and that the src is a king */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( dest_card == NOT_A_CARD
|
|
|
|
&& 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;
|
|
|
|
}
|
2006-09-10 20:04:17 +00:00
|
|
|
/* ... or check if the cards follow one another and have
|
|
|
|
* different colorsuit */
|
2006-08-02 22:17:21 +00:00
|
|
|
else if(( deck[dest_card].suit + deck[src_card].suit)%2==1
|
|
|
|
&& deck[dest_card].num == deck[src_card].num + 1 )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* this is a winning combination */
|
|
|
|
deck[dest_card].next = src_card;
|
|
|
|
}
|
|
|
|
/* ... or, humpf, well that's not good news */
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* 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 ... */
|
2006-08-02 22:17:21 +00:00
|
|
|
else if( dest_col < REM_COL )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* ... 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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( dest_card == NOT_A_CARD
|
|
|
|
&& deck[src_card].num == 0
|
|
|
|
&& 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} */
|
2006-08-02 22:17:21 +00:00
|
|
|
else if( deck[dest_card].suit == deck[src_card].suit
|
|
|
|
&& deck[dest_card].num + 1 == deck[src_card].num
|
|
|
|
&& (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* this is a winning combination */
|
|
|
|
deck[dest_card].next = src_card;
|
|
|
|
}
|
|
|
|
/* ... or, well that's not good news */
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
2006-09-10 20:04:17 +00:00
|
|
|
/* this is not a winning combination */
|
2004-08-21 23:05:36 +00:00
|
|
|
return MOVE_NOT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if we are on the remains' stack */
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* 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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( src_col == REM_COL )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* if src card is the first card from the stack */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( src_card_prev == NOT_A_CARD )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
rem = deck[src_card].next;
|
|
|
|
}
|
|
|
|
/* if src card is not the first card from the stack */
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
deck[src_card_prev].next = deck[src_card].next;
|
|
|
|
}
|
|
|
|
deck[src_card].next = NOT_A_CARD;
|
2006-07-11 21:38:27 +00:00
|
|
|
cur_rem = src_card_prev;
|
2006-09-04 19:36:09 +00:00
|
|
|
count_rem--;
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
/* if the src card is from somewhere else, just take everything */
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( src_card_prev == NOT_A_CARD )
|
|
|
|
{
|
|
|
|
if( src_col < COL_NUM )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cols[src_col] = NOT_A_CARD;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
stacks[src_col - STACKS_COL] = NOT_A_CARD;
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
deck[src_card_prev].next = NOT_A_CARD;
|
|
|
|
}
|
|
|
|
}
|
2005-12-20 22:57:04 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
2004-08-21 23:05:36 +00:00
|
|
|
/* tada ! */
|
|
|
|
return MOVE_OK;
|
|
|
|
}
|
|
|
|
|
2006-09-04 21:33:08 +00:00
|
|
|
enum { SOLITAIRE_WIN, SOLITAIRE_QUIT, SOLITAIRE_USB };
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
2006-09-04 21:33:08 +00:00
|
|
|
* Bouncing cards at the end of the game
|
2006-08-02 22:17:21 +00:00
|
|
|
*/
|
2006-09-04 21:33:08 +00:00
|
|
|
int bouncing_cards( void )
|
|
|
|
{
|
2006-09-15 06:24:36 +00:00
|
|
|
int i, j, x, vx, y, fp_y, fp_vy, button;
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-09-04 21:33:08 +00:00
|
|
|
/* flush the button queue */
|
|
|
|
while( ( button = rb->button_get( false ) ) != BUTTON_NONE )
|
|
|
|
{
|
|
|
|
if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
|
|
|
|
return SOLITAIRE_USB;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fun stuff :) */
|
|
|
|
for( i = CARDS_PER_SUIT-1; i>=0; i-- )
|
|
|
|
{
|
|
|
|
for( j = 0; j < SUITS; j++ )
|
|
|
|
{
|
2006-09-06 01:33:26 +00:00
|
|
|
x = LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*j+j+1;
|
2006-09-15 06:24:36 +00:00
|
|
|
fp_y = MARGIN<<8;
|
2006-09-04 21:33:08 +00:00
|
|
|
|
|
|
|
vx = rb->rand()%8-5;
|
|
|
|
if( !vx ) vx = -6;
|
|
|
|
|
2006-09-15 06:24:36 +00:00
|
|
|
fp_vy = -rb->rand()%(6<<8);
|
2006-09-04 21:33:08 +00:00
|
|
|
|
|
|
|
while( x < LCD_WIDTH && x + CARD_WIDTH > 0 )
|
|
|
|
{
|
2006-09-15 06:24:36 +00:00
|
|
|
fp_vy += 1<<8;
|
2006-09-04 21:33:08 +00:00
|
|
|
x += vx;
|
2006-09-15 06:24:36 +00:00
|
|
|
fp_y += fp_vy;
|
|
|
|
if( fp_y >= (LCD_HEIGHT-CARD_HEIGHT) << 8 )
|
2006-09-04 21:33:08 +00:00
|
|
|
{
|
2006-09-15 06:24:36 +00:00
|
|
|
fp_vy = -fp_vy*3/4;
|
|
|
|
fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 8;
|
2006-09-04 21:33:08 +00:00
|
|
|
}
|
2006-09-15 06:24:36 +00:00
|
|
|
y = fp_y >> 8;
|
2006-09-05 20:54:46 +00:00
|
|
|
draw_card( deck[j*CARDS_PER_SUIT+i], x, y,
|
|
|
|
false, false, false );
|
|
|
|
rb->lcd_update_rect( x<0?0:x, y<0?0:y,
|
2006-09-06 01:33:26 +00:00
|
|
|
CARD_WIDTH, CARD_HEIGHT );
|
2006-09-04 21:33:08 +00:00
|
|
|
|
2006-09-06 01:33:26 +00:00
|
|
|
button = rb->button_get_w_tmo( 2 );
|
2006-09-04 21:33:08 +00:00
|
|
|
if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
|
|
|
|
return SOLITAIRE_USB;
|
|
|
|
if( button == SOL_QUIT || button == SOL_MOVE )
|
|
|
|
return SOLITAIRE_WIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SOLITAIRE_WIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main game loop
|
|
|
|
*/
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
int solitaire( void )
|
|
|
|
{
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
int i,j;
|
2004-10-20 23:54:53 +00:00
|
|
|
int button, lastbutton = 0;
|
2005-12-20 22:57:04 +00:00
|
|
|
unsigned char c,h,prevcard;
|
2004-08-17 06:50:14 +00:00
|
|
|
int biggest_col_length;
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2005-06-26 20:12:56 +00:00
|
|
|
rb->srand( *rb->current_tick );
|
2006-09-18 00:36:09 +00:00
|
|
|
switch( solitaire_menu(false) )
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
|
|
|
case MENU_QUIT:
|
2004-10-20 23:54:53 +00:00
|
|
|
return SOLITAIRE_QUIT;
|
|
|
|
|
|
|
|
case MENU_USB:
|
|
|
|
return SOLITAIRE_USB;
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
solitaire_init();
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2005-12-20 22:57:04 +00:00
|
|
|
#if LCD_DEPTH>1
|
2006-08-02 22:17:21 +00:00
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
2005-12-20 22:57:04 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2006-08-02 22:17:21 +00:00
|
|
|
rb->lcd_set_background(BACKGROUND_COLOR);
|
2005-12-20 22:57:04 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2004-08-17 06:50:14 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
rb->lcd_set_background(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
for(i=0;i<COL_NUM;i++)
|
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
j = 0;
|
|
|
|
c = cols[i];
|
2006-08-02 22:17:21 +00:00
|
|
|
while( c != NOT_A_CARD )
|
|
|
|
{
|
2006-09-02 23:10:28 +00:00
|
|
|
if( deck[c].known ) j += 2;
|
|
|
|
else j ++;
|
2004-08-17 06:50:14 +00:00
|
|
|
c = deck[c].next;
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( j > biggest_col_length ) biggest_col_length = j;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
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 :) */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( biggest_col_length == 0 && rem == NOT_A_CARD )
|
|
|
|
{
|
2006-09-04 21:33:08 +00:00
|
|
|
rb->splash( HZ, true, "You Won :)" );
|
|
|
|
return bouncing_cards();
|
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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
for( i = 0; i < COL_NUM; i++ )
|
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
c = cols[i];
|
2005-12-20 22:57:04 +00:00
|
|
|
j = CARD_START;
|
2006-08-02 22:17:21 +00:00
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
if( c == NOT_A_CARD )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
/* draw the cursor on empty columns */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col == i )
|
|
|
|
{
|
2006-09-03 14:16:03 +00:00
|
|
|
draw_cursor( MARGIN+i*((LCD_WIDTH-2*MARGIN)/COL_NUM),
|
|
|
|
j+1 );
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-09-03 14:16:03 +00:00
|
|
|
draw_card( deck[c], MARGIN+i*((LCD_WIDTH-2*MARGIN)/COL_NUM),
|
|
|
|
j+1, c == sel_card, c == cur_card, false );
|
2006-08-02 22:17:21 +00:00
|
|
|
|
|
|
|
h = c;
|
|
|
|
c = deck[c].next;
|
|
|
|
if( c == NOT_A_CARD ) break;
|
|
|
|
|
|
|
|
/* This is where we change the spacing between cards so that
|
|
|
|
* they don't overflow out of the LCD */
|
|
|
|
if( h == cur_card )
|
|
|
|
j += SUIT_HEIGHT+2;
|
2006-09-02 23:10:28 +00:00
|
|
|
else if( deck[h].known )
|
|
|
|
j += min( SUIT_HEIGHT+2,
|
|
|
|
2*(LCD_HEIGHT - CARD_START - CARD_HEIGHT)/biggest_col_length );
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
j += min( SUIT_HEIGHT+2,
|
|
|
|
(LCD_HEIGHT - CARD_START - CARD_HEIGHT)/biggest_col_length );
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* draw the stacks */
|
|
|
|
for( i=0; i<SUITS; i++ )
|
|
|
|
{
|
|
|
|
c = find_last_card( STACKS_COL + i );
|
|
|
|
|
|
|
|
if( c != NOT_A_CARD )
|
|
|
|
{
|
|
|
|
draw_card( deck[c],
|
2006-09-06 01:33:26 +00:00
|
|
|
LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
|
2006-09-03 14:16:03 +00:00
|
|
|
MARGIN,
|
2006-08-02 22:17:21 +00:00
|
|
|
c == sel_card, cur_col == STACKS_COL + i, false );
|
2006-07-11 21:38:27 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
draw_empty_stack( i,
|
2006-09-06 01:33:26 +00:00
|
|
|
LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
|
2006-09-03 14:16:03 +00:00
|
|
|
MARGIN, cur_col == STACKS_COL + i );
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw the remains */
|
2006-09-03 16:54:42 +00:00
|
|
|
if( rem != NOT_A_CARD &&
|
|
|
|
( cur_rem == NOT_A_CARD || deck[cur_rem].next != NOT_A_CARD ) )
|
2006-08-03 20:58:35 +00:00
|
|
|
{
|
|
|
|
/* gruik ! (we want to display a card back) */
|
|
|
|
deck[rem].known = false;
|
2006-09-03 14:16:03 +00:00
|
|
|
draw_card( deck[rem], MARGIN, MARGIN, false, false, false );
|
2006-08-03 20:58:35 +00:00
|
|
|
deck[rem].known = true;
|
|
|
|
}
|
|
|
|
|
2006-09-10 20:04:17 +00:00
|
|
|
if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2006-09-10 20:04:17 +00:00
|
|
|
if( count_rem < 0 )
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2006-09-10 20:04:17 +00:00
|
|
|
prevcard = rem;
|
|
|
|
count_rem = 0;
|
|
|
|
while( prevcard != cur_rem && count_rem < cards_per_draw-1 )
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
|
|
|
prevcard = deck[prevcard].next;
|
2006-09-10 20:04:17 +00:00
|
|
|
count_rem++;
|
2006-07-11 21:38:27 +00:00
|
|
|
}
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
2006-09-10 20:04:17 +00:00
|
|
|
prevcard = cur_rem;
|
|
|
|
j = CARD_WIDTH+2*MARGIN+1;
|
|
|
|
for( i = 0; i < count_rem; i++ )
|
|
|
|
prevcard = find_prev_card(prevcard);
|
|
|
|
for( i = 0; i <= count_rem; i++ )
|
|
|
|
{
|
|
|
|
draw_card( deck[prevcard], j,
|
|
|
|
MARGIN, sel_card == prevcard,
|
|
|
|
cur_card == prevcard, i < count_rem );
|
|
|
|
prevcard = deck[prevcard].next;
|
|
|
|
j += NUMBER_WIDTH+2;
|
|
|
|
}
|
2006-09-05 21:47:31 +00:00
|
|
|
}
|
|
|
|
if( ( cur_rem == NOT_A_CARD || rem == NOT_A_CARD )
|
|
|
|
&& cur_col == REM_COL )
|
|
|
|
{
|
|
|
|
draw_cursor( CARD_WIDTH+2*MARGIN+1, MARGIN );
|
2006-08-02 22:33:34 +00:00
|
|
|
}
|
2006-07-11 21:38:27 +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 ... */
|
2006-08-02 22:17:21 +00:00
|
|
|
button = rb->button_get( true );
|
|
|
|
switch( button )
|
|
|
|
{
|
|
|
|
/* move cursor to the last card of the previous column
|
|
|
|
* or to the previous final stack
|
|
|
|
* or to the remains stack */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_RIGHT:
|
|
|
|
#ifdef SOL_RIGHT_PRE
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_RIGHT_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col >= COL_NUM )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_col = 0;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else if( cur_col == COL_NUM - 1 )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_col = REM_COL;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_col = (cur_col+1)%(REM_COL+1);
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if(cur_col == REM_COL)
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_card = cur_rem;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-02 22:17:21 +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
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* move cursor to the last card of the next column
|
|
|
|
* or to the next final stack
|
|
|
|
* or to the remains stack */
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_LEFT:
|
|
|
|
#ifdef SOL_LEFT_PRE
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_LEFT_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col == 0 )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_col = REM_COL;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else if( cur_col >= COL_NUM )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_col = COL_NUM - 1;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_col = (cur_col + REM_COL)%(REM_COL+1);
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col == REM_COL )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_card = cur_rem;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_DOWN_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
2006-09-17 22:14:18 +00:00
|
|
|
#else
|
|
|
|
case SOL_DOWN|BUTTON_REPEAT:
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
2006-08-02 22:17:21 +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;
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col == REM_COL )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_card = cur_rem;
|
2006-07-11 21:38:27 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cur_card = find_last_card( cur_col );
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_card == NOT_A_CARD ) break;
|
|
|
|
if( deck[cur_card].next != NOT_A_CARD )
|
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_card = deck[cur_card].next;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_card = cols[cur_col];
|
2006-08-02 22:17:21 +00:00
|
|
|
while( deck[ cur_card].known == 0
|
|
|
|
&& deck[cur_card].next != NOT_A_CARD )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_UP_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
2006-09-17 22:14:18 +00:00
|
|
|
#else
|
|
|
|
case SOL_UP|BUTTON_REPEAT:
|
2004-10-20 23:54:53 +00:00
|
|
|
#endif
|
2006-08-02 22:17:21 +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;
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col == REM_COL )
|
|
|
|
{
|
2004-08-21 23:05:36 +00:00
|
|
|
cur_card = cur_rem;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2006-08-02 22:17:21 +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 );
|
2004-08-21 23:05:36 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
} 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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_CUR2STACK_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-09-10 20:04:17 +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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_MOVE_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
if( sel_card == NOT_A_CARD )
|
|
|
|
{
|
|
|
|
if( cur_card != NOT_A_CARD )
|
|
|
|
{
|
|
|
|
if( deck[cur_card].next == NOT_A_CARD
|
|
|
|
&& deck[cur_card].known == 0 )
|
|
|
|
{
|
|
|
|
/* reveal a hidden card */
|
2004-08-21 23:05:36 +00:00
|
|
|
deck[cur_card].known = 1;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else if( cur_col == REM_COL && cur_rem == NOT_A_CARD )
|
|
|
|
{
|
2005-12-20 22:57:04 +00:00
|
|
|
break;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* select a card */
|
2004-08-21 23:05:36 +00:00
|
|
|
sel_card = cur_card;
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else if( sel_card == cur_card )
|
|
|
|
{
|
|
|
|
/* unselect card or try putting card on
|
|
|
|
* one of the 4 stacks */
|
2006-09-10 20:04:17 +00:00
|
|
|
if( move_card( deck[sel_card].suit + COL_NUM, sel_card )
|
|
|
|
== MOVE_OK && cur_col == REM_COL )
|
2006-07-11 21:38:27 +00:00
|
|
|
{
|
|
|
|
cur_card = cur_rem;
|
|
|
|
}
|
2006-09-10 20:04:17 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* try moving cards */
|
2006-09-10 20:04:17 +00:00
|
|
|
move_card( cur_col, sel_card );
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_REM2CUR_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-09-10 20:04:17 +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
|
|
|
|
2006-08-02 22:17:21 +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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_REM2STACK_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-09-10 20:04:17 +00:00
|
|
|
move_card( deck[cur_rem].suit + COL_NUM, cur_rem );
|
2004-08-21 23:05:36 +00:00
|
|
|
break;
|
2004-10-20 23:54:53 +00:00
|
|
|
|
2005-12-20 22:57:04 +00:00
|
|
|
#ifdef SOL_REM
|
2006-07-11 21:38:27 +00:00
|
|
|
case SOL_REM:
|
2006-08-02 22:17:21 +00:00
|
|
|
if( sel_card != NOT_A_CARD )
|
|
|
|
{
|
2005-12-20 22:57:04 +00:00
|
|
|
/* unselect selected card */
|
|
|
|
sel_card = NOT_A_CARD;
|
|
|
|
break;
|
2006-07-11 21:38:27 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
|
|
|
|
{
|
2006-09-02 21:56:22 +00:00
|
|
|
sel_card = cur_rem;
|
2006-08-02 22:17:21 +00:00
|
|
|
break;
|
2005-12-20 22:57:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2006-08-02 22:17:21 +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
|
2006-08-02 22:17:21 +00:00
|
|
|
if( lastbutton != SOL_DRAW_PRE )
|
2004-10-20 23:54:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-08-02 22:17:21 +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;
|
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
if( rem != NOT_A_CARD )
|
|
|
|
{
|
2005-06-26 19:35:29 +00:00
|
|
|
int cur_rem_old = cur_rem;
|
2006-09-04 19:36:09 +00:00
|
|
|
count_rem = -1;
|
2004-08-18 12:06:10 +00:00
|
|
|
/* draw new cards form the remains of the deck */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_rem == NOT_A_CARD )
|
|
|
|
{
|
|
|
|
/*if the cursor card is null*/
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_rem = rem;
|
2006-08-02 22:17:21 +00:00
|
|
|
i = cards_per_draw - 1;
|
2006-09-02 21:56:22 +00:00
|
|
|
count_rem++;
|
2006-08-02 22:17:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = cards_per_draw;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-07-11 21:38:27 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
while( i > 0 && deck[cur_rem].next != NOT_A_CARD )
|
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_rem = deck[cur_rem].next;
|
|
|
|
i--;
|
2006-09-02 21:56:22 +00:00
|
|
|
count_rem++;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
/* test if any cards are really left on
|
|
|
|
* the remains' stack */
|
2006-09-04 19:36:09 +00:00
|
|
|
if( i == cards_per_draw )
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
cur_rem = NOT_A_CARD;
|
2006-09-04 19:36:09 +00:00
|
|
|
count_rem = -1;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
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 */
|
2006-08-02 22:17:21 +00:00
|
|
|
if( cur_col == REM_COL && cur_card == cur_rem_old )
|
|
|
|
{
|
2005-06-26 19:35:29 +00:00
|
|
|
cur_card = cur_rem;
|
2005-12-20 22:57:04 +00:00
|
|
|
sel_card = NOT_A_CARD;
|
2006-07-11 21:38:27 +00:00
|
|
|
}
|
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 */
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef SOL_RC_QUIT
|
|
|
|
case SOL_RC_QUIT:
|
|
|
|
#endif
|
2004-10-20 23:54:53 +00:00
|
|
|
case SOL_QUIT:
|
2006-09-18 00:36:09 +00:00
|
|
|
switch( solitaire_menu(true) )
|
2006-08-02 22:17:21 +00:00
|
|
|
{
|
2004-08-17 06:50:14 +00:00
|
|
|
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
|
|
|
}
|
2006-08-02 22:17:21 +00:00
|
|
|
break;
|
|
|
|
|
2004-10-20 23:54:53 +00:00
|
|
|
default:
|
2006-08-02 22:17:21 +00:00
|
|
|
if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
|
2004-10-20 23:54:53 +00:00
|
|
|
return SOLITAIRE_USB;
|
|
|
|
break;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
if( button != BUTTON_NONE )
|
2004-10-20 23:54:53 +00:00
|
|
|
lastbutton = button;
|
2004-08-21 23:05:36 +00:00
|
|
|
|
|
|
|
/* fix incoherences concerning cur_col and cur_card */
|
2006-08-02 22:17:21 +00:00
|
|
|
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
|
|
|
|
2006-08-02 22:17:21 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/**
|
|
|
|
* Plugin entry point
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum plugin_status plugin_start( struct plugin_api* api, void* parameter )
|
2004-08-17 06:50:14 +00:00
|
|
|
{
|
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
|
|
|
(void)parameter;
|
|
|
|
rb = api;
|
2005-12-20 22:57:04 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
rb->splash( HZ, true, "Welcome to Solitaire!" );
|
2005-06-26 19:35:29 +00:00
|
|
|
|
2006-09-15 06:24:36 +00:00
|
|
|
configfile_init(rb);
|
|
|
|
configfile_load(CONFIG_FILENAME, config, 1, 0);
|
|
|
|
draw_type = draw_type_disk;
|
2006-09-17 22:14:18 +00:00
|
|
|
|
|
|
|
init_help();
|
2006-09-15 06:24:36 +00:00
|
|
|
|
2006-08-02 22:17:21 +00:00
|
|
|
/* play the game :)
|
|
|
|
* Keep playing if a game was won (that means display the menu after
|
|
|
|
* winning instead of quiting) */
|
|
|
|
while( ( result = solitaire() ) == SOLITAIRE_WIN );
|
2006-09-15 06:24:36 +00:00
|
|
|
|
|
|
|
if (draw_type != draw_type_disk)
|
|
|
|
{
|
|
|
|
draw_type_disk = draw_type;
|
|
|
|
configfile_save(CONFIG_FILENAME, config, 1, 0);
|
|
|
|
}
|
2004-08-17 06:50:14 +00:00
|
|
|
|
2004-08-18 12:06:10 +00:00
|
|
|
/* Exit the plugin */
|
2006-08-02 22:17:21 +00:00
|
|
|
return ( result == SOLITAIRE_USB ) ? PLUGIN_USB_CONNECTED : PLUGIN_OK;
|
2004-08-17 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 09:14:35 +00:00
|
|
|
#endif
|