forked from len0rd/rockbox
Fix corruption in remains stack and simplify code where possible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10924 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
87b703df2b
commit
764632c684
1 changed files with 30 additions and 45 deletions
|
|
@ -741,9 +741,9 @@ unsigned char rem;
|
||||||
/* upper visible card from the remains' stack */
|
/* upper visible card from the remains' stack */
|
||||||
unsigned char cur_rem;
|
unsigned char cur_rem;
|
||||||
/* number of cards drawn from the remains stack - 1 */
|
/* number of cards drawn from the remains stack - 1 */
|
||||||
unsigned char count_rem;
|
char count_rem;
|
||||||
/* number of cards per draw of the remains' stack */
|
/* number of cards per draw of the remains' stack */
|
||||||
int cards_per_draw;
|
char cards_per_draw;
|
||||||
|
|
||||||
/* the 7 game columns */
|
/* the 7 game columns */
|
||||||
unsigned char cols[COL_NUM];
|
unsigned char cols[COL_NUM];
|
||||||
|
|
@ -917,7 +917,6 @@ unsigned char find_last_card( unsigned char col )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//c = rem;
|
|
||||||
c = cur_rem;
|
c = cur_rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -973,7 +972,8 @@ enum move move_card( unsigned char dest_col, unsigned char src_card )
|
||||||
/* this is a winning combination */
|
/* this is a winning combination */
|
||||||
cols[dest_col] = src_card;
|
cols[dest_col] = src_card;
|
||||||
}
|
}
|
||||||
/* ... or check if the cards follow one another and have same suit */
|
/* ... or check if the cards follow one another and have
|
||||||
|
* different colorsuit */
|
||||||
else if(( deck[dest_card].suit + deck[src_card].suit)%2==1
|
else if(( deck[dest_card].suit + deck[src_card].suit)%2==1
|
||||||
&& deck[dest_card].num == deck[src_card].num + 1 )
|
&& deck[dest_card].num == deck[src_card].num + 1 )
|
||||||
{
|
{
|
||||||
|
|
@ -1012,7 +1012,7 @@ enum move move_card( unsigned char dest_col, unsigned char src_card )
|
||||||
/* ... or, well that's not good news */
|
/* ... or, well that's not good news */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* this is not a winnong combination */
|
/* this is not a winning combination */
|
||||||
return MOVE_NOT_OK;
|
return MOVE_NOT_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1031,7 +1031,6 @@ enum move move_card( unsigned char dest_col, unsigned char src_card )
|
||||||
if( src_card_prev == NOT_A_CARD )
|
if( src_card_prev == NOT_A_CARD )
|
||||||
{
|
{
|
||||||
rem = deck[src_card].next;
|
rem = deck[src_card].next;
|
||||||
//count_rem--;
|
|
||||||
}
|
}
|
||||||
/* if src card is not the first card from the stack */
|
/* if src card is not the first card from the stack */
|
||||||
else
|
else
|
||||||
|
|
@ -1260,25 +1259,30 @@ int solitaire( void )
|
||||||
deck[rem].known = true;
|
deck[rem].known = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( rem != NOT_A_CARD )
|
if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
|
||||||
{
|
{
|
||||||
if( count_rem >= cards_per_draw )
|
if( count_rem < 0 )
|
||||||
count_rem = cards_per_draw-1;
|
|
||||||
if( cur_rem != NOT_A_CARD )
|
|
||||||
{
|
{
|
||||||
prevcard = cur_rem;
|
prevcard = rem;
|
||||||
j = CARD_WIDTH+2*MARGIN+1;
|
count_rem = 0;
|
||||||
for( i = 0; i < count_rem; i++ )
|
while( prevcard != cur_rem && count_rem < cards_per_draw-1 )
|
||||||
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;
|
prevcard = deck[prevcard].next;
|
||||||
j += NUMBER_WIDTH+2;
|
count_rem++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( ( cur_rem == NOT_A_CARD || rem == NOT_A_CARD )
|
if( ( cur_rem == NOT_A_CARD || rem == NOT_A_CARD )
|
||||||
&& cur_col == REM_COL )
|
&& cur_col == REM_COL )
|
||||||
|
|
@ -1419,11 +1423,7 @@ int solitaire( void )
|
||||||
if( lastbutton != SOL_CUR2STACK_PRE )
|
if( lastbutton != SOL_CUR2STACK_PRE )
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
if( cur_card != NOT_A_CARD )
|
move_card( deck[cur_card].suit + STACKS_COL, cur_card );
|
||||||
{
|
|
||||||
move_card( deck[cur_card].suit + STACKS_COL, cur_card );
|
|
||||||
sel_card = NOT_A_CARD;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Move cards arround, Uncover cards, ... */
|
/* Move cards arround, Uncover cards, ... */
|
||||||
|
|
@ -1458,20 +1458,17 @@ int solitaire( void )
|
||||||
{
|
{
|
||||||
/* unselect card or try putting card on
|
/* unselect card or try putting card on
|
||||||
* one of the 4 stacks */
|
* one of the 4 stacks */
|
||||||
move_card( deck[sel_card].suit + COL_NUM, sel_card );
|
if( move_card( deck[sel_card].suit + COL_NUM, sel_card )
|
||||||
sel_card = NOT_A_CARD;
|
== MOVE_OK && cur_col == REM_COL )
|
||||||
if( cur_col == REM_COL )
|
|
||||||
{
|
{
|
||||||
cur_card = cur_rem;
|
cur_card = cur_rem;
|
||||||
}
|
}
|
||||||
|
sel_card = NOT_A_CARD;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* try moving cards */
|
/* try moving cards */
|
||||||
if( move_card( cur_col, sel_card ) == MOVE_OK )
|
move_card( cur_col, sel_card );
|
||||||
{
|
|
||||||
sel_card = NOT_A_CARD;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -1482,11 +1479,7 @@ int solitaire( void )
|
||||||
if( lastbutton != SOL_REM2CUR_PRE )
|
if( lastbutton != SOL_REM2CUR_PRE )
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
if( move_card( cur_col, cur_rem ) == MOVE_OK )
|
move_card( cur_col, cur_rem );
|
||||||
{
|
|
||||||
//count_rem--;
|
|
||||||
sel_card = NOT_A_CARD;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* If the card on top of the remains can be put on one
|
/* If the card on top of the remains can be put on one
|
||||||
|
|
@ -1496,15 +1489,7 @@ int solitaire( void )
|
||||||
if( lastbutton != SOL_REM2STACK_PRE )
|
if( lastbutton != SOL_REM2STACK_PRE )
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
if( cur_rem != NOT_A_CARD )
|
move_card( deck[cur_rem].suit + COL_NUM, cur_rem );
|
||||||
{
|
|
||||||
if( move_card( deck[cur_rem].suit + COL_NUM, cur_rem )
|
|
||||||
== MOVE_OK )
|
|
||||||
{
|
|
||||||
sel_card = NOT_A_CARD;
|
|
||||||
//count_rem--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef SOL_REM
|
#ifdef SOL_REM
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue