diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-08-18 12:06:10 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-08-18 12:06:10 +0000 |
commit | f50bbce43867ddc285823c0d2c65bc42b1d8d161 (patch) | |
tree | fde8d2b5f5dc58f60e1ecd4e7b4cd0341a0c63d8 | |
parent | 8fb336148fb34474c67fbc6e0354daa4512a22fb (diff) | |
download | rockbox-f50bbce43867ddc285823c0d2c65bc42b1d8d161.tar.gz rockbox-f50bbce43867ddc285823c0d2c65bc42b1d8d161.zip |
fixed comments, added linefeeds to chop some of the longest lines
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5000 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/minesweeper.c | 264 | ||||
-rw-r--r-- | apps/plugins/solitaire.c | 635 |
2 files changed, 475 insertions, 424 deletions
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c index b155c3fbad..127d96d3d5 100644 --- a/apps/plugins/minesweeper.c +++ b/apps/plugins/minesweeper.c | |||
@@ -45,8 +45,8 @@ use F3 to see how many mines are left (supposing all your flags are correct) | |||
45 | static struct plugin_api* rb; | 45 | static struct plugin_api* rb; |
46 | 46 | ||
47 | 47 | ||
48 | //define how numbers are displayed (that way we don't have to | 48 | /* define how numbers are displayed (that way we don't have to */ |
49 | //worry about fonts) | 49 | /* worry about fonts) */ |
50 | static unsigned char num[9][8] = { | 50 | static unsigned char num[9][8] = { |
51 | /*reading the sprites: | 51 | /*reading the sprites: |
52 | on screen f123 | 52 | on screen f123 |
@@ -60,87 +60,87 @@ static unsigned char num[9][8] = { | |||
60 | ea73 | 60 | ea73 |
61 | */ | 61 | */ |
62 | 62 | ||
63 | //0 | 63 | /* 0 */ |
64 | {0x00, //........ | 64 | {0x00, /* ........ */ |
65 | 0x00, //........ | 65 | 0x00, /* ........ */ |
66 | 0x00, //........ | 66 | 0x00, /* ........ */ |
67 | 0x00, //........ | 67 | 0x00, /* ........ */ |
68 | 0x00, //........ | 68 | 0x00, /* ........ */ |
69 | 0x00, //........ | 69 | 0x00, /* ........ */ |
70 | 0x00, //........ | 70 | 0x00, /* ........ */ |
71 | 0x00},//........ | 71 | 0x00},/* ........ */ |
72 | //1 | 72 | /* 1 */ |
73 | {0x00, //........ | 73 | {0x00, /* ........ */ |
74 | 0x00, //........ | 74 | 0x00, /* ........ */ |
75 | 0x00, //...OO... | 75 | 0x00, /* ...OO... */ |
76 | 0x44, //....O... | 76 | 0x44, /* ....O... */ |
77 | 0x7c, //....O... | 77 | 0x7c, /* ....O... */ |
78 | 0x40, //....O... | 78 | 0x40, /* ....O... */ |
79 | 0x00, //...OOO.. | 79 | 0x00, /* ...OOO.. */ |
80 | 0x00},//........ | 80 | 0x00},/* ........ */ |
81 | //2 | 81 | /* 2 */ |
82 | {0x00, //........ | 82 | {0x00, /* ........ */ |
83 | 0x00, //........ | 83 | 0x00, /* ........ */ |
84 | 0x48, //...OO... | 84 | 0x48, /* ...OO... */ |
85 | 0x64, //..O..O.. | 85 | 0x64, /* ..O..O.. */ |
86 | 0x54, //....O... | 86 | 0x54, /* ....O... */ |
87 | 0x48, //...O.... | 87 | 0x48, /* ...O.... */ |
88 | 0x00, //..OOOO.. | 88 | 0x00, /* ..OOOO.. */ |
89 | 0x00},//........ | 89 | 0x00},/* ........ */ |
90 | //3 | 90 | /* 3 */ |
91 | {0x00, //........ | 91 | {0x00, /* ........ */ |
92 | 0x00, //........ | 92 | 0x00, /* ........ */ |
93 | 0x44, //..OOO... | 93 | 0x44, /* ..OOO... */ |
94 | 0x54, //.....O.. | 94 | 0x54, /* .....O.. */ |
95 | 0x54, //...OO... | 95 | 0x54, /* ...OO... */ |
96 | 0x28, //.....O.. | 96 | 0x28, /* .....O.. */ |
97 | 0x00, //..OOO... | 97 | 0x00, /* ..OOO... */ |
98 | 0x00},//........ | 98 | 0x00},/* ........ */ |
99 | //4 | 99 | /* 4 */ |
100 | {0x00, //........ | 100 | {0x00, /* ........ */ |
101 | 0x00, //........ | 101 | 0x00, /* ........ */ |
102 | 0x1c, //..O..... | 102 | 0x1c, /* ..O..... */ |
103 | 0x10, //..O..... | 103 | 0x10, /* ..O..... */ |
104 | 0x70, //..OOOO.. | 104 | 0x70, /* ..OOOO.. */ |
105 | 0x10, //....O... | 105 | 0x10, /* ....O... */ |
106 | 0x00, //....O... | 106 | 0x00, /* ....O... */ |
107 | 0x00},//........ | 107 | 0x00},/* ........ */ |
108 | //5 | 108 | /* 5 */ |
109 | {0x00, //........ | 109 | {0x00, /* ........ */ |
110 | 0x00, //........ | 110 | 0x00, /* ........ */ |
111 | 0x5c, //..OOOO.. | 111 | 0x5c, /* ..OOOO.. */ |
112 | 0x54, //..O..... | 112 | 0x54, /* ..O..... */ |
113 | 0x54, //..OOO... | 113 | 0x54, /* ..OOO... */ |
114 | 0x24, //.....O.. | 114 | 0x24, /* .....O.. */ |
115 | 0x00, //..OOO... | 115 | 0x00, /* ..OOO... */ |
116 | 0x00},//........ | 116 | 0x00},/* ........ */ |
117 | //6 | 117 | /* 6 */ |
118 | {0x00, //........ | 118 | {0x00, /* ........ */ |
119 | 0x00, //........ | 119 | 0x00, /* ........ */ |
120 | 0x38, //...OOO.. | 120 | 0x38, /* ...OOO.. */ |
121 | 0x54, //..O..... | 121 | 0x54, /* ..O..... */ |
122 | 0x54, //..OOO... | 122 | 0x54, /* ..OOO... */ |
123 | 0x24, //..O..O.. | 123 | 0x24, /* ..O..O.. */ |
124 | 0x00, //...OO... | 124 | 0x00, /* ...OO... */ |
125 | 0x00},//........ | 125 | 0x00},/* ........ */ |
126 | //7 | 126 | /* 7 */ |
127 | {0x00, //........ | 127 | {0x00, /* ........ */ |
128 | 0x00, //........ | 128 | 0x00, /* ........ */ |
129 | 0x44, //..OOOO.. | 129 | 0x44, /* ..OOOO.. */ |
130 | 0x24, //.....O.. | 130 | 0x24, /* .....O.. */ |
131 | 0x14, //....O... | 131 | 0x14, /* ....O... */ |
132 | 0x0c, //...O.... | 132 | 0x0c, /* ...O.... */ |
133 | 0x00, //..O..... | 133 | 0x00, /* ..O..... */ |
134 | 0x00},//........ | 134 | 0x00},/* ........ */ |
135 | //8 | 135 | /* 8 */ |
136 | {0x00, //........ | 136 | {0x00, /* ........ */ |
137 | 0x00, //........ | 137 | 0x00, /* ........ */ |
138 | 0x28, //...OO... | 138 | 0x28, /* ...OO... */ |
139 | 0x54, //..O..O.. | 139 | 0x54, /* ..O..O.. */ |
140 | 0x54, //...OO... | 140 | 0x54, /* ...OO... */ |
141 | 0x28, //..O..O.. | 141 | 0x28, /* ..O..O.. */ |
142 | 0x00, //...OO... | 142 | 0x00, /* ...OO... */ |
143 | 0x00},//........ | 143 | 0x00},/* ........ */ |
144 | }; | 144 | }; |
145 | 145 | ||
146 | /* the tile struct | 146 | /* the tile struct |
@@ -156,20 +156,20 @@ typedef struct tile { | |||
156 | unsigned char neighbors : 4; | 156 | unsigned char neighbors : 4; |
157 | } tile; | 157 | } tile; |
158 | 158 | ||
159 | //the height and width of the field | 159 | /* the height and width of the field */ |
160 | //could be variable if malloc worked in the API :) | 160 | /* could be variable if malloc worked in the API :) */ |
161 | const int height = LCD_HEIGHT/8; | 161 | const int height = LCD_HEIGHT/8; |
162 | const int width = LCD_WIDTH/8; | 162 | const int width = LCD_WIDTH/8; |
163 | 163 | ||
164 | //the minefield | 164 | /* the minefield */ |
165 | tile minefield[LCD_HEIGHT/8][LCD_WIDTH/8]; | 165 | tile minefield[LCD_HEIGHT/8][LCD_WIDTH/8]; |
166 | 166 | ||
167 | //total number of mines on the game | 167 | /* total number of mines on the game */ |
168 | int mine_num = 0; | 168 | int mine_num = 0; |
169 | 169 | ||
170 | //discovers the tile when player clears one of them | 170 | /* discovers the tile when player clears one of them */ |
171 | //a chain reaction (of discovery) occurs if tile has no mines | 171 | /* a chain reaction (of discovery) occurs if tile has no mines */ |
172 | //as neighbors | 172 | /* as neighbors */ |
173 | void discover(int, int); | 173 | void discover(int, int); |
174 | void discover(int x, int y){ | 174 | void discover(int x, int y){ |
175 | 175 | ||
@@ -194,7 +194,7 @@ void discover(int x, int y){ | |||
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | //init not mine related elements of the mine field | 197 | /* init not mine related elements of the mine field */ |
198 | void minesweeper_init(void){ | 198 | void minesweeper_init(void){ |
199 | int i,j; | 199 | int i,j; |
200 | 200 | ||
@@ -207,9 +207,9 @@ void minesweeper_init(void){ | |||
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | //put mines on the mine field | 210 | /* put mines on the mine field */ |
211 | //there is p% chance that a tile is a mine | 211 | /* there is p% chance that a tile is a mine */ |
212 | //if the tile has coordinates (x,y), then it can't be a mine | 212 | /* if the tile has coordinates (x,y), then it can't be a mine */ |
213 | void minesweeper_putmines(int p, int x, int y){ | 213 | void minesweeper_putmines(int p, int x, int y){ |
214 | int i,j; | 214 | int i,j; |
215 | 215 | ||
@@ -225,44 +225,49 @@ void minesweeper_putmines(int p, int x, int y){ | |||
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | //we need to compute the neighbor element for each tile | 228 | /* we need to compute the neighbor element for each tile */ |
229 | for(i=0;i<height;i++){ | 229 | for(i=0;i<height;i++){ |
230 | for(j=0;j<width;j++){ | 230 | for(j=0;j<width;j++){ |
231 | if(i>0){ | 231 | if(i>0){ |
232 | if(j>0) minefield[i][j].neighbors += minefield[i-1][j-1].mine; | 232 | if(j>0) |
233 | minefield[i][j].neighbors += minefield[i-1][j-1].mine; | ||
233 | minefield[i][j].neighbors += minefield[i-1][j].mine; | 234 | minefield[i][j].neighbors += minefield[i-1][j].mine; |
234 | if(j<width-1) minefield[i][j].neighbors += minefield[i-1][j+1].mine; | 235 | if(j<width-1) |
236 | minefield[i][j].neighbors += minefield[i-1][j+1].mine; | ||
235 | } | 237 | } |
236 | if(j>0) minefield[i][j].neighbors += minefield[i][j-1].mine; | 238 | if(j>0) |
237 | if(j<width-1) minefield[i][j].neighbors += minefield[i][j+1].mine; | 239 | minefield[i][j].neighbors += minefield[i][j-1].mine; |
240 | if(j<width-1) | ||
241 | minefield[i][j].neighbors += minefield[i][j+1].mine; | ||
238 | if(i<height-1){ | 242 | if(i<height-1){ |
239 | if(j>0) minefield[i][j].neighbors += minefield[i+1][j-1].mine; | 243 | if(j>0) |
244 | minefield[i][j].neighbors += minefield[i+1][j-1].mine; | ||
240 | minefield[i][j].neighbors += minefield[i+1][j].mine; | 245 | minefield[i][j].neighbors += minefield[i+1][j].mine; |
241 | if(j<width-1) minefield[i][j].neighbors += minefield[i+1][j+1].mine; | 246 | if(j<width-1) |
247 | minefield[i][j].neighbors += minefield[i+1][j+1].mine; | ||
242 | } | 248 | } |
243 | } | 249 | } |
244 | } | 250 | } |
245 | } | 251 | } |
246 | 252 | ||
247 | //the big and ugly function that is the game | 253 | /* the big and ugly function that is the game */ |
248 | int minesweeper(void){ | 254 | int minesweeper(void) |
249 | 255 | { | |
250 | |||
251 | int i,j; | 256 | int i,j; |
252 | 257 | ||
253 | //the cursor coordinates | 258 | /* the cursor coordinates */ |
254 | int x=0,y=0; | 259 | int x=0,y=0; |
255 | 260 | ||
256 | //number of tiles left on the game | 261 | /* number of tiles left on the game */ |
257 | int tiles_left=width*height; | 262 | int tiles_left=width*height; |
258 | 263 | ||
259 | //percentage of mines on minefield used durring generation | 264 | /* percentage of mines on minefield used durring generation */ |
260 | int p=16; | 265 | int p=16; |
261 | 266 | ||
262 | //a usefull string for snprintf | 267 | /* a usefull string for snprintf */ |
263 | char str[30]; | 268 | char str[30]; |
264 | 269 | ||
265 | //welcome screen where player can chose mine percentage | 270 | /* welcome screen where player can chose mine percentage */ |
266 | i = 0; | 271 | i = 0; |
267 | while(true){ | 272 | while(true){ |
268 | rb->lcd_clear_display(); | 273 | rb->lcd_clear_display(); |
@@ -288,14 +293,15 @@ int minesweeper(void){ | |||
288 | p = (p + 2)%100; | 293 | p = (p + 2)%100; |
289 | break; | 294 | break; |
290 | 295 | ||
291 | case BUTTON_ON://start playing | 296 | case BUTTON_ON:/* start playing */ |
292 | i = 1; | 297 | i = 1; |
293 | break; | 298 | break; |
294 | 299 | ||
295 | case BUTTON_OFF://quit program | 300 | case BUTTON_OFF:/* quit program */ |
296 | return MINESWEEPER_QUIT; | 301 | return MINESWEEPER_QUIT; |
297 | } | 302 | } |
298 | if(i==1) break; | 303 | if(i==1) |
304 | break; | ||
299 | } | 305 | } |
300 | 306 | ||
301 | 307 | ||
@@ -333,43 +339,43 @@ int minesweeper(void){ | |||
333 | } | 339 | } |
334 | } | 340 | } |
335 | 341 | ||
336 | //display the cursor | 342 | /* display the cursor */ |
337 | rb->lcd_invertrect(x*8,y*8,8,8); | 343 | rb->lcd_invertrect(x*8,y*8,8,8); |
338 | 344 | ||
339 | //update the screen | 345 | /* update the screen */ |
340 | rb->lcd_update(); | 346 | rb->lcd_update(); |
341 | 347 | ||
342 | switch(rb->button_get(true)){ | 348 | switch(rb->button_get(true)){ |
343 | //quit minesweeper (you really shouldn't use this button ...) | 349 | /* quit minesweeper (you really shouldn't use this button ...) */ |
344 | case BUTTON_OFF: | 350 | case BUTTON_OFF: |
345 | return MINESWEEPER_QUIT; | 351 | return MINESWEEPER_QUIT; |
346 | 352 | ||
347 | //move cursor left | 353 | /* move cursor left */ |
348 | case BUTTON_LEFT: | 354 | case BUTTON_LEFT: |
349 | x = (x + width - 1)%width; | 355 | x = (x + width - 1)%width; |
350 | break; | 356 | break; |
351 | 357 | ||
352 | //move cursor right | 358 | /* move cursor right */ |
353 | case BUTTON_RIGHT: | 359 | case BUTTON_RIGHT: |
354 | x = (x + 1)%width; | 360 | x = (x + 1)%width; |
355 | break; | 361 | break; |
356 | 362 | ||
357 | //move cursor down | 363 | /* move cursor down */ |
358 | case BUTTON_DOWN: | 364 | case BUTTON_DOWN: |
359 | y = (y + 1)%height; | 365 | y = (y + 1)%height; |
360 | break; | 366 | break; |
361 | 367 | ||
362 | //move cursor up | 368 | /* move cursor up */ |
363 | case BUTTON_UP: | 369 | case BUTTON_UP: |
364 | y = (y + height - 1)%height; | 370 | y = (y + height - 1)%height; |
365 | break; | 371 | break; |
366 | 372 | ||
367 | //discover a tile (and it's neighbors if .neighbors == 0) | 373 | /* discover a tile (and it's neighbors if .neighbors == 0) */ |
368 | case BUTTON_ON: | 374 | case BUTTON_ON: |
369 | case BUTTON_F2: | 375 | case BUTTON_F2: |
370 | if(minefield[y][x].flag) break; | 376 | if(minefield[y][x].flag) break; |
371 | //we put the mines on the first "click" so that you don't | 377 | /* we put the mines on the first "click" so that you don't */ |
372 | //lose on the first "click" | 378 | /* lose on the first "click" */ |
373 | if(tiles_left == width*height) minesweeper_putmines(p,x,y); | 379 | if(tiles_left == width*height) minesweeper_putmines(p,x,y); |
374 | discover(x,y); | 380 | discover(x,y); |
375 | if(minefield[y][x].mine){ | 381 | if(minefield[y][x].mine){ |
@@ -386,14 +392,14 @@ int minesweeper(void){ | |||
386 | } | 392 | } |
387 | break; | 393 | break; |
388 | 394 | ||
389 | //toggle flag under cursor | 395 | /* toggle flag under cursor */ |
390 | case BUTTON_PLAY: | 396 | case BUTTON_PLAY: |
391 | case BUTTON_F1: | 397 | case BUTTON_F1: |
392 | minefield[y][x].flag = (minefield[y][x].flag + 1)%2; | 398 | minefield[y][x].flag = (minefield[y][x].flag + 1)%2; |
393 | break; | 399 | break; |
394 | 400 | ||
395 | //show how many mines you think you have found and how many | 401 | /* show how many mines you think you have found and how many */ |
396 | //there really are on the game | 402 | /* there really are on the game */ |
397 | case BUTTON_F3: | 403 | case BUTTON_F3: |
398 | tiles_left = 0; | 404 | tiles_left = 0; |
399 | for(i=0;i<height;i++){ | 405 | for(i=0;i<height;i++){ |
@@ -408,14 +414,14 @@ int minesweeper(void){ | |||
408 | 414 | ||
409 | } | 415 | } |
410 | 416 | ||
411 | //plugin entry point | 417 | /* plugin entry point */ |
412 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 418 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
413 | { | 419 | { |
414 | //plugin init | 420 | /* plugin init */ |
415 | TEST_PLUGIN_API(api); | 421 | TEST_PLUGIN_API(api); |
416 | (void)parameter; | 422 | (void)parameter; |
417 | rb = api; | 423 | rb = api; |
418 | //end of plugin init | 424 | /* end of plugin init */ |
419 | 425 | ||
420 | switch(minesweeper()){ | 426 | switch(minesweeper()){ |
421 | case MINESWEEPER_WIN: | 427 | case MINESWEEPER_WIN: |
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index 28334437c7..04fde17415 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c | |||
@@ -60,179 +60,179 @@ static struct plugin_api* rb; | |||
60 | #define HELP_BUTTON_ON "Select cards in the columns, Move cards inside the columns, reveal hidden cards ..." | 60 | #define HELP_BUTTON_ON "Select cards in the columns, Move cards inside the columns, reveal hidden cards ..." |
61 | 61 | ||
62 | static unsigned char colors[4][8] = { | 62 | static unsigned char colors[4][8] = { |
63 | //Spades | 63 | /* Spades */ |
64 | {0x00, //........ | 64 | {0x00, /* ........ */ |
65 | 0x18, //...O.... | 65 | 0x18, /* ...O.... */ |
66 | 0x1c, //..OOO... | 66 | 0x1c, /* ..OOO... */ |
67 | 0x3e, //.OOOOO.. | 67 | 0x3e, /* .OOOOO.. */ |
68 | 0x1c, //.OOOOO.. | 68 | 0x1c, /* .OOOOO.. */ |
69 | 0x18, //...O.... | 69 | 0x18, /* ...O.... */ |
70 | 0x00, //........ | 70 | 0x00, /* ........ */ |
71 | 0x00},//........ | 71 | 0x00},/* ........ */ |
72 | //Hearts | 72 | /* Hearts */ |
73 | {0x00, //........ | 73 | {0x00, /* ........ */ |
74 | 0x0c, //..O.O... | 74 | 0x0c, /* ..O.O... */ |
75 | 0x1e, //.OOOOO.. | 75 | 0x1e, /* .OOOOO.. */ |
76 | 0x3c, //.OOOOO.. | 76 | 0x3c, /* .OOOOO.. */ |
77 | 0x1e, //..OOO... | 77 | 0x1e, /* ..OOO... */ |
78 | 0x0c, //...O.... | 78 | 0x0c, /* ...O.... */ |
79 | 0x00, //........ | 79 | 0x00, /* ........ */ |
80 | 0x00},//........ | 80 | 0x00},/* ........ */ |
81 | //Clubs | 81 | /* Clubs */ |
82 | {0x00, //........ | 82 | {0x00, /* ........ */ |
83 | 0x18, //..OOO... | 83 | 0x18, /* ..OOO... */ |
84 | 0x0a, //...O.... | 84 | 0x0a, /* ...O.... */ |
85 | 0x3e, //.OOOOO.. | 85 | 0x3e, /* .OOOOO.. */ |
86 | 0x0a, //.O.O.O.. | 86 | 0x0a, /* .O.O.O.. */ |
87 | 0x18, //...O.... | 87 | 0x18, /* ...O.... */ |
88 | 0x00, //........ | 88 | 0x00, /* ........ */ |
89 | 0x00},//........ | 89 | 0x00},/* ........ */ |
90 | //Diamonds | 90 | /* Diamonds */ |
91 | {0x00, //........ | 91 | {0x00, /* ........ */ |
92 | 0x08, //...O.... | 92 | 0x08, /* ...O.... */ |
93 | 0x1c, //..OOO... | 93 | 0x1c, /* ..OOO... */ |
94 | 0x3e, //.OOOOO.. | 94 | 0x3e, /* .OOOOO.. */ |
95 | 0x1c, //..OOO... | 95 | 0x1c, /* ..OOO... */ |
96 | 0x08, //...O.... | 96 | 0x08, /* ...O.... */ |
97 | 0x00, //........ | 97 | 0x00, /* ........ */ |
98 | 0x00} //........ | 98 | 0x00} /* ........ */ |
99 | }; | 99 | }; |
100 | 100 | ||
101 | static unsigned char numbers[13][8] = { | 101 | static unsigned char numbers[13][8] = { |
102 | //Ace | 102 | /* Ace */ |
103 | {0x00, //........ | 103 | {0x00, /* ........ */ |
104 | 0x38, //...O.... | 104 | 0x38, /* ...O.... */ |
105 | 0x14, //..O.O... | 105 | 0x14, /* ..O.O... */ |
106 | 0x12, //.O...O.. | 106 | 0x12, /* .O...O.. */ |
107 | 0x14, //.OOOOO.. | 107 | 0x14, /* .OOOOO.. */ |
108 | 0x38, //.O...O.. | 108 | 0x38, /* .O...O.. */ |
109 | 0x00, //........ | 109 | 0x00, /* ........ */ |
110 | 0x00},//........ | 110 | 0x00},/* ........ */ |
111 | //2 | 111 | /* 2 */ |
112 | {0x00, //........ | 112 | {0x00, /* ........ */ |
113 | 0x24, //..OOO... | 113 | 0x24, /* ..OOO... */ |
114 | 0x32, //.O...O.. | 114 | 0x32, /* .O...O.. */ |
115 | 0x32, //....O... | 115 | 0x32, /* ....O... */ |
116 | 0x2a, //..OO.... | 116 | 0x2a, /* ..OO.... */ |
117 | 0x24, //.OOOOO.. | 117 | 0x24, /* .OOOOO.. */ |
118 | 0x00, //........ | 118 | 0x00, /* ........ */ |
119 | 0x00},//........ | 119 | 0x00},/* ........ */ |
120 | //3 | 120 | /* 3 */ |
121 | {0x00, //........ | 121 | {0x00, /* ........ */ |
122 | 0x22, //.OOOO... | 122 | 0x22, /* .OOOO... */ |
123 | 0x2a, //.....O.. | 123 | 0x2a, /* .....O.. */ |
124 | 0x2a, //..OOO... | 124 | 0x2a, /* ..OOO... */ |
125 | 0x2a, //.....O.. | 125 | 0x2a, /* .....O.. */ |
126 | 0x14, //.OOOO... | 126 | 0x14, /* .OOOO... */ |
127 | 0x00, //........ | 127 | 0x00, /* ........ */ |
128 | 0x00},//........ | 128 | 0x00},/* ........ */ |
129 | //4 | 129 | /* 4 */ |
130 | {0x00, //........ | 130 | {0x00, /* ........ */ |
131 | 0x10, //....O... | 131 | 0x10, /* ....O... */ |
132 | 0x18, //...O.... | 132 | 0x18, /* ...O.... */ |
133 | 0x34, //..O..... | 133 | 0x34, /* ..O..... */ |
134 | 0x12, //.OOOOO.. | 134 | 0x12, /* .OOOOO.. */ |
135 | 0x10, //...O.... | 135 | 0x10, /* ...O.... */ |
136 | 0x00, //........ | 136 | 0x00, /* ........ */ |
137 | 0x00},//........ | 137 | 0x00},/* ........ */ |
138 | //5 | 138 | /* 5 */ |
139 | {0x00, //........ | 139 | {0x00, /* ........ */ |
140 | 0x2e, //.OOOOO.. | 140 | 0x2e, /* .OOOOO.. */ |
141 | 0x2a, //.O...... | 141 | 0x2a, /* .O...... */ |
142 | 0x2a, //.OOOO... | 142 | 0x2a, /* .OOOO... */ |
143 | 0x2a, //.....O.. | 143 | 0x2a, /* .....O.. */ |
144 | 0x12, //.OOOO... | 144 | 0x12, /* .OOOO... */ |
145 | 0x00, //........ | 145 | 0x00, /* ........ */ |
146 | 0x00},//........ | 146 | 0x00},/* ........ */ |
147 | //6 | 147 | /* 6 */ |
148 | {0x00, //........ | 148 | {0x00, /* ........ */ |
149 | 0x1c, //..OOO... | 149 | 0x1c, /* ..OOO... */ |
150 | 0x2a, //.O...... | 150 | 0x2a, /* .O...... */ |
151 | 0x2a, //.OOOO... | 151 | 0x2a, /* .OOOO... */ |
152 | 0x2a, //.O...O.. | 152 | 0x2a, /* .O...O.. */ |
153 | 0x10, //..OOO... | 153 | 0x10, /* ..OOO... */ |
154 | 0x00, //........ | 154 | 0x00, /* ........ */ |
155 | 0x00},//........ | 155 | 0x00},/* ........ */ |
156 | //7 | 156 | /* 7 */ |
157 | {0x00, //........ | 157 | {0x00, /* ........ */ |
158 | 0x22, //.OOOOO.. | 158 | 0x22, /* .OOOOO.. */ |
159 | 0x12, //....O... | 159 | 0x12, /* ....O... */ |
160 | 0x0a, //...O.... | 160 | 0x0a, /* ...O.... */ |
161 | 0x06, //..O..... | 161 | 0x06, /* ..O..... */ |
162 | 0x02, //.O...... | 162 | 0x02, /* .O...... */ |
163 | 0x00, //........ | 163 | 0x00, /* ........ */ |
164 | 0x00},//........ | 164 | 0x00},/* ........ */ |
165 | //8 | 165 | /* 8 */ |
166 | {0x00, //........ | 166 | {0x00, /* ........ */ |
167 | 0x14, //..OOO... | 167 | 0x14, /* ..OOO... */ |
168 | 0x2a, //.O...O.. | 168 | 0x2a, /* .O...O.. */ |
169 | 0x2a, //..OOO... | 169 | 0x2a, /* ..OOO... */ |
170 | 0x2a, //.O...O.. | 170 | 0x2a, /* .O...O.. */ |
171 | 0x14, //..OOO... | 171 | 0x14, /* ..OOO... */ |
172 | 0x00, //........ | 172 | 0x00, /* ........ */ |
173 | 0x00},//........ | 173 | 0x00},/* ........ */ |
174 | //9 | 174 | /* 9 */ |
175 | {0x00, //........ | 175 | {0x00, /* ........ */ |
176 | 0x04, //..OOO... | 176 | 0x04, /* ..OOO... */ |
177 | 0x2a, //.O...O.. | 177 | 0x2a, /* .O...O.. */ |
178 | 0x2a, //..OOOO.. | 178 | 0x2a, /* ..OOOO.. */ |
179 | 0x2a, //.....O.. | 179 | 0x2a, /* .....O.. */ |
180 | 0x1c, //..OOO... | 180 | 0x1c, /* ..OOO... */ |
181 | 0x00, //........ | 181 | 0x00, /* ........ */ |
182 | 0x00},//........ | 182 | 0x00},/* ........ */ |
183 | //10 | 183 | /* 10 */ |
184 | {0x00, //........ | 184 | {0x00, /* ........ */ |
185 | 0x3e, //.O..O... | 185 | 0x3e, /* .O..O... */ |
186 | 0x00, //.O.O.O.. | 186 | 0x00, /* .O.O.O.. */ |
187 | 0x1c, //.O.O.O.. | 187 | 0x1c, /* .O.O.O.. */ |
188 | 0x22, //.O.O.O.. | 188 | 0x22, /* .O.O.O.. */ |
189 | 0x1c, //.O..O... | 189 | 0x1c, /* .O..O... */ |
190 | 0x00, //........ | 190 | 0x00, /* ........ */ |
191 | 0x00},//........ | 191 | 0x00},/* ........ */ |
192 | //Jack | 192 | /* Jack */ |
193 | {0x00, //........ | 193 | {0x00, /* ........ */ |
194 | 0x12, //.OOOOO.. | 194 | 0x12, /* .OOOOO.. */ |
195 | 0x22, //...O.... | 195 | 0x22, /* ...O.... */ |
196 | 0x1e, //...O.... | 196 | 0x1e, /* ...O.... */ |
197 | 0x02, //.O.O.... | 197 | 0x02, /* .O.O.... */ |
198 | 0x02, //..O..... | 198 | 0x02, /* ..O..... */ |
199 | 0x00, //........ | 199 | 0x00, /* ........ */ |
200 | 0x00},//........ | 200 | 0x00},/* ........ */ |
201 | //Queen | 201 | /* Queen */ |
202 | {0x00, //........ | 202 | {0x00, /* ........ */ |
203 | 0x1c, //..OOO... | 203 | 0x1c, /* ..OOO... */ |
204 | 0x22, //.O...O.. | 204 | 0x22, /* .O...O.. */ |
205 | 0x32, //.O...O.. | 205 | 0x32, /* .O...O.. */ |
206 | 0x22, //.O.O.O.. | 206 | 0x22, /* .O.O.O.. */ |
207 | 0x1c, //..OOO... | 207 | 0x1c, /* ..OOO... */ |
208 | 0x00, //........ | 208 | 0x00, /* ........ */ |
209 | 0x00},//........ | 209 | 0x00},/* ........ */ |
210 | //King | 210 | /* King */ |
211 | {0x00, //........ | 211 | {0x00, /* ........ */ |
212 | 0x3e, //.O...O.. | 212 | 0x3e, /* .O...O.. */ |
213 | 0x08, //.O..O... | 213 | 0x08, /* .O..O... */ |
214 | 0x08, //.OOO.... | 214 | 0x08, /* .OOO.... */ |
215 | 0x14, //.O..O... | 215 | 0x14, /* .O..O... */ |
216 | 0x22, //.O...O.. | 216 | 0x22, /* .O...O.. */ |
217 | 0x00, //........ | 217 | 0x00, /* ........ */ |
218 | 0x00} //........ | 218 | 0x00} /* ........ */ |
219 | }; | 219 | }; |
220 | 220 | ||
221 | #define NOT_A_CARD 255 | 221 | #define NOT_A_CARD 255 |
222 | 222 | ||
223 | //number of cards per color | 223 | /* number of cards per color */ |
224 | #define CARDS_PER_COLOR 13 | 224 | #define CARDS_PER_COLOR 13 |
225 | 225 | ||
226 | //number of colors | 226 | /* number of colors */ |
227 | #define COLORS 4 | 227 | #define COLORS 4 |
228 | 228 | ||
229 | //number of columns | 229 | /* number of columns */ |
230 | #define COL_NUM 7 | 230 | #define COL_NUM 7 |
231 | 231 | ||
232 | //number of cards that are drawn on the remains' stack (by pressing F2) | 232 | /* number of cards that are drawn on the remains' stack (by pressing F2) */ |
233 | #define CARDS_PER_DRAW 3 | 233 | #define CARDS_PER_DRAW 3 |
234 | 234 | ||
235 | //size of a card on the screen | 235 | /* size of a card on the screen */ |
236 | #define CARD_WIDTH 14 | 236 | #define CARD_WIDTH 14 |
237 | #define CARD_HEIGHT 10 | 237 | #define CARD_HEIGHT 10 |
238 | 238 | ||
@@ -240,7 +240,7 @@ typedef struct card { | |||
240 | unsigned char color : 2; | 240 | unsigned char color : 2; |
241 | unsigned char num : 4; | 241 | unsigned char num : 4; |
242 | unsigned char known : 1; | 242 | unsigned char known : 1; |
243 | unsigned char used : 1;//this is what is used when dealing cards | 243 | unsigned char used : 1;/* this is what is used when dealing cards */ |
244 | unsigned char next; | 244 | unsigned char next; |
245 | } card; | 245 | } card; |
246 | 246 | ||
@@ -260,9 +260,9 @@ unsigned char next_random_card(card *deck){ | |||
260 | return i; | 260 | return i; |
261 | } | 261 | } |
262 | 262 | ||
263 | //help for the not so intuitive interface | 263 | /* help for the not so intuitive interface */ |
264 | void solitaire_help(void){ | 264 | void solitaire_help(void) |
265 | 265 | { | |
266 | rb->lcd_clear_display(); | 266 | rb->lcd_clear_display(); |
267 | 267 | ||
268 | rb->lcd_putsxy(0, 0, "Press a key to see"); | 268 | rb->lcd_putsxy(0, 0, "Press a key to see"); |
@@ -291,37 +291,39 @@ void solitaire_help(void){ | |||
291 | } | 291 | } |
292 | } | 292 | } |
293 | 293 | ||
294 | //menu return codes | 294 | /* menu return codes */ |
295 | #define MENU_RESUME 0 | 295 | #define MENU_RESUME 0 |
296 | #define MENU_RESTART 1 | 296 | #define MENU_RESTART 1 |
297 | #define MENU_HELP 2 | 297 | #define MENU_HELP 2 |
298 | #define MENU_QUIT 3 | 298 | #define MENU_QUIT 3 |
299 | 299 | ||
300 | //menu item number | 300 | /* menu item number */ |
301 | #define MENU_LENGTH 4 | 301 | #define MENU_LENGTH 4 |
302 | 302 | ||
303 | //different menu behaviors | 303 | /* different menu behaviors */ |
304 | #define MENU_BEFOREGAME 0 | 304 | #define MENU_BEFOREGAME 0 |
305 | #define MENU_DURINGGAME 1 | 305 | #define MENU_DURINGGAME 1 |
306 | 306 | ||
307 | //the menu | 307 | /* the menu */ |
308 | //text displayed changes depending on the 'when' parameter | 308 | /* text displayed changes depending on the 'when' parameter */ |
309 | int solitaire_menu(unsigned char when){ | 309 | int solitaire_menu(unsigned char when) { |
310 | 310 | ||
311 | static char menu[2][MENU_LENGTH][13] = | 311 | static char menu[2][MENU_LENGTH][13] = |
312 | { { "Start Game", | 312 | { { "Start Game", |
313 | "", | 313 | "", |
314 | "Help", | 314 | "Help", |
315 | "Quit" }, | 315 | "Quit" }, |
316 | { "Resume Game", | 316 | { "Resume Game", |
317 | "Restart Game", | 317 | "Restart Game", |
318 | "Help", | 318 | "Help", |
319 | "Quit"} }; | 319 | "Quit"} |
320 | }; | ||
320 | 321 | ||
321 | int i; | 322 | int i; |
322 | int cursor=0; | 323 | int cursor=0; |
323 | 324 | ||
324 | if(when!=MENU_BEFOREGAME && when!=MENU_DURINGGAME) when = MENU_DURINGGAME; | 325 | if(when!=MENU_BEFOREGAME && when!=MENU_DURINGGAME) |
326 | when = MENU_DURINGGAME; | ||
325 | 327 | ||
326 | while(1){ | 328 | while(1){ |
327 | 329 | ||
@@ -377,33 +379,33 @@ int solitaire_menu(unsigned char when){ | |||
377 | } | 379 | } |
378 | } | 380 | } |
379 | 381 | ||
380 | //player's cursor | 382 | /* player's cursor */ |
381 | unsigned char cur_card; | 383 | unsigned char cur_card; |
382 | //player's cursor column num | 384 | /* player's cursor column num */ |
383 | unsigned char cur_col; | 385 | unsigned char cur_col; |
384 | 386 | ||
385 | //selected card | 387 | /* selected card */ |
386 | unsigned char sel_card; | 388 | unsigned char sel_card; |
387 | 389 | ||
388 | //the deck | 390 | /* the deck */ |
389 | card deck[COLORS * CARDS_PER_COLOR]; | 391 | card deck[COLORS * CARDS_PER_COLOR]; |
390 | 392 | ||
391 | //the remaining cards | 393 | /* the remaining cards */ |
392 | unsigned char rem; | 394 | unsigned char rem; |
393 | unsigned char cur_rem; | 395 | unsigned char cur_rem; |
394 | 396 | ||
395 | //the 7 game columns | 397 | /* the 7 game columns */ |
396 | unsigned char cols[COL_NUM]; | 398 | unsigned char cols[COL_NUM]; |
397 | 399 | ||
398 | //the 4 final color stacks | 400 | /* the 4 final color stacks */ |
399 | unsigned char stacks[COLORS]; | 401 | unsigned char stacks[COLORS]; |
400 | 402 | ||
401 | //initialize the game | 403 | /* initialize the game */ |
402 | void solitaire_init(void){ | 404 | void solitaire_init(void){ |
403 | unsigned char c; | 405 | unsigned char c; |
404 | int i,j; | 406 | int i,j; |
405 | 407 | ||
406 | //init deck | 408 | /* init deck */ |
407 | for(i=0;i<COLORS;i++){ | 409 | for(i=0;i<COLORS;i++){ |
408 | for(j=0;j<CARDS_PER_COLOR;j++){ | 410 | for(j=0;j<CARDS_PER_COLOR;j++){ |
409 | deck[i*CARDS_PER_COLOR+j].color = i; | 411 | deck[i*CARDS_PER_COLOR+j].color = i; |
@@ -414,8 +416,8 @@ void solitaire_init(void){ | |||
414 | } | 416 | } |
415 | } | 417 | } |
416 | 418 | ||
417 | //deal the cards ... | 419 | /* deal the cards ... */ |
418 | //... in the columns | 420 | /* ... in the columns */ |
419 | for(i=0; i<COL_NUM; i++){ | 421 | for(i=0; i<COL_NUM; i++){ |
420 | c = NOT_A_CARD; | 422 | c = NOT_A_CARD; |
421 | for(j=0; j<=i; j++){ | 423 | for(j=0; j<=i; j++){ |
@@ -430,7 +432,7 @@ void solitaire_init(void){ | |||
430 | } | 432 | } |
431 | } | 433 | } |
432 | 434 | ||
433 | //... shuffle what's left of the deck | 435 | /* ... shuffle what's left of the deck */ |
434 | rem = next_random_card(deck); | 436 | rem = next_random_card(deck); |
435 | c = rem; | 437 | c = rem; |
436 | 438 | ||
@@ -439,26 +441,26 @@ void solitaire_init(void){ | |||
439 | c = deck[c].next; | 441 | c = deck[c].next; |
440 | } | 442 | } |
441 | 443 | ||
442 | //we now finished dealing the cards. The game can start ! (at last) | 444 | /* we now finished dealing the cards. The game can start ! (at last) */ |
443 | 445 | ||
444 | //init the stack | 446 | /* init the stack */ |
445 | for(i = 0; i<COL_NUM;i++){ | 447 | for(i = 0; i<COL_NUM;i++){ |
446 | stacks[i] = NOT_A_CARD; | 448 | stacks[i] = NOT_A_CARD; |
447 | } | 449 | } |
448 | 450 | ||
449 | //the cursor starts on upper left card | 451 | /* the cursor starts on upper left card */ |
450 | cur_card = cols[0]; | 452 | cur_card = cols[0]; |
451 | cur_col = 0; | 453 | cur_col = 0; |
452 | 454 | ||
453 | //no card is selected | 455 | /* no card is selected */ |
454 | sel_card = NOT_A_CARD; | 456 | sel_card = NOT_A_CARD; |
455 | 457 | ||
456 | //init the remainder | 458 | /* init the remainder */ |
457 | cur_rem = NOT_A_CARD; | 459 | cur_rem = NOT_A_CARD; |
458 | } | 460 | } |
459 | 461 | ||
460 | 462 | ||
461 | //the game | 463 | /* the game */ |
462 | void solitaire(void){ | 464 | void solitaire(void){ |
463 | 465 | ||
464 | int i,j; | 466 | int i,j; |
@@ -472,7 +474,7 @@ void solitaire(void){ | |||
472 | 474 | ||
473 | rb->lcd_clear_display(); | 475 | rb->lcd_clear_display(); |
474 | 476 | ||
475 | //get the biggest column length so that display can be "optimized" | 477 | /* get the biggest column length so that display can be "optimized" */ |
476 | biggest_col_length = 0; | 478 | biggest_col_length = 0; |
477 | 479 | ||
478 | for(i=0;i<COL_NUM;i++){ | 480 | for(i=0;i<COL_NUM;i++){ |
@@ -485,55 +487,74 @@ void solitaire(void){ | |||
485 | if(j>biggest_col_length) biggest_col_length = j; | 487 | if(j>biggest_col_length) biggest_col_length = j; |
486 | } | 488 | } |
487 | 489 | ||
488 | //check if there are cards remaining in the game. | 490 | /* check if there are cards remaining in the game. */ |
489 | //if there aren't any, that means you won :) | 491 | /* if there aren't any, that means you won :) */ |
490 | if(biggest_col_length == 0 && rem == NOT_A_CARD){ | 492 | if(biggest_col_length == 0 && rem == NOT_A_CARD){ |
491 | rb->splash(HZ*2, true, "You Won :)"); | 493 | rb->splash(HZ*2, true, "You Won :)"); |
492 | return; | 494 | return; |
493 | } | 495 | } |
494 | 496 | ||
495 | //draw the columns | 497 | /* draw the columns */ |
496 | for(i=0;i<COL_NUM;i++){ | 498 | for(i=0;i<COL_NUM;i++){ |
497 | c = cols[i]; | 499 | c = cols[i]; |
498 | j = 0; | 500 | j = 0; |
499 | while(true){ | 501 | while(true){ |
500 | if(c==NOT_A_CARD) break; | 502 | if(c==NOT_A_CARD) break; |
501 | //clear the card's spot | 503 | /* clear the card's spot */ |
502 | rb->lcd_clearrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM, j+1, CARD_WIDTH, CARD_HEIGHT-1); | 504 | rb->lcd_clearrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM, |
503 | //known card | 505 | j+1, CARD_WIDTH, CARD_HEIGHT-1); |
504 | if(deck[c].known){ | 506 | /* known card */ |
505 | rb->lcd_bitmap(numbers[deck[c].num], i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j, 8, 8, true); | 507 | if(deck[c].known) { |
506 | rb->lcd_bitmap(colors[deck[c].color], i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+7, j, 8, 8, true); | 508 | rb->lcd_bitmap(numbers[deck[c].num], |
509 | i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, | ||
510 | j, 8, 8, true); | ||
511 | rb->lcd_bitmap(colors[deck[c].color], | ||
512 | i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+7, | ||
513 | j, 8, 8, true); | ||
507 | } | 514 | } |
508 | //draw top line of the card | 515 | /* draw top line of the card */ |
509 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,j,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH-1,j); | 516 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, |
510 | //selected card | 517 | j,i*(LCD_WIDTH - CARD_WIDTH)/ |
518 | COL_NUM+CARD_WIDTH-1,j); | ||
519 | /* selected card */ | ||
511 | if(c == sel_card && sel_card != NOT_A_CARD){ | 520 | if(c == sel_card && sel_card != NOT_A_CARD){ |
512 | rb->lcd_drawrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j+1, CARD_WIDTH-1, CARD_HEIGHT-1); | 521 | rb->lcd_drawrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, |
522 | j+1, CARD_WIDTH-1, CARD_HEIGHT-1); | ||
513 | } | 523 | } |
514 | //cursor (or not) | 524 | /* cursor (or not) */ |
515 | if(c == cur_card){ | 525 | if(c == cur_card){ |
516 | rb->lcd_invertrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j+1, CARD_WIDTH-1, CARD_HEIGHT-1); | 526 | rb->lcd_invertrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, |
517 | //go to the next card | 527 | j+1, CARD_WIDTH-1, CARD_HEIGHT-1); |
528 | /* go to the next card */ | ||
518 | c = deck[c].next; | 529 | c = deck[c].next; |
519 | if(c == NOT_A_CARD) break; | 530 | if(c == NOT_A_CARD) |
531 | break; | ||
520 | j += CARD_HEIGHT - 2; | 532 | j += CARD_HEIGHT - 2; |
521 | } else { | 533 | } |
522 | //go to the next card | 534 | else { |
535 | /* go to the next card */ | ||
523 | c = deck[c].next; | 536 | c = deck[c].next; |
524 | if(c == NOT_A_CARD) break; | 537 | if(c == NOT_A_CARD) |
525 | j += min(CARD_HEIGHT - 2, (LCD_HEIGHT - CARD_HEIGHT)/biggest_col_length); | 538 | break; |
539 | j += min(CARD_HEIGHT - 2, | ||
540 | (LCD_HEIGHT - CARD_HEIGHT)/biggest_col_length); | ||
526 | } | 541 | } |
527 | } | 542 | } |
528 | //draw line to the left of the column | 543 | /* draw line to the left of the column */ |
529 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,j+CARD_HEIGHT-1); | 544 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM, |
530 | //draw line to the right of the column | 545 | 1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM, |
531 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH,1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH,j+CARD_HEIGHT-1); | 546 | j+CARD_HEIGHT-1); |
532 | //draw bottom of the last card | 547 | /* draw line to the right of the column */ |
533 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,j+CARD_HEIGHT,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH-1,j+CARD_HEIGHT); | 548 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH, |
549 | 1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH, | ||
550 | j+CARD_HEIGHT-1); | ||
551 | /* draw bottom of the last card */ | ||
552 | rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, | ||
553 | j+CARD_HEIGHT,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+ | ||
554 | CARD_WIDTH-1,j+CARD_HEIGHT); | ||
534 | } | 555 | } |
535 | 556 | ||
536 | //draw the stacks | 557 | /* draw the stacks */ |
537 | for(i=0; i<COLORS; i++){ | 558 | for(i=0; i<COLORS; i++){ |
538 | c = stacks[i]; | 559 | c = stacks[i]; |
539 | if(c!=NOT_A_CARD){ | 560 | if(c!=NOT_A_CARD){ |
@@ -542,27 +563,39 @@ void solitaire(void){ | |||
542 | } | 563 | } |
543 | } | 564 | } |
544 | if(c != NOT_A_CARD) { | 565 | if(c != NOT_A_CARD) { |
545 | rb->lcd_bitmap(numbers[deck[c].num], LCD_WIDTH - CARD_WIDTH+1, i*CARD_HEIGHT, 8, 8, true); | 566 | rb->lcd_bitmap(numbers[deck[c].num], LCD_WIDTH - CARD_WIDTH+1, |
567 | i*CARD_HEIGHT, 8, 8, true); | ||
546 | } | 568 | } |
547 | rb->lcd_bitmap(colors[i], LCD_WIDTH - CARD_WIDTH+7, i*CARD_HEIGHT, 8, 8, true); | 569 | rb->lcd_bitmap(colors[i], LCD_WIDTH - CARD_WIDTH+7, |
548 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,i*CARD_HEIGHT,LCD_WIDTH - 1,i*CARD_HEIGHT); | 570 | i*CARD_HEIGHT, 8, 8, true); |
549 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,(i+1)*CARD_HEIGHT,LCD_WIDTH - 1,(i+1)*CARD_HEIGHT); | 571 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1, |
572 | i*CARD_HEIGHT,LCD_WIDTH - 1,i*CARD_HEIGHT); | ||
573 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1, | ||
574 | (i+1)*CARD_HEIGHT,LCD_WIDTH - 1, | ||
575 | (i+1)*CARD_HEIGHT); | ||
550 | } | 576 | } |
551 | 577 | ||
552 | //draw the remains | 578 | /* draw the remains */ |
553 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,LCD_HEIGHT-CARD_HEIGHT-1,LCD_WIDTH - 1,LCD_HEIGHT-CARD_HEIGHT-1); | 579 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1, |
554 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,LCD_HEIGHT-1,LCD_WIDTH - 1,LCD_HEIGHT-1); | 580 | LCD_HEIGHT-CARD_HEIGHT-1, |
581 | LCD_WIDTH - 1,LCD_HEIGHT-CARD_HEIGHT-1); | ||
582 | rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1, | ||
583 | LCD_HEIGHT-1,LCD_WIDTH - 1,LCD_HEIGHT-1); | ||
555 | if(cur_rem != NOT_A_CARD){ | 584 | if(cur_rem != NOT_A_CARD){ |
556 | rb->lcd_bitmap(numbers[deck[cur_rem].num], LCD_WIDTH - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT, 8, 8, true); | 585 | rb->lcd_bitmap(numbers[deck[cur_rem].num], |
557 | rb->lcd_bitmap(colors[deck[cur_rem].color], LCD_WIDTH - CARD_WIDTH+7, LCD_HEIGHT-CARD_HEIGHT, 8, 8, true); | 586 | LCD_WIDTH - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT, |
587 | 8, 8, true); | ||
588 | rb->lcd_bitmap(colors[deck[cur_rem].color], | ||
589 | LCD_WIDTH - CARD_WIDTH+7, | ||
590 | LCD_HEIGHT-CARD_HEIGHT, 8, 8, true); | ||
558 | } | 591 | } |
559 | 592 | ||
560 | rb->lcd_update(); | 593 | rb->lcd_update(); |
561 | 594 | ||
562 | //what to do when a key is pressed ... | 595 | /* what to do when a key is pressed ... */ |
563 | switch(rb->button_get(true)){ | 596 | switch(rb->button_get(true)){ |
564 | 597 | ||
565 | //move cursor to the last card of the previous column | 598 | /* move cursor to the last card of the previous column */ |
566 | case BUTTON_RIGHT: | 599 | case BUTTON_RIGHT: |
567 | cur_col = (cur_col+1)%COL_NUM; | 600 | cur_col = (cur_col+1)%COL_NUM; |
568 | cur_card = cols[cur_col]; | 601 | cur_card = cols[cur_col]; |
@@ -573,7 +606,7 @@ void solitaire(void){ | |||
573 | } | 606 | } |
574 | break; | 607 | break; |
575 | 608 | ||
576 | //move cursor to the last card of the next column | 609 | /* move cursor to the last card of the next column */ |
577 | case BUTTON_LEFT: | 610 | case BUTTON_LEFT: |
578 | cur_col = (cur_col + COL_NUM - 1)%COL_NUM; | 611 | cur_col = (cur_col + COL_NUM - 1)%COL_NUM; |
579 | cur_card = cols[cur_col]; | 612 | cur_card = cols[cur_col]; |
@@ -584,7 +617,7 @@ void solitaire(void){ | |||
584 | } | 617 | } |
585 | break; | 618 | break; |
586 | 619 | ||
587 | //move cursor to card that's bellow | 620 | /* move cursor to card that's bellow */ |
588 | case BUTTON_DOWN: | 621 | case BUTTON_DOWN: |
589 | if(cur_card == NOT_A_CARD) break; | 622 | if(cur_card == NOT_A_CARD) break; |
590 | if(deck[cur_card].next != NOT_A_CARD){ | 623 | if(deck[cur_card].next != NOT_A_CARD){ |
@@ -594,7 +627,7 @@ void solitaire(void){ | |||
594 | } | 627 | } |
595 | break; | 628 | break; |
596 | 629 | ||
597 | //move cursor to card that's above | 630 | /* move cursor to card that's above */ |
598 | case BUTTON_UP: | 631 | case BUTTON_UP: |
599 | if(cur_card == NOT_A_CARD) break; | 632 | if(cur_card == NOT_A_CARD) break; |
600 | if(cols[cur_col] == cur_card){ | 633 | if(cols[cur_col] == cur_card){ |
@@ -610,61 +643,64 @@ void solitaire(void){ | |||
610 | } | 643 | } |
611 | break; | 644 | break; |
612 | 645 | ||
613 | //Try to put card under cursor on one of the stacks | 646 | /* Try to put card under cursor on one of the stacks */ |
614 | case BUTTON_F1: | 647 | case BUTTON_F1: |
615 | //check if a card is selected | 648 | /* check if a card is selected */ |
616 | //else there would be nothing to move on the stacks ! | 649 | /* else there would be nothing to move on the stacks ! */ |
617 | if(cur_card != NOT_A_CARD){ | 650 | if(cur_card != NOT_A_CARD){ |
618 | //find the last card in the color's stack and put it's number in 'c'. | 651 | /* find the last card in the color's stack and put it's number in 'c'. */ |
619 | c = stacks[deck[cur_card].color]; | 652 | c = stacks[deck[cur_card].color]; |
620 | if(c!=NOT_A_CARD){ | 653 | if(c!=NOT_A_CARD){ |
621 | while(deck[c].next!=NOT_A_CARD){ | 654 | while(deck[c].next!=NOT_A_CARD){ |
622 | c = deck[c].next; | 655 | c = deck[c].next; |
623 | } | 656 | } |
624 | } | 657 | } |
625 | //if 'c' isn't a card, that means that the stack is empty | 658 | /* if 'c' isn't a card, that means that the stack is empty */ |
626 | //which implies that only an ace can be moved | 659 | /* which implies that only an ace can be moved */ |
627 | if(c == NOT_A_CARD){ | 660 | if(c == NOT_A_CARD){ |
628 | //check if the selected card is an ace | 661 | /* check if the selected card is an ace */ |
629 | //we don't have to check if any card is in the *.next | 662 | /* we don't have to check if any card is in the *.next */ |
630 | //position since the ace is the last possible card | 663 | /* position since the ace is the last possible card */ |
631 | if(deck[cur_card].num == 0){ | 664 | if(deck[cur_card].num == 0){ |
632 | //remove 'cur_card' from any *.next postition ... | 665 | /* remove 'cur_card' from any *.next postition ... */ |
633 | //... by looking in the columns | 666 | /* ... by looking in the columns */ |
634 | for(i=0;i<COL_NUM;i++){ | 667 | for(i=0;i<COL_NUM;i++){ |
635 | if(cols[i]==cur_card) cols[i] = NOT_A_CARD; | 668 | if(cols[i]==cur_card) cols[i] = NOT_A_CARD; |
636 | } | 669 | } |
637 | //... and in the entire deck | 670 | /* ... and in the entire deck */ |
638 | //TODO : check if looking in the cols is really needed | 671 | /* TODO : check if looking in the cols is really needed */ |
639 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ | 672 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ |
640 | if(deck[i].next==cur_card) deck[i].next = NOT_A_CARD; | 673 | if(deck[i].next==cur_card) deck[i].next = NOT_A_CARD; |
641 | } | 674 | } |
642 | //move cur_card on top of the stack | 675 | /* move cur_card on top of the stack */ |
643 | stacks[deck[cur_card].color] = cur_card; | 676 | stacks[deck[cur_card].color] = cur_card; |
644 | //assign the card at the bottom of cur_col to cur_card | 677 | /* assign the card at the bottom of cur_col to cur_card */ |
645 | cur_card = cols[cur_col]; | 678 | cur_card = cols[cur_col]; |
646 | if(cur_card != NOT_A_CARD){ | 679 | if(cur_card != NOT_A_CARD){ |
647 | while(deck[cur_card].next != NOT_A_CARD){ | 680 | while(deck[cur_card].next != NOT_A_CARD){ |
648 | cur_card = deck[cur_card].next; | 681 | cur_card = deck[cur_card].next; |
649 | } | 682 | } |
650 | } | 683 | } |
651 | //clear the selection indicator | 684 | /* clear the selection indicator */ |
652 | sel_card = NOT_A_CARD; | 685 | sel_card = NOT_A_CARD; |
653 | } | 686 | } |
654 | } | 687 | } |
655 | //the stack is not empty | 688 | /* the stack is not empty */ |
656 | //so we can move any card other than an ace | 689 | /* so we can move any card other than an ace */ |
657 | //we thus check that the card we are moving is the next on the stack and that it isn't under any card | 690 | /* we thus check that the card we are moving is the next on the stack and that it isn't under any card */ |
658 | else if(deck[cur_card].num == deck[c].num + 1 && deck[cur_card].next == NOT_A_CARD){ | 691 | else if(deck[cur_card].num == deck[c].num + 1 && |
659 | //same as above | 692 | deck[cur_card].next == NOT_A_CARD) { |
660 | for(i=0;i<COL_NUM;i++){ | 693 | /* same as above */ |
661 | if(cols[i]==cur_card) cols[i] = NOT_A_CARD; | 694 | for(i=0;i<COL_NUM;i++) { |
695 | if(cols[i]==cur_card) | ||
696 | cols[i] = NOT_A_CARD; | ||
662 | } | 697 | } |
663 | //re same | 698 | /* re same */ |
664 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ | 699 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ |
665 | if(deck[i].next==cur_card) deck[i].next = NOT_A_CARD; | 700 | if(deck[i].next==cur_card) |
701 | deck[i].next = NOT_A_CARD; | ||
666 | } | 702 | } |
667 | //... | 703 | /* ... */ |
668 | deck[c].next = cur_card; | 704 | deck[c].next = cur_card; |
669 | cur_card = cols[cur_col]; | 705 | cur_card = cols[cur_col]; |
670 | if(cur_card != NOT_A_CARD){ | 706 | if(cur_card != NOT_A_CARD){ |
@@ -677,10 +713,12 @@ void solitaire(void){ | |||
677 | } | 713 | } |
678 | break; | 714 | break; |
679 | 715 | ||
680 | //Move cards arround, Uncover cards, ... | 716 | /* Move cards arround, Uncover cards, ... */ |
681 | case BUTTON_ON: | 717 | case BUTTON_ON: |
682 | if(sel_card == NOT_A_CARD) { | 718 | if(sel_card == NOT_A_CARD) { |
683 | if((cur_card != NOT_A_CARD?deck[cur_card].next == NOT_A_CARD && deck[cur_card].known==0:0)){ | 719 | if((cur_card != NOT_A_CARD? |
720 | deck[cur_card].next == NOT_A_CARD && | ||
721 | deck[cur_card].known==0:0)) { | ||
684 | deck[cur_card].known = 1; | 722 | deck[cur_card].known = 1; |
685 | } else { | 723 | } else { |
686 | sel_card = cur_card; | 724 | sel_card = cur_card; |
@@ -688,12 +726,15 @@ void solitaire(void){ | |||
688 | } else if(sel_card == cur_card) { | 726 | } else if(sel_card == cur_card) { |
689 | sel_card = NOT_A_CARD; | 727 | sel_card = NOT_A_CARD; |
690 | } else if(cur_card != NOT_A_CARD){ | 728 | } else if(cur_card != NOT_A_CARD){ |
691 | if(deck[cur_card].num == deck[sel_card].num + 1 && (deck[cur_card].color + deck[sel_card].color)%2 == 1 ){ | 729 | if(deck[cur_card].num == deck[sel_card].num + 1 && |
730 | (deck[cur_card].color + deck[sel_card].color)%2 == 1 ){ | ||
692 | for(i=0;i<COL_NUM;i++){ | 731 | for(i=0;i<COL_NUM;i++){ |
693 | if(cols[i]==sel_card) cols[i] = NOT_A_CARD; | 732 | if(cols[i]==sel_card) |
733 | cols[i] = NOT_A_CARD; | ||
694 | } | 734 | } |
695 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ | 735 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ |
696 | if(deck[i].next==sel_card) deck[i].next = NOT_A_CARD; | 736 | if(deck[i].next==sel_card) |
737 | deck[i].next = NOT_A_CARD; | ||
697 | } | 738 | } |
698 | deck[cur_card].next = sel_card; | 739 | deck[cur_card].next = sel_card; |
699 | sel_card = NOT_A_CARD; | 740 | sel_card = NOT_A_CARD; |
@@ -701,10 +742,12 @@ void solitaire(void){ | |||
701 | } else if(cur_card == NOT_A_CARD){ | 742 | } else if(cur_card == NOT_A_CARD){ |
702 | if(deck[sel_card].num == CARDS_PER_COLOR - 1){ | 743 | if(deck[sel_card].num == CARDS_PER_COLOR - 1){ |
703 | for(i=0;i<COL_NUM;i++){ | 744 | for(i=0;i<COL_NUM;i++){ |
704 | if(cols[i]==sel_card) cols[i] = NOT_A_CARD; | 745 | if(cols[i]==sel_card) |
746 | cols[i] = NOT_A_CARD; | ||
705 | } | 747 | } |
706 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ | 748 | for(i=0;i<COLORS*CARDS_PER_COLOR;i++){ |
707 | if(deck[i].next==sel_card) deck[i].next = NOT_A_CARD; | 749 | if(deck[i].next==sel_card) |
750 | deck[i].next = NOT_A_CARD; | ||
708 | } | 751 | } |
709 | cols[cur_col] = sel_card; | 752 | cols[cur_col] = sel_card; |
710 | sel_card = NOT_A_CARD; | 753 | sel_card = NOT_A_CARD; |
@@ -712,25 +755,25 @@ void solitaire(void){ | |||
712 | } | 755 | } |
713 | break; | 756 | break; |
714 | 757 | ||
715 | //If the card on the top of the remains can be put where | 758 | /* If the card on the top of the remains can be put where */ |
716 | //the cursor is, go ahead | 759 | /* the cursor is, go ahead */ |
717 | case BUTTON_PLAY: | 760 | case BUTTON_PLAY: |
718 | //check if a card is face up on the remains' stack | 761 | /* check if a card is face up on the remains' stack */ |
719 | if(cur_rem != NOT_A_CARD){ | 762 | if(cur_rem != NOT_A_CARD){ |
720 | //if no card is selected, it means the col is empty | 763 | /* if no card is selected, it means the col is empty */ |
721 | //thus, only a king can be moved | 764 | /* thus, only a king can be moved */ |
722 | if(cur_card == NOT_A_CARD){ | 765 | if(cur_card == NOT_A_CARD){ |
723 | //check if selcted card is a king | 766 | /* check if selcted card is a king */ |
724 | if(deck[cur_rem].num == CARDS_PER_COLOR - 1){ | 767 | if(deck[cur_rem].num == CARDS_PER_COLOR - 1){ |
725 | //find the previous card on the remains' stack | 768 | /* find the previous card on the remains' stack */ |
726 | c = rem; | 769 | c = rem; |
727 | //if the current card on the remains' stack | 770 | /* if the current card on the remains' stack */ |
728 | //is the first card of the stack, then ... | 771 | /* is the first card of the stack, then ... */ |
729 | if(c == cur_rem){ | 772 | if(c == cur_rem){ |
730 | c = NOT_A_CARD; | 773 | c = NOT_A_CARD; |
731 | rem = deck[cur_rem].next; | 774 | rem = deck[cur_rem].next; |
732 | } | 775 | } |
733 | //else ... | 776 | /* else ... */ |
734 | else { | 777 | else { |
735 | while(deck[c].next != cur_rem){ | 778 | while(deck[c].next != cur_rem){ |
736 | c = deck[c].next; | 779 | c = deck[c].next; |
@@ -742,7 +785,9 @@ void solitaire(void){ | |||
742 | deck[cur_rem].known = 1; | 785 | deck[cur_rem].known = 1; |
743 | cur_rem = c; | 786 | cur_rem = c; |
744 | } | 787 | } |
745 | } else if(deck[cur_rem].num + 1 == deck[cur_card].num && (deck[cur_rem].color + deck[cur_card].color)%2==1) { | 788 | } else if(deck[cur_rem].num + 1 == deck[cur_card].num && |
789 | (deck[cur_rem].color + | ||
790 | deck[cur_card].color)%2==1) { | ||
746 | c = rem; | 791 | c = rem; |
747 | if(c == cur_rem){ | 792 | if(c == cur_rem){ |
748 | c = NOT_A_CARD; | 793 | c = NOT_A_CARD; |
@@ -761,8 +806,8 @@ void solitaire(void){ | |||
761 | } | 806 | } |
762 | break; | 807 | break; |
763 | 808 | ||
764 | //If the card on top of the remains can be put on one | 809 | /* If the card on top of the remains can be put on one */ |
765 | //of the stacks, do so | 810 | /* of the stacks, do so */ |
766 | case BUTTON_F3: | 811 | case BUTTON_F3: |
767 | if(cur_rem != NOT_A_CARD){ | 812 | if(cur_rem != NOT_A_CARD){ |
768 | if(deck[cur_rem].num == 0){ | 813 | if(deck[cur_rem].num == 0){ |
@@ -807,14 +852,14 @@ void solitaire(void){ | |||
807 | } | 852 | } |
808 | break; | 853 | break; |
809 | 854 | ||
810 | //unselect selected card or ... | 855 | /* unselect selected card or ... */ |
811 | //draw new cards from the remains of the deck | 856 | /* draw new cards from the remains of the deck */ |
812 | case BUTTON_F2: | 857 | case BUTTON_F2: |
813 | if(sel_card != NOT_A_CARD){ | 858 | if(sel_card != NOT_A_CARD){ |
814 | //unselect selected card | 859 | /* unselect selected card */ |
815 | sel_card = NOT_A_CARD; | 860 | sel_card = NOT_A_CARD; |
816 | } else if(rem != NOT_A_CARD) { | 861 | } else if(rem != NOT_A_CARD) { |
817 | //draw new cards form the remains of the deck | 862 | /* draw new cards form the remains of the deck */ |
818 | if(cur_rem == NOT_A_CARD){ | 863 | if(cur_rem == NOT_A_CARD){ |
819 | cur_rem = rem; | 864 | cur_rem = rem; |
820 | i = CARDS_PER_DRAW - 1; | 865 | i = CARDS_PER_DRAW - 1; |
@@ -825,14 +870,14 @@ void solitaire(void){ | |||
825 | cur_rem = deck[cur_rem].next; | 870 | cur_rem = deck[cur_rem].next; |
826 | i--; | 871 | i--; |
827 | } | 872 | } |
828 | //test if any cards are really left on the remains' stack | 873 | /* test if any cards are really left on the remains' stack */ |
829 | if(i == CARDS_PER_DRAW){ | 874 | if(i == CARDS_PER_DRAW){ |
830 | cur_rem = NOT_A_CARD; | 875 | cur_rem = NOT_A_CARD; |
831 | } | 876 | } |
832 | } | 877 | } |
833 | break; | 878 | break; |
834 | 879 | ||
835 | //Show the menu | 880 | /* Show the menu */ |
836 | case BUTTON_OFF: | 881 | case BUTTON_OFF: |
837 | switch(solitaire_menu(MENU_DURINGGAME)){ | 882 | switch(solitaire_menu(MENU_DURINGGAME)){ |
838 | case MENU_QUIT: | 883 | case MENU_QUIT: |
@@ -848,19 +893,19 @@ void solitaire(void){ | |||
848 | 893 | ||
849 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 894 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
850 | { | 895 | { |
851 | //plugin init | 896 | /* plugin init */ |
852 | TEST_PLUGIN_API(api); | 897 | TEST_PLUGIN_API(api); |
853 | (void)parameter; | 898 | (void)parameter; |
854 | rb = api; | 899 | rb = api; |
855 | //end of plugin init | 900 | /* end of plugin init */ |
856 | 901 | ||
857 | //Welcome to Solitaire ! | 902 | /* Welcome to Solitaire ! */ |
858 | rb->splash(HZ*2, true, "Welcome to Solitaire !"); | 903 | rb->splash(HZ*2, true, "Welcome to Solitaire !"); |
859 | 904 | ||
860 | //play the game :) | 905 | /* play the game :) */ |
861 | solitaire(); | 906 | solitaire(); |
862 | 907 | ||
863 | //Exit the plugin | 908 | /* Exit the plugin */ |
864 | return PLUGIN_OK; | 909 | return PLUGIN_OK; |
865 | } | 910 | } |
866 | 911 | ||