summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/minesweeper.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index bf71436464..d7e19e9423 100644
--- a/apps/plugins/minesweeper.c
+++ b/apps/plugins/minesweeper.c
@@ -33,7 +33,7 @@ use F3 to see how many mines are left (supposing all your flags are correct)
33 33
34#ifdef HAVE_LCD_BITMAP 34#ifdef HAVE_LCD_BITMAP
35 35
36//what the minesweeper() function can return 36//what the minesweeper() function can return
37#define MINESWEEPER_USB 3 37#define MINESWEEPER_USB 3
38#define MINESWEEPER_QUIT 2 38#define MINESWEEPER_QUIT 2
39#define MINESWEEPER_LOSE 1 39#define MINESWEEPER_LOSE 1
@@ -81,13 +81,13 @@ static unsigned char num[9][8] = {
81 4567 81 4567
82 890a 82 890a
83 bcde 83 bcde
84 84
85 in binary b84f 85 in binary b84f
86 c951 86 c951
87 d062 87 d062
88 ea73 88 ea73
89 */ 89 */
90 90
91 /* 0 */ 91 /* 0 */
92 {0x00, /* ........ */ 92 {0x00, /* ........ */
93 0x00, /* ........ */ 93 0x00, /* ........ */
@@ -185,9 +185,8 @@ typedef struct tile {
185} tile; 185} tile;
186 186
187/* the height and width of the field */ 187/* the height and width of the field */
188/* could be variable if malloc worked in the API :) */ 188int height = LCD_HEIGHT/8;
189const int height = LCD_HEIGHT/8; 189int width = LCD_WIDTH/8;
190const int width = LCD_WIDTH/8;
191 190
192/* the minefield */ 191/* the minefield */
193tile minefield[LCD_HEIGHT/8][LCD_WIDTH/8]; 192tile minefield[LCD_HEIGHT/8][LCD_WIDTH/8];
@@ -200,13 +199,13 @@ int mine_num = 0;
200/* as neighbors */ 199/* as neighbors */
201void discover(int, int); 200void discover(int, int);
202void discover(int x, int y){ 201void discover(int x, int y){
203 202
204 if(x<0) return; 203 if(x<0) return;
205 if(y<0) return; 204 if(y<0) return;
206 if(x>width-1) return; 205 if(x>width-1) return;
207 if(y>height-1) return; 206 if(y>height-1) return;
208 if(minefield[y][x].known) return; 207 if(minefield[y][x].known) return;
209 208
210 minefield[y][x].known = 1; 209 minefield[y][x].known = 1;
211 if(minefield[y][x].neighbors == 0){ 210 if(minefield[y][x].neighbors == 0){
212 discover(x-1,y-1); 211 discover(x-1,y-1);
@@ -225,7 +224,7 @@ void discover(int x, int y){
225/* init not mine related elements of the mine field */ 224/* init not mine related elements of the mine field */
226void minesweeper_init(void){ 225void minesweeper_init(void){
227 int i,j; 226 int i,j;
228 227
229 for(i=0;i<height;i++){ 228 for(i=0;i<height;i++){
230 for(j=0;j<width;j++){ 229 for(j=0;j<width;j++){
231 minefield[i][j].known = 0; 230 minefield[i][j].known = 0;
@@ -253,7 +252,7 @@ void minesweeper_putmines(int p, int x, int y){
253 minefield[i][j].neighbors = 0; 252 minefield[i][j].neighbors = 0;
254 } 253 }
255 } 254 }
256 255
257 /* we need to compute the neighbor element for each tile */ 256 /* we need to compute the neighbor element for each tile */
258 for(i=0;i<height;i++){ 257 for(i=0;i<height;i++){
259 for(j=0;j<width;j++){ 258 for(j=0;j<width;j++){
@@ -285,10 +284,10 @@ int minesweeper(void)
285 int i,j; 284 int i,j;
286 int button; 285 int button;
287 int lastbutton = BUTTON_NONE; 286 int lastbutton = BUTTON_NONE;
288 287
289 /* the cursor coordinates */ 288 /* the cursor coordinates */
290 int x=0,y=0; 289 int x=0,y=0;
291 290
292 /* number of tiles left on the game */ 291 /* number of tiles left on the game */
293 int tiles_left=width*height; 292 int tiles_left=width*height;
294 293
@@ -302,18 +301,21 @@ int minesweeper(void)
302 i = 0; 301 i = 0;
303 while(true){ 302 while(true){
304 rb->lcd_clear_display(); 303 rb->lcd_clear_display();
305 304
306 rb->lcd_puts(0,0,"Mine Sweeper"); 305 rb->lcd_puts(0,0,"Mine Sweeper");
307 306
308 rb->snprintf(str, 20, "%d%% mines", p); 307 rb->snprintf(str, 20, "%d%% mines", p);
309 rb->lcd_puts(0,1,str); 308 rb->lcd_puts(0,2,str);
310 rb->lcd_puts(0,2,"down / up"); 309 rb->lcd_puts(0,3,"down / up");
310 rb->snprintf(str, 20, "%d cols x %d rows", width, height);
311 rb->lcd_puts(0,4,str);
312 rb->lcd_puts(0,5,"left x right ");
311#if CONFIG_KEYPAD == RECORDER_PAD 313#if CONFIG_KEYPAD == RECORDER_PAD
312 rb->lcd_puts(0,4,"ON to start"); 314 rb->lcd_puts(0,6,"ON to start");
313#elif CONFIG_KEYPAD == ONDIO_PAD 315#elif CONFIG_KEYPAD == ONDIO_PAD
314 rb->lcd_puts(0,4,"MODE to start"); 316 rb->lcd_puts(0,6,"MODE to start");
315#elif CONFIG_KEYPAD == IRIVER_H100_PAD 317#elif CONFIG_KEYPAD == IRIVER_H100_PAD
316 rb->lcd_puts(0,4,"SELECT to start"); 318 rb->lcd_puts(0,6,"SELECT to start");
317#endif 319#endif
318 320
319 rb->lcd_update(); 321 rb->lcd_update();
@@ -322,15 +324,21 @@ int minesweeper(void)
322 button = rb->button_get(true); 324 button = rb->button_get(true);
323 switch(button){ 325 switch(button){
324 case BUTTON_DOWN: 326 case BUTTON_DOWN:
325 case BUTTON_LEFT:
326 p = (p + 98)%100; 327 p = (p + 98)%100;
327 break; 328 break;
328 329
329 case BUTTON_UP: 330 case BUTTON_UP:
330 case BUTTON_RIGHT:
331 p = (p + 2)%100; 331 p = (p + 2)%100;
332 break; 332 break;
333 333
334 case BUTTON_RIGHT:
335 height = height%(LCD_HEIGHT/8)+1;
336 break;
337
338 case BUTTON_LEFT:
339 width = width%(LCD_WIDTH/8)+1;
340 break;
341
334 case MINESWP_START:/* start playing */ 342 case MINESWP_START:/* start playing */
335 i = 1; 343 i = 1;
336 break; 344 break;
@@ -346,7 +354,7 @@ int minesweeper(void)
346 if(i==1) 354 if(i==1)
347 break; 355 break;
348 } 356 }
349 357
350 358
351 /******************** 359 /********************
352 * init * 360 * init *
@@ -359,10 +367,10 @@ int minesweeper(void)
359 **********************/ 367 **********************/
360 368
361 while(true){ 369 while(true){
362 370
363 //clear the screen buffer 371 //clear the screen buffer
364 rb->lcd_clear_display(); 372 rb->lcd_clear_display();
365 373
366 //display the mine field 374 //display the mine field
367 for(i=0;i<height;i++){ 375 for(i=0;i<height;i++){
368 for(j=0;j<width;j++){ 376 for(j=0;j<width;j++){
@@ -371,8 +379,8 @@ int minesweeper(void)
371 if(minefield[i][j].mine){ 379 if(minefield[i][j].mine){
372 rb->lcd_putsxy(j*8+1,i*8+1,"b"); 380 rb->lcd_putsxy(j*8+1,i*8+1,"b");
373 } else if(minefield[i][j].neighbors){ 381 } else if(minefield[i][j].neighbors){
374 rb->lcd_bitmap(num[minefield[i][j].neighbors],j*8,i*8,8,8,false); 382 rb->lcd_bitmap(num[minefield[i][j].neighbors],j*8,i*8,8,8,false);
375 } 383 }
376 } else if(minefield[i][j].flag) { 384 } else if(minefield[i][j].flag) {
377 rb->lcd_drawline(j*8+2,i*8+2,j*8+5,i*8+5); 385 rb->lcd_drawline(j*8+2,i*8+2,j*8+5,i*8+5);
378 rb->lcd_drawline(j*8+2,i*8+5,j*8+5,i*8+2); 386 rb->lcd_drawline(j*8+2,i*8+5,j*8+5,i*8+2);
@@ -389,31 +397,31 @@ int minesweeper(void)
389 397
390 /* update the screen */ 398 /* update the screen */
391 rb->lcd_update(); 399 rb->lcd_update();
392 400
393 button = rb->button_get(true); 401 button = rb->button_get(true);
394 switch(button){ 402 switch(button){
395 /* quit minesweeper (you really shouldn't use this button ...) */ 403 /* quit minesweeper (you really shouldn't use this button ...) */
396 case MINESWP_QUIT: 404 case MINESWP_QUIT:
397 return MINESWEEPER_QUIT; 405 return MINESWEEPER_QUIT;
398 406
399 /* move cursor left */ 407 /* move cursor left */
400 case BUTTON_LEFT: 408 case BUTTON_LEFT:
401 case (BUTTON_LEFT | BUTTON_REPEAT): 409 case (BUTTON_LEFT | BUTTON_REPEAT):
402 x = (x + width - 1)%width; 410 x = (x + width - 1)%width;
403 break; 411 break;
404 412
405 /* move cursor right */ 413 /* move cursor right */
406 case BUTTON_RIGHT: 414 case BUTTON_RIGHT:
407 case (BUTTON_RIGHT | BUTTON_REPEAT): 415 case (BUTTON_RIGHT | BUTTON_REPEAT):
408 x = (x + 1)%width; 416 x = (x + 1)%width;
409 break; 417 break;
410 418
411 /* move cursor down */ 419 /* move cursor down */
412 case BUTTON_DOWN: 420 case BUTTON_DOWN:
413 case (BUTTON_DOWN | BUTTON_REPEAT): 421 case (BUTTON_DOWN | BUTTON_REPEAT):
414 y = (y + 1)%height; 422 y = (y + 1)%height;
415 break; 423 break;
416 424
417 /* move cursor up */ 425 /* move cursor up */
418 case BUTTON_UP: 426 case BUTTON_UP:
419 case (BUTTON_UP | BUTTON_REPEAT): 427 case (BUTTON_UP | BUTTON_REPEAT):
@@ -442,8 +450,8 @@ int minesweeper(void)
442 if(tiles_left == mine_num){ 450 if(tiles_left == mine_num){
443 return MINESWEEPER_WIN; 451 return MINESWEEPER_WIN;
444 } 452 }
445 break; 453 break;
446 454
447 /* toggle flag under cursor */ 455 /* toggle flag under cursor */
448 case MINESWP_TOGGLE: 456 case MINESWP_TOGGLE:
449#ifdef MINESWP_TOGGLE_PRE 457#ifdef MINESWP_TOGGLE_PRE
@@ -476,7 +484,7 @@ int minesweeper(void)
476 if (button != BUTTON_NONE) 484 if (button != BUTTON_NONE)
477 lastbutton = button; 485 lastbutton = button;
478 } 486 }
479 487
480} 488}
481 489
482/* plugin entry point */ 490/* plugin entry point */
@@ -494,18 +502,18 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
494 case MINESWEEPER_WIN: 502 case MINESWEEPER_WIN:
495 rb->splash(HZ*2, true, "You Win :)"); 503 rb->splash(HZ*2, true, "You Win :)");
496 break; 504 break;
497 505
498 case MINESWEEPER_LOSE: 506 case MINESWEEPER_LOSE:
499 rb->splash(HZ*2, true, "You Lost :("); 507 rb->splash(HZ*2, true, "You Lost :(");
500 break; 508 break;
501 509
502 case MINESWEEPER_USB: 510 case MINESWEEPER_USB:
503 return PLUGIN_USB_CONNECTED; 511 return PLUGIN_USB_CONNECTED;
504 512
505 case MINESWEEPER_QUIT: 513 case MINESWEEPER_QUIT:
506 exit = true; 514 exit = true;
507 break; 515 break;
508 516
509 default: 517 default:
510 break; 518 break;
511 } 519 }