diff options
-rw-r--r-- | apps/plugins/solitaire.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index 5ce52a81e8..cd86c34ad6 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c | |||
@@ -275,18 +275,18 @@ static char helptext[] = | |||
275 | #endif | 275 | #endif |
276 | 276 | ||
277 | #if HAVE_LCD_COLOR | 277 | #if HAVE_LCD_COLOR |
278 | static const unsigned colors[4] = { | 278 | static const fb_data colors[4] = { |
279 | LCD_BLACK, LCD_RGBPACK(255, 0, 0), LCD_BLACK, LCD_RGBPACK(255, 0, 0) | 279 | LCD_BLACK, LCD_RGBPACK(255, 0, 0), LCD_BLACK, LCD_RGBPACK(255, 0, 0) |
280 | }; | 280 | }; |
281 | #elif LCD_DEPTH > 1 | 281 | #elif LCD_DEPTH > 1 |
282 | static const unsigned colors[4] = { | 282 | static const fb_data colors[4] = { |
283 | LCD_BLACK, LCD_BRIGHTNESS(127), LCD_BLACK, LCD_BRIGHTNESS(127) | 283 | LCD_BLACK, LCD_BRIGHTNESS(127), LCD_BLACK, LCD_BRIGHTNESS(127) |
284 | }; | 284 | }; |
285 | #endif | 285 | #endif |
286 | 286 | ||
287 | #define CONFIG_FILENAME "sol.cfg" | 287 | #define CONFIG_FILENAME "sol.cfg" |
288 | 288 | ||
289 | #define NOT_A_CARD 255 | 289 | #define NOT_A_CARD -1 |
290 | 290 | ||
291 | /* number of cards per suit */ | 291 | /* number of cards per suit */ |
292 | #define CARDS_PER_SUIT 13 | 292 | #define CARDS_PER_SUIT 13 |
@@ -305,7 +305,7 @@ static char helptext[] = | |||
305 | /* column COL_NUM + SUITS corresponds to the remains' stack */ | 305 | /* column COL_NUM + SUITS corresponds to the remains' stack */ |
306 | #define REM_COL (STACKS_COL + SUITS) | 306 | #define REM_COL (STACKS_COL + SUITS) |
307 | 307 | ||
308 | #define NOT_A_COL 255 | 308 | #define NOT_A_COL -1 |
309 | 309 | ||
310 | /* background color */ | 310 | /* background color */ |
311 | #define BACKGROUND_COLOR LCD_RGBPACK(0,157,0) | 311 | #define BACKGROUND_COLOR LCD_RGBPACK(0,157,0) |
@@ -316,11 +316,11 @@ static char helptext[] = | |||
316 | 316 | ||
317 | typedef struct | 317 | typedef struct |
318 | { | 318 | { |
319 | unsigned char suit : 2; | 319 | signed char suit; |
320 | unsigned char num : 4; | 320 | signed char num; |
321 | unsigned char known : 1; | 321 | bool known : 1; |
322 | unsigned char used : 1;/* this is what is used when dealing cards */ | 322 | bool used : 1; /* this is what is used when dealing cards */ |
323 | unsigned char next; | 323 | signed char next; |
324 | } card_t; | 324 | } card_t; |
325 | 325 | ||
326 | 326 | ||
@@ -336,7 +336,7 @@ static void draw_cursor( int x, int y ) | |||
336 | } | 336 | } |
337 | 337 | ||
338 | /* Draw a card's border, select it if it's selected and draw the cursor | 338 | /* Draw a card's border, select it if it's selected and draw the cursor |
339 | * is the cursor is currently over the card */ | 339 | * if the cursor is currently over the card */ |
340 | static void draw_card_ext( int x, int y, bool selected, bool cursor ) | 340 | static void draw_card_ext( int x, int y, bool selected, bool cursor ) |
341 | { | 341 | { |
342 | #if LCD_DEPTH > 1 | 342 | #if LCD_DEPTH > 1 |
@@ -360,7 +360,7 @@ static void draw_card_ext( int x, int y, bool selected, bool cursor ) | |||
360 | } | 360 | } |
361 | 361 | ||
362 | /* Draw a card's inner graphics */ | 362 | /* Draw a card's inner graphics */ |
363 | static void draw_card( card_t card, int x, int y, | 363 | static void draw_card( card_t *card, int x, int y, |
364 | bool selected, bool cursor, bool leftstyle ) | 364 | bool selected, bool cursor, bool leftstyle ) |
365 | { | 365 | { |
366 | #ifndef HAVE_LCD_COLOR | 366 | #ifndef HAVE_LCD_COLOR |
@@ -377,7 +377,7 @@ static void draw_card( card_t card, int x, int y, | |||
377 | rb->lcd_set_drawmode( DRMODE_SOLID ); | 377 | rb->lcd_set_drawmode( DRMODE_SOLID ); |
378 | #endif | 378 | #endif |
379 | #endif | 379 | #endif |
380 | if( card.known ) | 380 | if( card->known ) |
381 | { | 381 | { |
382 | #ifdef HAVE_LCD_COLOR | 382 | #ifdef HAVE_LCD_COLOR |
383 | /* On Color LCDs we have a card back so we only need to clear | 383 | /* On Color LCDs we have a card back so we only need to clear |
@@ -387,26 +387,26 @@ static void draw_card( card_t card, int x, int y, | |||
387 | #endif | 387 | #endif |
388 | 388 | ||
389 | #if LCD_DEPTH > 1 | 389 | #if LCD_DEPTH > 1 |
390 | rb->lcd_set_foreground( colors[card.suit] ); | 390 | rb->lcd_set_foreground( colors[card->suit] ); |
391 | #endif | 391 | #endif |
392 | if( leftstyle ) | 392 | if( leftstyle ) |
393 | { | 393 | { |
394 | #if MARGIN > 0 | 394 | #if MARGIN > 0 |
395 | draw_suit( card.suit, x+1, y+2+NUMBER_HEIGHT ); | 395 | draw_suit( card->suit, x+1, y+2+NUMBER_HEIGHT ); |
396 | draw_number( card.num, x+1, y+1 ); | 396 | draw_number( card->num, x+1, y+1 ); |
397 | #else | 397 | #else |
398 | draw_suit( card.suit, x+1, y+NUMBER_HEIGHT ); | 398 | draw_suit( card->suit, x+1, y+NUMBER_HEIGHT ); |
399 | draw_number( card.num, x+1, y ); | 399 | draw_number( card->num, x+1, y ); |
400 | #endif | 400 | #endif |
401 | } | 401 | } |
402 | else | 402 | else |
403 | { | 403 | { |
404 | #if MARGIN > 0 | 404 | #if MARGIN > 0 |
405 | draw_suit( card.suit, x+2+NUMBER_WIDTH, y+1 ); | 405 | draw_suit( card->suit, x+2+NUMBER_WIDTH, y+1 ); |
406 | #else | 406 | #else |
407 | draw_suit( card.suit, x+1+NUMBER_WIDTH, y+1 ); | 407 | draw_suit( card->suit, x+1+NUMBER_WIDTH, y+1 ); |
408 | #endif | 408 | #endif |
409 | draw_number( card.num, x+1, y+1 ); | 409 | draw_number( card->num, x+1, y+1 ); |
410 | } | 410 | } |
411 | } | 411 | } |
412 | #ifdef HAVE_LCD_COLOR | 412 | #ifdef HAVE_LCD_COLOR |
@@ -667,38 +667,38 @@ int solitaire_menu(bool in_game) | |||
667 | */ | 667 | */ |
668 | 668 | ||
669 | /* player's cursor */ | 669 | /* player's cursor */ |
670 | unsigned char cur_card; | 670 | int cur_card; |
671 | /* player's cursor column num */ | 671 | /* player's cursor column num */ |
672 | unsigned char cur_col; | 672 | int cur_col; |
673 | 673 | ||
674 | /* selected card */ | 674 | /* selected card */ |
675 | unsigned char sel_card; | 675 | int sel_card; |
676 | 676 | ||
677 | /* the deck */ | 677 | /* the deck */ |
678 | card_t deck[ NUM_CARDS ]; | 678 | card_t deck[ NUM_CARDS ]; |
679 | 679 | ||
680 | /* the remaining cards */ | 680 | /* the remaining cards */ |
681 | /* first card of the remains' stack */ | 681 | /* first card of the remains' stack */ |
682 | unsigned char rem; | 682 | int rem; |
683 | /* upper visible card from the remains' stack */ | 683 | /* upper visible card from the remains' stack */ |
684 | unsigned char cur_rem; | 684 | int cur_rem; |
685 | /* number of cards drawn from the remains stack - 1 */ | 685 | /* number of cards drawn from the remains stack - 1 */ |
686 | signed char count_rem; | 686 | int count_rem; |
687 | /* number of cards per draw of the remains' stack */ | 687 | /* number of cards per draw of the remains' stack */ |
688 | signed char cards_per_draw; | 688 | int cards_per_draw; |
689 | 689 | ||
690 | /* the 7 game columns */ | 690 | /* the 7 game columns */ |
691 | unsigned char cols[COL_NUM]; | 691 | int cols[COL_NUM]; |
692 | /* the 4 final stacks */ | 692 | /* the 4 final stacks */ |
693 | unsigned char stacks[SUITS]; | 693 | int stacks[SUITS]; |
694 | 694 | ||
695 | /** | 695 | /** |
696 | * Card handling routines | 696 | * Card handling routines |
697 | */ | 697 | */ |
698 | 698 | ||
699 | unsigned char next_random_card( card_t *deck ) | 699 | int next_random_card( card_t *deck ) |
700 | { | 700 | { |
701 | unsigned char i,r; | 701 | int i,r; |
702 | 702 | ||
703 | r = rb->rand()%(NUM_CARDS)+1; | 703 | r = rb->rand()%(NUM_CARDS)+1; |
704 | i = 0; | 704 | i = 0; |
@@ -709,7 +709,7 @@ unsigned char next_random_card( card_t *deck ) | |||
709 | if( !deck[i].used ) r--; | 709 | if( !deck[i].used ) r--; |
710 | } | 710 | } |
711 | 711 | ||
712 | deck[i].used = 1; | 712 | deck[i].used = true; |
713 | 713 | ||
714 | return i; | 714 | return i; |
715 | } | 715 | } |
@@ -719,7 +719,7 @@ unsigned char next_random_card( card_t *deck ) | |||
719 | void solitaire_init( void ) | 719 | void solitaire_init( void ) |
720 | { | 720 | { |
721 | 721 | ||
722 | unsigned char c; | 722 | int c; |
723 | int i, j; | 723 | int i, j; |
724 | 724 | ||
725 | /* number of cards that are drawn on the remains' stack (by pressing F2) */ | 725 | /* number of cards that are drawn on the remains' stack (by pressing F2) */ |
@@ -740,8 +740,8 @@ void solitaire_init( void ) | |||
740 | #define card deck[i*CARDS_PER_SUIT+j] | 740 | #define card deck[i*CARDS_PER_SUIT+j] |
741 | card.suit = i; | 741 | card.suit = i; |
742 | card.num = j; | 742 | card.num = j; |
743 | card.known = 1; | 743 | card.known = true; |
744 | card.used = 0; | 744 | card.used = false; |
745 | card.next = NOT_A_CARD; | 745 | card.next = NOT_A_CARD; |
746 | #undef card | 746 | #undef card |
747 | } | 747 | } |
@@ -765,7 +765,7 @@ void solitaire_init( void ) | |||
765 | c = deck[c].next; | 765 | c = deck[c].next; |
766 | } | 766 | } |
767 | if( j < i ) | 767 | if( j < i ) |
768 | deck[c].known = 0; | 768 | deck[c].known = false; |
769 | } | 769 | } |
770 | } | 770 | } |
771 | 771 | ||
@@ -801,10 +801,10 @@ void solitaire_init( void ) | |||
801 | } | 801 | } |
802 | 802 | ||
803 | /* find the column number in which 'card' can be found */ | 803 | /* find the column number in which 'card' can be found */ |
804 | unsigned char find_card_col( unsigned char card ) | 804 | int find_card_col( int card ) |
805 | { | 805 | { |
806 | int i; | 806 | int i; |
807 | unsigned char c; | 807 | int c; |
808 | 808 | ||
809 | if( card == NOT_A_CARD ) return NOT_A_COL; | 809 | if( card == NOT_A_CARD ) return NOT_A_COL; |
810 | 810 | ||
@@ -833,7 +833,7 @@ unsigned char find_card_col( unsigned char card ) | |||
833 | 833 | ||
834 | /* find the card preceding 'card' */ | 834 | /* find the card preceding 'card' */ |
835 | /* if it doesn't exist, return NOT_A_CARD */ | 835 | /* if it doesn't exist, return NOT_A_CARD */ |
836 | unsigned char find_prev_card( unsigned char card ){ | 836 | int find_prev_card( int card ){ |
837 | int i; | 837 | int i; |
838 | 838 | ||
839 | for( i=0; i < NUM_CARDS; i++ ) | 839 | for( i=0; i < NUM_CARDS; i++ ) |
@@ -845,9 +845,9 @@ unsigned char find_prev_card( unsigned char card ){ | |||
845 | } | 845 | } |
846 | 846 | ||
847 | /* find the last card of a given column */ | 847 | /* find the last card of a given column */ |
848 | unsigned char find_last_card( unsigned char col ) | 848 | int find_last_card( int col ) |
849 | { | 849 | { |
850 | unsigned char c; | 850 | int c; |
851 | 851 | ||
852 | if( col < COL_NUM ) | 852 | if( col < COL_NUM ) |
853 | { | 853 | { |
@@ -874,16 +874,16 @@ unsigned char find_last_card( unsigned char col ) | |||
874 | 874 | ||
875 | enum move { MOVE_OK, MOVE_NOT_OK }; | 875 | enum move { MOVE_OK, MOVE_NOT_OK }; |
876 | 876 | ||
877 | enum move move_card( unsigned char dest_col, unsigned char src_card ) | 877 | enum move move_card( int dest_col, int src_card ) |
878 | { | 878 | { |
879 | /* the column on which to take src_card */ | 879 | /* the column on which to take src_card */ |
880 | unsigned char src_col; | 880 | int src_col; |
881 | 881 | ||
882 | /* the last card of dest_col */ | 882 | /* the last card of dest_col */ |
883 | unsigned char dest_card; | 883 | int dest_card; |
884 | 884 | ||
885 | /* the card under src_card */ | 885 | /* the card under src_card */ |
886 | unsigned char src_card_prev; | 886 | int src_card_prev; |
887 | 887 | ||
888 | /* you can't move no card (at least, it doesn't have any consequence) */ | 888 | /* you can't move no card (at least, it doesn't have any consequence) */ |
889 | if( src_card == NOT_A_CARD ) return MOVE_NOT_OK; | 889 | if( src_card == NOT_A_CARD ) return MOVE_NOT_OK; |
@@ -1047,7 +1047,7 @@ int bouncing_cards( void ) | |||
1047 | fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 8; | 1047 | fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 8; |
1048 | } | 1048 | } |
1049 | y = fp_y >> 8; | 1049 | y = fp_y >> 8; |
1050 | draw_card( deck[j*CARDS_PER_SUIT+i], x, y, | 1050 | draw_card( &deck[j*CARDS_PER_SUIT+i], x, y, |
1051 | false, false, false ); | 1051 | false, false, false ); |
1052 | rb->lcd_update_rect( x<0?0:x, y<0?0:y, | 1052 | rb->lcd_update_rect( x<0?0:x, y<0?0:y, |
1053 | CARD_WIDTH, CARD_HEIGHT ); | 1053 | CARD_WIDTH, CARD_HEIGHT ); |
@@ -1072,7 +1072,7 @@ int solitaire( void ) | |||
1072 | 1072 | ||
1073 | int i,j; | 1073 | int i,j; |
1074 | int button, lastbutton = 0; | 1074 | int button, lastbutton = 0; |
1075 | unsigned char c,h,prevcard; | 1075 | int c,h,prevcard; |
1076 | int biggest_col_length; | 1076 | int biggest_col_length; |
1077 | 1077 | ||
1078 | rb->srand( *rb->current_tick ); | 1078 | rb->srand( *rb->current_tick ); |
@@ -1143,7 +1143,7 @@ int solitaire( void ) | |||
1143 | break; | 1143 | break; |
1144 | } | 1144 | } |
1145 | 1145 | ||
1146 | draw_card( deck[c], MARGIN+i*((LCD_WIDTH-2*MARGIN)/COL_NUM), | 1146 | draw_card( &deck[c], MARGIN+i*((LCD_WIDTH-2*MARGIN)/COL_NUM), |
1147 | j+1, c == sel_card, c == cur_card, false ); | 1147 | j+1, c == sel_card, c == cur_card, false ); |
1148 | 1148 | ||
1149 | h = c; | 1149 | h = c; |
@@ -1170,7 +1170,7 @@ int solitaire( void ) | |||
1170 | 1170 | ||
1171 | if( c != NOT_A_CARD ) | 1171 | if( c != NOT_A_CARD ) |
1172 | { | 1172 | { |
1173 | draw_card( deck[c], | 1173 | draw_card( &deck[c], |
1174 | LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1, | 1174 | LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1, |
1175 | MARGIN, | 1175 | MARGIN, |
1176 | c == sel_card, cur_col == STACKS_COL + i, false ); | 1176 | c == sel_card, cur_col == STACKS_COL + i, false ); |
@@ -1189,7 +1189,7 @@ int solitaire( void ) | |||
1189 | { | 1189 | { |
1190 | /* gruik ! (we want to display a card back) */ | 1190 | /* gruik ! (we want to display a card back) */ |
1191 | deck[rem].known = false; | 1191 | deck[rem].known = false; |
1192 | draw_card( deck[rem], MARGIN, MARGIN, false, false, false ); | 1192 | draw_card( &deck[rem], MARGIN, MARGIN, false, false, false ); |
1193 | deck[rem].known = true; | 1193 | deck[rem].known = true; |
1194 | } | 1194 | } |
1195 | 1195 | ||
@@ -1211,7 +1211,7 @@ int solitaire( void ) | |||
1211 | prevcard = find_prev_card(prevcard); | 1211 | prevcard = find_prev_card(prevcard); |
1212 | for( i = 0; i <= count_rem; i++ ) | 1212 | for( i = 0; i <= count_rem; i++ ) |
1213 | { | 1213 | { |
1214 | draw_card( deck[prevcard], j, | 1214 | draw_card( &deck[prevcard], j, |
1215 | MARGIN, sel_card == prevcard, | 1215 | MARGIN, sel_card == prevcard, |
1216 | cur_card == prevcard, i < count_rem ); | 1216 | cur_card == prevcard, i < count_rem ); |
1217 | prevcard = deck[prevcard].next; | 1217 | prevcard = deck[prevcard].next; |
@@ -1315,7 +1315,7 @@ int solitaire( void ) | |||
1315 | else | 1315 | else |
1316 | { | 1316 | { |
1317 | cur_card = cols[cur_col]; | 1317 | cur_card = cols[cur_col]; |
1318 | while( deck[ cur_card].known == 0 | 1318 | while( !deck[ cur_card].known |
1319 | && deck[cur_card].next != NOT_A_CARD ) | 1319 | && deck[cur_card].next != NOT_A_CARD ) |
1320 | { | 1320 | { |
1321 | cur_card = deck[cur_card].next; | 1321 | cur_card = deck[cur_card].next; |
@@ -1352,7 +1352,7 @@ int solitaire( void ) | |||
1352 | cur_card = find_last_card( cur_col ); | 1352 | cur_card = find_last_card( cur_col ); |
1353 | } | 1353 | } |
1354 | } while( deck[cur_card].next != NOT_A_CARD | 1354 | } while( deck[cur_card].next != NOT_A_CARD |
1355 | && deck[cur_card].known == 0 ); | 1355 | && !deck[cur_card].known ); |
1356 | break; | 1356 | break; |
1357 | 1357 | ||
1358 | /* Try to put card under cursor on one of the stacks */ | 1358 | /* Try to put card under cursor on one of the stacks */ |
@@ -1376,10 +1376,10 @@ int solitaire( void ) | |||
1376 | if( cur_card != NOT_A_CARD ) | 1376 | if( cur_card != NOT_A_CARD ) |
1377 | { | 1377 | { |
1378 | if( deck[cur_card].next == NOT_A_CARD | 1378 | if( deck[cur_card].next == NOT_A_CARD |
1379 | && deck[cur_card].known == 0 ) | 1379 | && !deck[cur_card].known ) |
1380 | { | 1380 | { |
1381 | /* reveal a hidden card */ | 1381 | /* reveal a hidden card */ |
1382 | deck[cur_card].known = 1; | 1382 | deck[cur_card].known = true; |
1383 | } | 1383 | } |
1384 | else if( cur_col == REM_COL && cur_rem == NOT_A_CARD ) | 1384 | else if( cur_col == REM_COL && cur_rem == NOT_A_CARD ) |
1385 | { | 1385 | { |