1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2004-2006 Antoine Cellerier <dionoea @t videolan d.t org>
*
* 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
Graphics & Fix Bugs by Ben Basha
use arrows to move the cursor
use ON to select cards, move cards, reveal hidden cards, ...
use PLAY to move a card from the remains' stack to the top of the cursor
use F1 to put card under cursor on one of the 4 final stacks
use F2 to un-select card if a card was selected, else draw 3 new cards
out of the remains' stack
use F3 to put card on top of the remains' stack on one of the 4 final stacks
*****************************************************************************/
#include "plugin.h"
#include "configfile.h"
#include "button.h"
#include "lcd.h"
#ifdef HAVE_LCD_BITMAP
PLUGIN_HEADER
static struct plugin_api* rb;
#define min(a,b) (a<b?a:b)
/**
* Key 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_F1
# define SOL_REM2CUR BUTTON_PLAY
# define SOL_CUR2STACK BUTTON_F2
# define SOL_REM2STACK BUTTON_F3
# define HK_MOVE "ON"
# define HK_DRAW "F1"
# define HK_REM2CUR "PLAY"
# define HK_CUR2STACK "F2"
# define HK_REM2STACK "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_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)
# define HK_MOVE "MODE"
# define HK_DRAW "MODE.."
# define HK_REM2CUR "DOWN.."
# define HK_CUR2STACK "UP.."
# define HK_REM2STACK "RIGHT.."
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
(CONFIG_KEYPAD == IRIVER_H300_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_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
# define HK_MOVE "NAVI"
# define HK_DRAW "A-B"
# define HK_REM2CUR "PLAY+LEFT"
# define HK_CUR2STACK "NAVI.."
# define HK_REM2STACK "PLAY+RIGHT"
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) ||(CONFIG_KEYPAD == IPOD_3G_PAD)
# define SOL_QUIT (BUTTON_SELECT | BUTTON_MENU)
# 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)
# define HK_UD "SCROLL U/D"
# define HK_MOVE "SELECT"
# define HK_DRAW "MENU"
# define HK_REM2CUR "PLAY"
# define HK_CUR2STACK "MENU.."
# define HK_REM2STACK "RIGHT.."
#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
# 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"
# define HK_CUR2STACK "REC+UP"
# define HK_REM2STACK "REC+DOWN"
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
# 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"
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
# 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"
#else
# error "Unknown keypad"
#endif
#define HK_LR "LEFT/RIGHT"
#ifndef HK_UD
# define HK_UD "UP/DOWN"
#endif
/**
* Help strings
*/
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"
;
/**
* Misc constants, graphics and other defines
*/
#include "solitaire_cardback.h"
#include "solitaire_deck.h"
#include "solitaire_suitsi.h"
#define CARD_GFX_WIDTH BMPWIDTH_solitaire_cardback
#define CARD_GFX_HEIGHT BMPHEIGHT_solitaire_cardback
#define CARD_WIDTH (BMPWIDTH_solitaire_cardback+2)
#define CARD_HEIGHT (BMPHEIGHT_solitaire_cardback+2)
#if LCD_WIDTH >= 320
# define MARGIN 4
# define LARGE_CARD
# define SYMBOL_HEIGHT 12
#elif LCD_WIDTH >= 220
# define MARGIN 3
# define LARGE_CARD
# define SYMBOL_HEIGHT 12
#elif LCD_WIDTH >= 160
# define MARGIN 2
# define SYMBOL_HEIGHT 11
#elif LCD_WIDTH >= 128
# define MARGIN 1
# define SYMBOL_HEIGHT 10
#else
# define MARGIN 0
# define SYMBOL_HEIGHT 8
#endif
#define CARD_START (CARD_HEIGHT+2*MARGIN+1)
/* background color */
#ifdef HAVE_LCD_COLOR
# define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
#elif LCD_DEPTH > 1
# define BACKGROUND_COLOR LCD_WHITE
#endif
#define CONFIG_FILENAME "sol.cfg"
#define NOT_A_CARD -1
/* number of cards per suit */
#define CARDS_PER_SUIT 13
/* number of suits */
#define SUITS 4
#define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
/* number of columns */
#define COL_NUM 7
/* pseudo column numbers to be used for cursor coordinates */
/* columns COL_NUM to COL_NUM + SUITS - 1 correspond to the final stacks */
#define STACKS_COL COL_NUM
/* column COL_NUM + SUITS corresponds to the remains' stack */
#define REM_COL (STACKS_COL + SUITS)
#define NOT_A_COL -1
typedef struct
{
signed char suit;
signed char num;
bool known : 1;
bool used : 1; /* this is what is used when dealing cards */
signed char next;
} card_t;
/**
* LCD card drawing routines
*/
static void draw_cursor( int x, int y )
{
rb->lcd_set_drawmode( DRMODE_COMPLEMENT );
rb->lcd_fillrect( x+1, y+1, CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
#ifdef LARGE_CARD
rb->lcd_drawpixel( x+1, y+1 );
rb->lcd_drawpixel( x+1, y+CARD_HEIGHT-2 );
rb->lcd_drawpixel( x+CARD_WIDTH-2, y+1 );
rb->lcd_drawpixel( x+CARD_WIDTH-2, y+CARD_HEIGHT-2 );
#endif
rb->lcd_set_drawmode( DRMODE_SOLID );
}
/* Draw a card's border, select it if it's selected and draw the cursor
* if 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
#ifdef LARGE_CARD
rb->lcd_hline( x+2, x+CARD_WIDTH-3, y );
rb->lcd_hline( x+2, x+CARD_WIDTH-3, y+CARD_HEIGHT-1 );
rb->lcd_vline( x, y+2, y+CARD_HEIGHT-3 );
rb->lcd_vline( x+CARD_WIDTH-1, y+2, y+CARD_HEIGHT-3 );
rb->lcd_drawpixel( x+1, y+1 );
rb->lcd_drawpixel( x+1, y+CARD_HEIGHT-2 );
rb->lcd_drawpixel( x+CARD_WIDTH-2, y+1 );
rb->lcd_drawpixel( x+CARD_WIDTH-2, y+CARD_HEIGHT-2 );
#else
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 );
#endif
if( selected )
{
rb->lcd_drawrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
#ifdef LARGE_CARD
rb->lcd_drawrect( x+2, y+2, CARD_WIDTH-4, CARD_HEIGHT-4 );
#endif
}
if( cursor )
{
draw_cursor( x, y );
}
}
/* Draw a card's inner graphics */
static void draw_card( card_t *card, int x, int y,
bool selected, bool cursor )
{
if( card->known )
{
rb->lcd_bitmap_part( solitaire_deck, CARD_GFX_WIDTH * card->num,
CARD_GFX_HEIGHT * card->suit, BMPWIDTH_solitaire_deck,
x+1, y+1, CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
}
else
{
rb->lcd_bitmap( solitaire_cardback, x+1, y+1,
CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
}
draw_card_ext( x, y, selected, cursor );
}
/* Draw an empty stack */
static void draw_empty_stack( int s, int x, int y, bool cursor )
{
rb->lcd_bitmap_part( solitaire_suitsi, 0,
CARD_GFX_HEIGHT * s, BMPWIDTH_solitaire_suitsi,
x+1, y+1, CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
draw_card_ext( x, y, false, cursor );
}
/**
* Help
*/
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;
}
enum help { HELP_QUIT, HELP_USB };
/* help for the not so intuitive interface */
enum help solitaire_help( void )
{
int start = 0;
int button;
int lastbutton = BUTTON_NONE;
bool fixed = (displaylines >= helplines);
while( true )
{
char *text = helptext;
int line = fixed ? (displaylines - helplines) / 2 : 0;
int i;
rb->lcd_clear_display();
for (i = 0; i < start + displaylines; i++)
{
if (i >= start)
rb->lcd_puts(0, line++, text);
text += rb->strlen(text) + 1;
}
rb->lcd_update();
button = rb->button_get( true );
switch( button )
{
case SOL_UP:
#ifdef SOL_UP_PRE
if( lastbutton != SOL_UP_PRE )
break;
#else
case SOL_UP|BUTTON_REPEAT:
#endif
if (!fixed && start > 0)
start--;
break;
case SOL_DOWN:
#ifdef SOL_DOWN_PRE
if( lastbutton != SOL_DOWN_PRE )
break;
#else
case SOL_DOWN|BUTTON_REPEAT:
#endif
if (!fixed && start < helplines - displaylines)
start++;
break;
#ifdef SOL_RC_QUIT
case SOL_RC_QUIT:
#endif
case SOL_QUIT:
return HELP_QUIT;
default:
if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
return HELP_USB;
break;
}
if( button != BUTTON_NONE )
lastbutton = button;
}
}
/**
* Custom menu / options
*/
#define CFGFILE_VERSION 0
/* introduce a struct if there's more than one setting */
int draw_type_disk = 0;
int draw_type;
static struct configdata config[] = {
{ TYPE_INT, 0, 1, &draw_type_disk, "draw_type", NULL, NULL }
};
char draw_option_string[32];
static void create_draw_option_string(void)
{
if (draw_type == 0)
rb->strcpy(draw_option_string, "Draw Three Cards");
else
rb->strcpy(draw_option_string, "Draw One Card");
}
void solitaire_init(void);
/* menu return codes */
enum { MENU_RESUME, MENU_QUIT, MENU_USB };
int solitaire_menu(bool in_game)
{
int m;
int result = -1;
int i = 0;
struct menu_item items[4];
#if LCD_DEPTH > 1
rb->lcd_set_foreground(LCD_DEFAULT_FG);
rb->lcd_set_background(LCD_DEFAULT_BG);
#endif
if (in_game)
{
items[i++].desc = "Resume Game";
items[i++].desc = "Restart Game";
}
else
{
items[i++].desc = "Start Game";
items[i++].desc = draw_option_string;
}
items[i++].desc = "Help";
items[i++].desc = "Quit";
create_draw_option_string();
m = rb->menu_init(items, i, NULL, NULL, NULL, NULL);
while (result < 0)
{
switch (rb->menu_show(m))
{
case MENU_SELECTED_EXIT:
result = MENU_RESUME;
break;
case MENU_ATTACHED_USB:
result = MENU_USB;
break;
case 0:
result = MENU_RESUME;
break;
case 1:
if (in_game)
{
solitaire_init();
result = MENU_RESUME;
}
else
{
draw_type = (draw_type + 1) % 2;
create_draw_option_string();
}
break;
case 2:
rb->lcd_setmargins(0, 0);
if (solitaire_help() == HELP_USB)
result = MENU_USB;
break;
case 3:
result = MENU_QUIT;
break;
}
}
rb->menu_exit(m);
rb->lcd_setmargins(0, 0);
return result;
}
/**
* Global variables
*/
/* player's cursor */
int cur_card;
/* player's cursor column num */
int cur_col;
/* selected card */
int sel_card;
/* the deck */
card_t deck[ NUM_CARDS ];
/* the remaining cards */
/* first card of the remains' stack */
int rem;
/* upper visible card from the remains' stack */
int cur_rem;
/* number of cards drawn from the remains stack - 1 */
int count_rem;
/* number of cards per draw of the remains' stack */
int cards_per_draw;
/* the 7 game columns */
int cols[COL_NUM];
/* the 4 final stacks */
int stacks[SUITS];
/**
* Card handling routines
*/
int next_random_card( card_t *deck )
{
int 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 = true;
return i;
}
/* initialize the game */
void solitaire_init( void )
{
int c;
int i, j;
/* number of cards that are drawn on the remains' stack (by pressing F2) */
if( draw_type == 0 )
{
cards_per_draw = 3;
}
else
{
cards_per_draw = 1;
}
/* init deck */
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 = true;
card.used = false;
card.next = NOT_A_CARD;
#undef card
}
}
/* deal the cards ... */
/* ... in the columns */
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;
}
if( j < i )
deck[c].known = false;
}
}
/* ... shuffle what's left of the deck */
rem = next_random_card(deck);
c = rem;
for( i=1; i < NUM_CARDS - COL_NUM * (COL_NUM + 1)/2; i++ )
{
deck[c].next = next_random_card( deck );
c = deck[c].next;
}
/* we now finished dealing the cards. The game can start ! (at last) */
/* init the stack */
for( i = 0; i<SUITS; i++ )
{
stacks[i] = NOT_A_CARD;
}
/* the cursor starts on upper left card */
cur_card = cols[0];
cur_col = 0;
/* no card is selected */
sel_card = NOT_A_CARD;
/* init the remainder */
cur_rem = NOT_A_CARD;
count_rem = -1;
}
/* find the column number in which 'card' can be found */
int find_card_col( int card )
{
int i;
int 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;
}
}
for( i=0; i<SUITS; i++ )
{
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 */
int find_prev_card( int card ){
int i;
for( i=0; i < NUM_CARDS; i++ )
{
if( deck[i].next == card ) return i;
}
return NOT_A_CARD;
}
/* find the last card of a given column */
int find_last_card( int col )
{
int c;
if( col < COL_NUM )
{
c = cols[col];
}
else if( col < REM_COL )
{
c = stacks[col - STACKS_COL];
}
else
{
c = cur_rem;
}
if(c == NOT_A_CARD)
return c;
else
{
while(deck[c].next != NOT_A_CARD)
c = deck[c].next;
return c;
}
}
enum move { MOVE_OK, MOVE_NOT_OK };
enum move move_card( int dest_col, int src_card )
{
/* the column on which to take src_card */
int src_col;
/* the last card of dest_col */
int dest_card;
/* the card under src_card */
int src_card_prev;
/* 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;
/* you can't move an unknown card */
if( !deck[src_card].known ) return MOVE_NOT_OK;
src_col = find_card_col( src_card );
dest_card = find_last_card( dest_col );
src_card_prev = find_prev_card( src_card );
/* you can't move more than one card at a time from the final stack */
/* 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;
}
/* 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
&& deck[src_card].num == CARDS_PER_SUIT - 1 )
{
/* this is a winning combination */
cols[dest_col] = src_card;
}
/* ... or check if the cards follow one another and have
* different colorsuit */
else if(( deck[dest_card].suit + deck[src_card].suit)%2==1
&& 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;
}
}
/* if we are on one of the 4 final stacks ... */
else if( dest_col < REM_COL )
{
/* ... check if we are on an empty stack, that the src is an
* ace and that this is the good final stack */
if( dest_card == NOT_A_CARD
&& deck[src_card].num == 0
&& deck[src_card].suit == dest_col - STACKS_COL )
{
/* this is a winning combination */
stacks[dest_col - STACKS_COL] = src_card;
}
/* ... or check if the cards follow one another, have the same
* suit and {that src has no .next element or is from the remains'
* stack} */
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) )
{
/* this is a winning combination */
deck[dest_card].next = src_card;
}
/* ... or, well that's not good news */
else
{
/* this is not a winning 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;
}
/* 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;
}
deck[src_card].next = NOT_A_CARD;
cur_rem = src_card_prev;
count_rem--;
}
/* 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;
}
}
sel_card = NOT_A_CARD;
/* tada ! */
return MOVE_OK;
}
enum { SOLITAIRE_WIN, SOLITAIRE_QUIT, SOLITAIRE_USB };
/**
* Bouncing cards at the end of the game
*/
#define BC_ACCEL ((1<<16)*LCD_HEIGHT/128)
#define BC_MYSPEED (6*BC_ACCEL)
#define BC_MXSPEED (6*LCD_HEIGHT/128)
int bouncing_cards( void )
{
int i, j, x, vx, y, fp_y, fp_vy, button;
/* 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++ )
{
x = LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*j+j+1;
fp_y = MARGIN<<16;
#if LCD_WIDTH > 200
vx = rb->rand() % (4*BC_MXSPEED/3-2) - BC_MXSPEED;
if( vx >= -1 )
vx += 3;
#else
vx = rb->rand() % (4*BC_MXSPEED/3) - BC_MXSPEED;
if( vx >= 0 )
vx++;
#endif
fp_vy = -rb->rand() % BC_MYSPEED;
while( x < LCD_WIDTH && x + CARD_WIDTH > 0 )
{
fp_vy += BC_ACCEL;
x += vx;
fp_y += fp_vy;
if( fp_y >= (LCD_HEIGHT-CARD_HEIGHT) << 16 )
{
fp_vy = -fp_vy*4/5;
fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 16;
}
y = fp_y >> 16;
draw_card( &deck[j*CARDS_PER_SUIT+i], x, y,
false, false );
rb->lcd_update_rect( x<0?0:x, y<0?0:y,
CARD_WIDTH, CARD_HEIGHT );
button = rb->button_get_w_tmo( 2 );
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
*/
int solitaire( void )
{
int i,j;
int button, lastbutton = 0;
int c,h,prevcard;
int biggest_col_length;
rb->srand( *rb->current_tick );
switch( solitaire_menu(false) )
{
case MENU_QUIT:
return SOLITAIRE_QUIT;
case MENU_USB:
return SOLITAIRE_USB;
}
solitaire_init();
while( true )
{
#if LCD_DEPTH>1
rb->lcd_set_background(BACKGROUND_COLOR);
#endif
rb->lcd_clear_display();
#if LCD_DEPTH > 1
rb->lcd_set_foreground(LCD_BLACK);
rb->lcd_set_background(LCD_WHITE);
#endif
/* get the biggest column length so that display can be "optimized" */
biggest_col_length = 0;
for(i=0;i<COL_NUM;i++)
{
j = 0;
c = cols[i];
if( c != NOT_A_CARD )
{
while( true )
{
/* don't include the last card in the column length. */
if( deck[c].next == NOT_A_CARD )
{
break; /* no successor: get outta here. */
}
else
{
if( deck[c].known )
j += 2;
else
j++;
}
c = deck[c].next;
}
/* make column distinguishable from an empty column,
* and avoid division by zero while displaying */
if( j == 0 )
j = 1;
}
if( j > biggest_col_length )
biggest_col_length = j;
}
/* check if there are cards remaining in the game. */
/* if there aren't any, that means you won :) */
if( biggest_col_length == 0 && rem == NOT_A_CARD )
{
rb->splash( HZ, true, "You Won :)" );
return bouncing_cards();
}
/* draw the columns */
for( i = 0; i < COL_NUM; i++ )
{
c = cols[i];
j = CARD_START;
while( true )
{
if( c == NOT_A_CARD )
{
/* draw the cursor on empty columns */
if( cur_col == i )
{
draw_cursor( MARGIN + i * (CARD_WIDTH
+(LCD_WIDTH-COL_NUM*CARD_WIDTH-2*MARGIN)/(COL_NUM-1)),
j );
}
break;
}
draw_card( &deck[c], MARGIN + i * (CARD_WIDTH
+(LCD_WIDTH-COL_NUM*CARD_WIDTH-2*MARGIN)/(COL_NUM-1)),
j, c == sel_card, c == cur_card );
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 += SYMBOL_HEIGHT;
else if( deck[h].known )
j += min( SYMBOL_HEIGHT,
2 * (LCD_HEIGHT - CARD_START - CARD_HEIGHT - MARGIN)
/ biggest_col_length );
else
j += min( SYMBOL_HEIGHT / 2,
(LCD_HEIGHT - CARD_START - CARD_HEIGHT - MARGIN)
/ biggest_col_length );
}
}
/* 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],
LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
MARGIN,
c == sel_card, cur_col == STACKS_COL + i );
}
else
{
draw_empty_stack( i,
LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
MARGIN, cur_col == STACKS_COL + i );
}
}
/* draw the remains */
if( rem != NOT_A_CARD &&
( cur_rem == NOT_A_CARD || deck[cur_rem].next != NOT_A_CARD ) )
{
/* gruik ! (we want to display a card back) */
deck[rem].known = false;
draw_card( &deck[rem], MARGIN, MARGIN, false, false );
deck[rem].known = true;
}
if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
{
if( count_rem < 0 )
{
prevcard = rem;
count_rem = 0;
while( prevcard != cur_rem && count_rem < cards_per_draw-1 )
{
prevcard = deck[prevcard].next;
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 );
prevcard = deck[prevcard].next;
j += CARD_WIDTH/2;
}
}
if( ( cur_rem == NOT_A_CARD || rem == NOT_A_CARD )
&& cur_col == REM_COL )
{
draw_cursor( CARD_WIDTH+2*MARGIN+1, MARGIN );
}
rb->lcd_update();
/* what to do when a key is pressed ... */
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 */
case SOL_RIGHT:
#ifdef SOL_RIGHT_PRE
if( lastbutton != SOL_RIGHT_PRE )
break;
#endif
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);
}
if(cur_col == REM_COL)
{
cur_card = cur_rem;
break;
}
cur_card = find_last_card( cur_col );
break;
/* move cursor to the last card of the next column
* or to the next final stack
* or to the remains stack */
case SOL_LEFT:
#ifdef SOL_LEFT_PRE
if( lastbutton != SOL_LEFT_PRE )
break;
#endif
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;
}
cur_card = find_last_card( cur_col );
break;
/* move cursor to card that's bellow */
case SOL_DOWN:
#ifdef SOL_DOWN_PRE
if( lastbutton != SOL_DOWN_PRE )
break;
#else
case SOL_DOWN|BUTTON_REPEAT:
#endif
if( cur_col >= COL_NUM )
{
cur_col = (cur_col - COL_NUM + 1)%(SUITS + 1) + COL_NUM;
if( cur_col == REM_COL )
{
cur_card = cur_rem;
}
else
{
cur_card = find_last_card( cur_col );
}
break;
}
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];
while( !deck[ cur_card].known
&& deck[cur_card].next != NOT_A_CARD )
{
cur_card = deck[cur_card].next;
}
}
break;
/* move cursor to card that's above */
case SOL_UP:
#ifdef SOL_UP_PRE
if( lastbutton != SOL_UP_PRE )
break;
#else
case SOL_UP|BUTTON_REPEAT:
#endif
if( cur_col >= COL_NUM )
{
cur_col = (cur_col - COL_NUM + SUITS)%(SUITS + 1) + COL_NUM;
if( cur_col == REM_COL )
{
cur_card = cur_rem;
}
else
{
cur_card = find_last_card( cur_col );
}
break;
}
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 );
break;
/* Try to put card under cursor on one of the stacks */
case SOL_CUR2STACK:
#ifdef SOL_CUR2STACK_PRE
if( lastbutton != SOL_CUR2STACK_PRE )
break;
#endif
move_card( deck[cur_card].suit + STACKS_COL, cur_card );
break;
/* Move cards arround, Uncover cards, ... */
case SOL_MOVE:
#ifdef SOL_MOVE_PRE
if( lastbutton != SOL_MOVE_PRE )
break;
#endif
if( sel_card == NOT_A_CARD )
{
if( cur_card != NOT_A_CARD )
{
if( deck[cur_card].next == NOT_A_CARD
&& !deck[cur_card].known )
{
/* reveal a hidden card */
deck[cur_card].known = true;
}
else if( cur_col == REM_COL && cur_rem == NOT_A_CARD )
{
break;
}
else
{
/* select a card */
sel_card = cur_card;
}
}
}
else if( sel_card == cur_card )
{
/* unselect card or try putting card on
* one of the 4 stacks */
if( move_card( deck[sel_card].suit + COL_NUM, sel_card )
== MOVE_OK && cur_col == REM_COL )
{
cur_card = cur_rem;
}
sel_card = NOT_A_CARD;
}
else
{
/* try moving cards */
move_card( cur_col, sel_card );
}
break;
/* If the card on the top of the remains can be put where
* the cursor is, go ahead */
case SOL_REM2CUR:
#ifdef SOL_REM2CUR_PRE
if( lastbutton != SOL_REM2CUR_PRE )
break;
#endif
move_card( cur_col, cur_rem );
break;
/* If the card on top of the remains can be put on one
* of the stacks, do so */
case SOL_REM2STACK:
#ifdef SOL_REM2STACK_PRE
if( lastbutton != SOL_REM2STACK_PRE )
break;
#endif
move_card( deck[cur_rem].suit + COL_NUM, cur_rem );
break;
#ifdef SOL_REM
case SOL_REM:
if( sel_card != NOT_A_CARD )
{
/* unselect selected card */
sel_card = NOT_A_CARD;
break;
}
if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
{
sel_card = cur_rem;
break;
}
break;
#endif
/* unselect selected card or ...
* draw new cards from the remains of the deck */
case SOL_DRAW:
#ifdef SOL_DRAW_PRE
if( lastbutton != SOL_DRAW_PRE )
break;
#endif
if( sel_card != NOT_A_CARD )
{
/* unselect selected card */
sel_card = NOT_A_CARD;
break;
}
if( rem != NOT_A_CARD )
{
int cur_rem_old = cur_rem;
count_rem = -1;
/* draw new cards form the remains of the deck */
if( cur_rem == NOT_A_CARD )
{
/*if the cursor card is null*/
cur_rem = rem;
i = cards_per_draw - 1;
count_rem++;
}
else
{
i = cards_per_draw;
}
while( i > 0 && deck[cur_rem].next != NOT_A_CARD )
{
cur_rem = deck[cur_rem].next;
i--;
count_rem++;
}
/* test if any cards are really left on
* the remains' stack */
if( i == cards_per_draw )
{
cur_rem = NOT_A_CARD;
count_rem = -1;
}
/* 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;
sel_card = NOT_A_CARD;
}
}
break;
/* Show the menu */
#ifdef SOL_RC_QUIT
case SOL_RC_QUIT:
#endif
case SOL_QUIT:
switch( solitaire_menu(true) )
{
case MENU_QUIT:
return SOLITAIRE_QUIT;
case MENU_USB:
return SOLITAIRE_USB;
}
break;
default:
if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
return SOLITAIRE_USB;
break;
}
if( button != BUTTON_NONE )
lastbutton = button;
/* 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 );
if( cur_card == NOT_A_CARD
&& find_last_card( cur_col ) != NOT_A_CARD )
cur_card = find_last_card( cur_col );
}
}
/**
* Plugin entry point
*/
enum plugin_status plugin_start( struct plugin_api* api, void* parameter )
{
int result;
/* plugin init */
(void)parameter;
rb = api;
rb->splash( HZ, true, "Welcome to Solitaire!" );
configfile_init(rb);
configfile_load(CONFIG_FILENAME, config, 1, 0);
draw_type = draw_type_disk;
init_help();
/* 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 );
if (draw_type != draw_type_disk)
{
draw_type_disk = draw_type;
configfile_save(CONFIG_FILENAME, config, 1, 0);
}
/* Exit the plugin */
return ( result == SOLITAIRE_USB ) ? PLUGIN_USB_CONNECTED : PLUGIN_OK;
}
#endif
|