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 /apps/plugins/minesweeper.c | |
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
Diffstat (limited to 'apps/plugins/minesweeper.c')
-rw-r--r-- | apps/plugins/minesweeper.c | 264 |
1 files changed, 135 insertions, 129 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: |