summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-08-18 12:06:10 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-08-18 12:06:10 +0000
commitf50bbce43867ddc285823c0d2c65bc42b1d8d161 (patch)
treefde8d2b5f5dc58f60e1ecd4e7b4cd0341a0c63d8 /apps/plugins
parent8fb336148fb34474c67fbc6e0354daa4512a22fb (diff)
downloadrockbox-f50bbce43867ddc285823c0d2c65bc42b1d8d161.zip
rockbox-f50bbce43867ddc285823c0d2c65bc42b1d8d161.tar.gz
rockbox-f50bbce43867ddc285823c0d2c65bc42b1d8d161.tar.bz2
rockbox-f50bbce43867ddc285823c0d2c65bc42b1d8d161.tar.xz
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')
-rw-r--r--apps/plugins/minesweeper.c264
-rw-r--r--apps/plugins/solitaire.c635
2 files changed, 475 insertions, 424 deletions
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index b155c3f..127d96d 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)
static struct plugin_api* rb;
-//define how numbers are displayed (that way we don't have to
-//worry about fonts)
+/* define how numbers are displayed (that way we don't have to */
+/* worry about fonts) */
static unsigned char num[9][8] = {
/*reading the sprites:
on screen f123
@@ -60,87 +60,87 @@ static unsigned char num[9][8] = {
ea73
*/
- //0
- {0x00, //........
- 0x00, //........
- 0x00, //........
- 0x00, //........
- 0x00, //........
- 0x00, //........
- 0x00, //........
- 0x00},//........
- //1
- {0x00, //........
- 0x00, //........
- 0x00, //...OO...
- 0x44, //....O...
- 0x7c, //....O...
- 0x40, //....O...
- 0x00, //...OOO..
- 0x00},//........
- //2
- {0x00, //........
- 0x00, //........
- 0x48, //...OO...
- 0x64, //..O..O..
- 0x54, //....O...
- 0x48, //...O....
- 0x00, //..OOOO..
- 0x00},//........
- //3
- {0x00, //........
- 0x00, //........
- 0x44, //..OOO...
- 0x54, //.....O..
- 0x54, //...OO...
- 0x28, //.....O..
- 0x00, //..OOO...
- 0x00},//........
- //4
- {0x00, //........
- 0x00, //........
- 0x1c, //..O.....
- 0x10, //..O.....
- 0x70, //..OOOO..
- 0x10, //....O...
- 0x00, //....O...
- 0x00},//........
- //5
- {0x00, //........
- 0x00, //........
- 0x5c, //..OOOO..
- 0x54, //..O.....
- 0x54, //..OOO...
- 0x24, //.....O..
- 0x00, //..OOO...
- 0x00},//........
- //6
- {0x00, //........
- 0x00, //........
- 0x38, //...OOO..
- 0x54, //..O.....
- 0x54, //..OOO...
- 0x24, //..O..O..
- 0x00, //...OO...
- 0x00},//........
- //7
- {0x00, //........
- 0x00, //........
- 0x44, //..OOOO..
- 0x24, //.....O..
- 0x14, //....O...
- 0x0c, //...O....
- 0x00, //..O.....
- 0x00},//........
- //8
- {0x00, //........
- 0x00, //........
- 0x28, //...OO...
- 0x54, //..O..O..
- 0x54, //...OO...
- 0x28, //..O..O..
- 0x00, //...OO...
- 0x00},//........
+ /* 0 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+ /* 1 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x00, /* ...OO... */
+ 0x44, /* ....O... */
+ 0x7c, /* ....O... */
+ 0x40, /* ....O... */
+ 0x00, /* ...OOO.. */
+ 0x00},/* ........ */
+ /* 2 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x48, /* ...OO... */
+ 0x64, /* ..O..O.. */
+ 0x54, /* ....O... */
+ 0x48, /* ...O.... */
+ 0x00, /* ..OOOO.. */
+ 0x00},/* ........ */
+ /* 3 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x44, /* ..OOO... */
+ 0x54, /* .....O.. */
+ 0x54, /* ...OO... */
+ 0x28, /* .....O.. */
+ 0x00, /* ..OOO... */
+ 0x00},/* ........ */
+ /* 4 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x1c, /* ..O..... */
+ 0x10, /* ..O..... */
+ 0x70, /* ..OOOO.. */
+ 0x10, /* ....O... */
+ 0x00, /* ....O... */
+ 0x00},/* ........ */
+ /* 5 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x5c, /* ..OOOO.. */
+ 0x54, /* ..O..... */
+ 0x54, /* ..OOO... */
+ 0x24, /* .....O.. */
+ 0x00, /* ..OOO... */
+ 0x00},/* ........ */
+ /* 6 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x38, /* ...OOO.. */
+ 0x54, /* ..O..... */
+ 0x54, /* ..OOO... */
+ 0x24, /* ..O..O.. */
+ 0x00, /* ...OO... */
+ 0x00},/* ........ */
+ /* 7 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x44, /* ..OOOO.. */
+ 0x24, /* .....O.. */
+ 0x14, /* ....O... */
+ 0x0c, /* ...O.... */
+ 0x00, /* ..O..... */
+ 0x00},/* ........ */
+ /* 8 */
+ {0x00, /* ........ */
+ 0x00, /* ........ */
+ 0x28, /* ...OO... */
+ 0x54, /* ..O..O.. */
+ 0x54, /* ...OO... */
+ 0x28, /* ..O..O.. */
+ 0x00, /* ...OO... */
+ 0x00},/* ........ */
};
/* the tile struct
@@ -156,20 +156,20 @@ typedef struct tile {
unsigned char neighbors : 4;
} tile;
-//the height and width of the field
-//could be variable if malloc worked in the API :)
+/* the height and width of the field */
+/* could be variable if malloc worked in the API :) */
const int height = LCD_HEIGHT/8;
const int width = LCD_WIDTH/8;
-//the minefield
+/* the minefield */
tile minefield[LCD_HEIGHT/8][LCD_WIDTH/8];
-//total number of mines on the game
+/* total number of mines on the game */
int mine_num = 0;
-//discovers the tile when player clears one of them
-//a chain reaction (of discovery) occurs if tile has no mines
-//as neighbors
+/* discovers the tile when player clears one of them */
+/* a chain reaction (of discovery) occurs if tile has no mines */
+/* as neighbors */
void discover(int, int);
void discover(int x, int y){
@@ -194,7 +194,7 @@ void discover(int x, int y){
}
-//init not mine related elements of the mine field
+/* init not mine related elements of the mine field */
void minesweeper_init(void){
int i,j;
@@ -207,9 +207,9 @@ void minesweeper_init(void){
}
-//put mines on the mine field
-//there is p% chance that a tile is a mine
-//if the tile has coordinates (x,y), then it can't be a mine
+/* put mines on the mine field */
+/* there is p% chance that a tile is a mine */
+/* if the tile has coordinates (x,y), then it can't be a mine */
void minesweeper_putmines(int p, int x, int y){
int i,j;
@@ -225,44 +225,49 @@ void minesweeper_putmines(int p, int x, int y){
}
}
- //we need to compute the neighbor element for each tile
+ /* we need to compute the neighbor element for each tile */
for(i=0;i<height;i++){
for(j=0;j<width;j++){
if(i>0){
- if(j>0) minefield[i][j].neighbors += minefield[i-1][j-1].mine;
+ if(j>0)
+ minefield[i][j].neighbors += minefield[i-1][j-1].mine;
minefield[i][j].neighbors += minefield[i-1][j].mine;
- if(j<width-1) minefield[i][j].neighbors += minefield[i-1][j+1].mine;
+ if(j<width-1)
+ minefield[i][j].neighbors += minefield[i-1][j+1].mine;
}
- if(j>0) minefield[i][j].neighbors += minefield[i][j-1].mine;
- if(j<width-1) minefield[i][j].neighbors += minefield[i][j+1].mine;
+ if(j>0)
+ minefield[i][j].neighbors += minefield[i][j-1].mine;
+ if(j<width-1)
+ minefield[i][j].neighbors += minefield[i][j+1].mine;
if(i<height-1){
- if(j>0) minefield[i][j].neighbors += minefield[i+1][j-1].mine;
+ if(j>0)
+ minefield[i][j].neighbors += minefield[i+1][j-1].mine;
minefield[i][j].neighbors += minefield[i+1][j].mine;
- if(j<width-1) minefield[i][j].neighbors += minefield[i+1][j+1].mine;
+ if(j<width-1)
+ minefield[i][j].neighbors += minefield[i+1][j+1].mine;
}
}
}
}
-//the big and ugly function that is the game
-int minesweeper(void){
-
-
+/* the big and ugly function that is the game */
+int minesweeper(void)
+{
int i,j;
- //the cursor coordinates
+ /* the cursor coordinates */
int x=0,y=0;
- //number of tiles left on the game
+ /* number of tiles left on the game */
int tiles_left=width*height;
- //percentage of mines on minefield used durring generation
+ /* percentage of mines on minefield used durring generation */
int p=16;
- //a usefull string for snprintf
+ /* a usefull string for snprintf */
char str[30];
- //welcome screen where player can chose mine percentage
+ /* welcome screen where player can chose mine percentage */
i = 0;
while(true){
rb->lcd_clear_display();
@@ -288,14 +293,15 @@ int minesweeper(void){
p = (p + 2)%100;
break;
- case BUTTON_ON://start playing
+ case BUTTON_ON:/* start playing */
i = 1;
break;
- case BUTTON_OFF://quit program
+ case BUTTON_OFF:/* quit program */
return MINESWEEPER_QUIT;
}
- if(i==1) break;
+ if(i==1)
+ break;
}
@@ -333,43 +339,43 @@ int minesweeper(void){
}
}
- //display the cursor
+ /* display the cursor */
rb->lcd_invertrect(x*8,y*8,8,8);
- //update the screen
+ /* update the screen */
rb->lcd_update();
switch(rb->button_get(true)){
- //quit minesweeper (you really shouldn't use this button ...)
+ /* quit minesweeper (you really shouldn't use this button ...) */
case BUTTON_OFF:
return MINESWEEPER_QUIT;
- //move cursor left
+ /* move cursor left */
case BUTTON_LEFT:
x = (x + width - 1)%width;
break;
- //move cursor right
+ /* move cursor right */
case BUTTON_RIGHT:
x = (x + 1)%width;
break;
- //move cursor down
+ /* move cursor down */
case BUTTON_DOWN:
y = (y + 1)%height;
break;
- //move cursor up
+ /* move cursor up */
case BUTTON_UP:
y = (y + height - 1)%height;
break;
- //discover a tile (and it's neighbors if .neighbors == 0)
+ /* discover a tile (and it's neighbors if .neighbors == 0) */
case BUTTON_ON:
case BUTTON_F2:
if(minefield[y][x].flag) break;
- //we put the mines on the first "click" so that you don't
- //lose on the first "click"
+ /* we put the mines on the first "click" so that you don't */
+ /* lose on the first "click" */
if(tiles_left == width*height) minesweeper_putmines(p,x,y);
discover(x,y);
if(minefield[y][x].mine){
@@ -386,14 +392,14 @@ int minesweeper(void){
}
break;
- //toggle flag under cursor
+ /* toggle flag under cursor */
case BUTTON_PLAY:
case BUTTON_F1:
minefield[y][x].flag = (minefield[y][x].flag + 1)%2;
break;
- //show how many mines you think you have found and how many
- //there really are on the game
+ /* show how many mines you think you have found and how many */
+ /* there really are on the game */
case BUTTON_F3:
tiles_left = 0;
for(i=0;i<height;i++){
@@ -408,14 +414,14 @@ int minesweeper(void){
}
-//plugin entry point
+/* plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
- //plugin init
+ /* plugin init */
TEST_PLUGIN_API(api);
(void)parameter;
rb = api;
- //end of plugin init
+ /* end of plugin init */
switch(minesweeper()){
case MINESWEEPER_WIN:
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index 2833443..04fde17 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -60,179 +60,179 @@ static struct plugin_api* rb;
#define HELP_BUTTON_ON "Select cards in the columns, Move cards inside the columns, reveal hidden cards ..."
static unsigned char colors[4][8] = {
-//Spades
-{0x00, //........
- 0x18, //...O....
- 0x1c, //..OOO...
- 0x3e, //.OOOOO..
- 0x1c, //.OOOOO..
- 0x18, //...O....
- 0x00, //........
- 0x00},//........
-//Hearts
-{0x00, //........
- 0x0c, //..O.O...
- 0x1e, //.OOOOO..
- 0x3c, //.OOOOO..
- 0x1e, //..OOO...
- 0x0c, //...O....
- 0x00, //........
- 0x00},//........
-//Clubs
-{0x00, //........
- 0x18, //..OOO...
- 0x0a, //...O....
- 0x3e, //.OOOOO..
- 0x0a, //.O.O.O..
- 0x18, //...O....
- 0x00, //........
- 0x00},//........
-//Diamonds
-{0x00, //........
- 0x08, //...O....
- 0x1c, //..OOO...
- 0x3e, //.OOOOO..
- 0x1c, //..OOO...
- 0x08, //...O....
- 0x00, //........
- 0x00} //........
+/* Spades */
+ {0x00, /* ........ */
+ 0x18, /* ...O.... */
+ 0x1c, /* ..OOO... */
+ 0x3e, /* .OOOOO.. */
+ 0x1c, /* .OOOOO.. */
+ 0x18, /* ...O.... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* Hearts */
+ {0x00, /* ........ */
+ 0x0c, /* ..O.O... */
+ 0x1e, /* .OOOOO.. */
+ 0x3c, /* .OOOOO.. */
+ 0x1e, /* ..OOO... */
+ 0x0c, /* ...O.... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* Clubs */
+ {0x00, /* ........ */
+ 0x18, /* ..OOO... */
+ 0x0a, /* ...O.... */
+ 0x3e, /* .OOOOO.. */
+ 0x0a, /* .O.O.O.. */
+ 0x18, /* ...O.... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* Diamonds */
+ {0x00, /* ........ */
+ 0x08, /* ...O.... */
+ 0x1c, /* ..OOO... */
+ 0x3e, /* .OOOOO.. */
+ 0x1c, /* ..OOO... */
+ 0x08, /* ...O.... */
+ 0x00, /* ........ */
+ 0x00} /* ........ */
};
static unsigned char numbers[13][8] = {
-//Ace
-{0x00, //........
- 0x38, //...O....
- 0x14, //..O.O...
- 0x12, //.O...O..
- 0x14, //.OOOOO..
- 0x38, //.O...O..
- 0x00, //........
- 0x00},//........
-//2
-{0x00, //........
- 0x24, //..OOO...
- 0x32, //.O...O..
- 0x32, //....O...
- 0x2a, //..OO....
- 0x24, //.OOOOO..
- 0x00, //........
- 0x00},//........
-//3
-{0x00, //........
- 0x22, //.OOOO...
- 0x2a, //.....O..
- 0x2a, //..OOO...
- 0x2a, //.....O..
- 0x14, //.OOOO...
- 0x00, //........
- 0x00},//........
-//4
-{0x00, //........
- 0x10, //....O...
- 0x18, //...O....
- 0x34, //..O.....
- 0x12, //.OOOOO..
- 0x10, //...O....
- 0x00, //........
- 0x00},//........
-//5
-{0x00, //........
- 0x2e, //.OOOOO..
- 0x2a, //.O......
- 0x2a, //.OOOO...
- 0x2a, //.....O..
- 0x12, //.OOOO...
- 0x00, //........
- 0x00},//........
-//6
-{0x00, //........
- 0x1c, //..OOO...
- 0x2a, //.O......
- 0x2a, //.OOOO...
- 0x2a, //.O...O..
- 0x10, //..OOO...
- 0x00, //........
- 0x00},//........
-//7
-{0x00, //........
- 0x22, //.OOOOO..
- 0x12, //....O...
- 0x0a, //...O....
- 0x06, //..O.....
- 0x02, //.O......
- 0x00, //........
- 0x00},//........
-//8
-{0x00, //........
- 0x14, //..OOO...
- 0x2a, //.O...O..
- 0x2a, //..OOO...
- 0x2a, //.O...O..
- 0x14, //..OOO...
- 0x00, //........
- 0x00},//........
-//9
-{0x00, //........
- 0x04, //..OOO...
- 0x2a, //.O...O..
- 0x2a, //..OOOO..
- 0x2a, //.....O..
- 0x1c, //..OOO...
- 0x00, //........
- 0x00},//........
-//10
-{0x00, //........
- 0x3e, //.O..O...
- 0x00, //.O.O.O..
- 0x1c, //.O.O.O..
- 0x22, //.O.O.O..
- 0x1c, //.O..O...
- 0x00, //........
- 0x00},//........
-//Jack
-{0x00, //........
- 0x12, //.OOOOO..
- 0x22, //...O....
- 0x1e, //...O....
- 0x02, //.O.O....
- 0x02, //..O.....
- 0x00, //........
- 0x00},//........
-//Queen
-{0x00, //........
- 0x1c, //..OOO...
- 0x22, //.O...O..
- 0x32, //.O...O..
- 0x22, //.O.O.O..
- 0x1c, //..OOO...
- 0x00, //........
- 0x00},//........
-//King
-{0x00, //........
- 0x3e, //.O...O..
- 0x08, //.O..O...
- 0x08, //.OOO....
- 0x14, //.O..O...
- 0x22, //.O...O..
- 0x00, //........
- 0x00} //........
+/* Ace */
+ {0x00, /* ........ */
+ 0x38, /* ...O.... */
+ 0x14, /* ..O.O... */
+ 0x12, /* .O...O.. */
+ 0x14, /* .OOOOO.. */
+ 0x38, /* .O...O.. */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 2 */
+ {0x00, /* ........ */
+ 0x24, /* ..OOO... */
+ 0x32, /* .O...O.. */
+ 0x32, /* ....O... */
+ 0x2a, /* ..OO.... */
+ 0x24, /* .OOOOO.. */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 3 */
+ {0x00, /* ........ */
+ 0x22, /* .OOOO... */
+ 0x2a, /* .....O.. */
+ 0x2a, /* ..OOO... */
+ 0x2a, /* .....O.. */
+ 0x14, /* .OOOO... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 4 */
+ {0x00, /* ........ */
+ 0x10, /* ....O... */
+ 0x18, /* ...O.... */
+ 0x34, /* ..O..... */
+ 0x12, /* .OOOOO.. */
+ 0x10, /* ...O.... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 5 */
+ {0x00, /* ........ */
+ 0x2e, /* .OOOOO.. */
+ 0x2a, /* .O...... */
+ 0x2a, /* .OOOO... */
+ 0x2a, /* .....O.. */
+ 0x12, /* .OOOO... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 6 */
+ {0x00, /* ........ */
+ 0x1c, /* ..OOO... */
+ 0x2a, /* .O...... */
+ 0x2a, /* .OOOO... */
+ 0x2a, /* .O...O.. */
+ 0x10, /* ..OOO... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 7 */
+ {0x00, /* ........ */
+ 0x22, /* .OOOOO.. */
+ 0x12, /* ....O... */
+ 0x0a, /* ...O.... */
+ 0x06, /* ..O..... */
+ 0x02, /* .O...... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 8 */
+ {0x00, /* ........ */
+ 0x14, /* ..OOO... */
+ 0x2a, /* .O...O.. */
+ 0x2a, /* ..OOO... */
+ 0x2a, /* .O...O.. */
+ 0x14, /* ..OOO... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 9 */
+ {0x00, /* ........ */
+ 0x04, /* ..OOO... */
+ 0x2a, /* .O...O.. */
+ 0x2a, /* ..OOOO.. */
+ 0x2a, /* .....O.. */
+ 0x1c, /* ..OOO... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* 10 */
+ {0x00, /* ........ */
+ 0x3e, /* .O..O... */
+ 0x00, /* .O.O.O.. */
+ 0x1c, /* .O.O.O.. */
+ 0x22, /* .O.O.O.. */
+ 0x1c, /* .O..O... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* Jack */
+ {0x00, /* ........ */
+ 0x12, /* .OOOOO.. */
+ 0x22, /* ...O.... */
+ 0x1e, /* ...O.... */
+ 0x02, /* .O.O.... */
+ 0x02, /* ..O..... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* Queen */
+ {0x00, /* ........ */
+ 0x1c, /* ..OOO... */
+ 0x22, /* .O...O.. */
+ 0x32, /* .O...O.. */
+ 0x22, /* .O.O.O.. */
+ 0x1c, /* ..OOO... */
+ 0x00, /* ........ */
+ 0x00},/* ........ */
+/* King */
+ {0x00, /* ........ */
+ 0x3e, /* .O...O.. */
+ 0x08, /* .O..O... */
+ 0x08, /* .OOO.... */
+ 0x14, /* .O..O... */
+ 0x22, /* .O...O.. */
+ 0x00, /* ........ */
+ 0x00} /* ........ */
};
#define NOT_A_CARD 255
-//number of cards per color
+/* number of cards per color */
#define CARDS_PER_COLOR 13
-//number of colors
+/* number of colors */
#define COLORS 4
-//number of columns
+/* number of columns */
#define COL_NUM 7
-//number of cards that are drawn on the remains' stack (by pressing F2)
+/* number of cards that are drawn on the remains' stack (by pressing F2) */
#define CARDS_PER_DRAW 3
-//size of a card on the screen
+/* size of a card on the screen */
#define CARD_WIDTH 14
#define CARD_HEIGHT 10
@@ -240,7 +240,7 @@ typedef struct card {
unsigned char color : 2;
unsigned char num : 4;
unsigned char known : 1;
- unsigned char used : 1;//this is what is used when dealing cards
+ unsigned char used : 1;/* this is what is used when dealing cards */
unsigned char next;
} card;
@@ -260,9 +260,9 @@ unsigned char next_random_card(card *deck){
return i;
}
-//help for the not so intuitive interface
-void solitaire_help(void){
-
+/* help for the not so intuitive interface */
+void solitaire_help(void)
+{
rb->lcd_clear_display();
rb->lcd_putsxy(0, 0, "Press a key to see");
@@ -291,37 +291,39 @@ void solitaire_help(void){
}
}
-//menu return codes
+/* menu return codes */
#define MENU_RESUME 0
#define MENU_RESTART 1
#define MENU_HELP 2
#define MENU_QUIT 3
-//menu item number
+/* menu item number */
#define MENU_LENGTH 4
-//different menu behaviors
+/* different menu behaviors */
#define MENU_BEFOREGAME 0
#define MENU_DURINGGAME 1
-//the menu
-//text displayed changes depending on the 'when' parameter
-int solitaire_menu(unsigned char when){
+/* the menu */
+/* text displayed changes depending on the 'when' parameter */
+int solitaire_menu(unsigned char when) {
static char menu[2][MENU_LENGTH][13] =
- { { "Start Game",
- "",
- "Help",
- "Quit" },
- { "Resume Game",
- "Restart Game",
- "Help",
- "Quit"} };
+ { { "Start Game",
+ "",
+ "Help",
+ "Quit" },
+ { "Resume Game",
+ "Restart Game",
+ "Help",
+ "Quit"}
+ };
int i;
int cursor=0;
- if(when!=MENU_BEFOREGAME && when!=MENU_DURINGGAME) when = MENU_DURINGGAME;
+ if(when!=MENU_BEFOREGAME && when!=MENU_DURINGGAME)
+ when = MENU_DURINGGAME;
while(1){
@@ -377,33 +379,33 @@ int solitaire_menu(unsigned char when){
}
}
-//player's cursor
+/* player's cursor */
unsigned char cur_card;
-//player's cursor column num
+/* player's cursor column num */
unsigned char cur_col;
-//selected card
+/* selected card */
unsigned char sel_card;
-//the deck
+/* the deck */
card deck[COLORS * CARDS_PER_COLOR];
-//the remaining cards
+/* the remaining cards */
unsigned char rem;
unsigned char cur_rem;
-//the 7 game columns
+/* the 7 game columns */
unsigned char cols[COL_NUM];
-//the 4 final color stacks
+/* the 4 final color stacks */
unsigned char stacks[COLORS];
-//initialize the game
+/* initialize the game */
void solitaire_init(void){
unsigned char c;
int i,j;
- //init deck
+ /* init deck */
for(i=0;i<COLORS;i++){
for(j=0;j<CARDS_PER_COLOR;j++){
deck[i*CARDS_PER_COLOR+j].color = i;
@@ -414,8 +416,8 @@ void solitaire_init(void){
}
}
- //deal the cards ...
- //... in the columns
+ /* deal the cards ... */
+ /* ... in the columns */
for(i=0; i<COL_NUM; i++){
c = NOT_A_CARD;
for(j=0; j<=i; j++){
@@ -430,7 +432,7 @@ void solitaire_init(void){
}
}
- //... shuffle what's left of the deck
+ /* ... shuffle what's left of the deck */
rem = next_random_card(deck);
c = rem;
@@ -439,26 +441,26 @@ void solitaire_init(void){
c = deck[c].next;
}
- //we now finished dealing the cards. The game can start ! (at last)
+ /* we now finished dealing the cards. The game can start ! (at last) */
- //init the stack
+ /* init the stack */
for(i = 0; i<COL_NUM;i++){
stacks[i] = NOT_A_CARD;
}
- //the cursor starts on upper left card
+ /* the cursor starts on upper left card */
cur_card = cols[0];
cur_col = 0;
- //no card is selected
+ /* no card is selected */
sel_card = NOT_A_CARD;
- //init the remainder
+ /* init the remainder */
cur_rem = NOT_A_CARD;
}
-//the game
+/* the game */
void solitaire(void){
int i,j;
@@ -472,7 +474,7 @@ void solitaire(void){
rb->lcd_clear_display();
- //get the biggest column length so that display can be "optimized"
+ /* get the biggest column length so that display can be "optimized" */
biggest_col_length = 0;
for(i=0;i<COL_NUM;i++){
@@ -485,55 +487,74 @@ void solitaire(void){
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 :)
+ /* 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*2, true, "You Won :)");
return;
}
- //draw the columns
+ /* draw the columns */
for(i=0;i<COL_NUM;i++){
c = cols[i];
j = 0;
while(true){
if(c==NOT_A_CARD) break;
- //clear the card's spot
- rb->lcd_clearrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM, j+1, CARD_WIDTH, CARD_HEIGHT-1);
- //known card
- if(deck[c].known){
- rb->lcd_bitmap(numbers[deck[c].num], i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j, 8, 8, true);
- rb->lcd_bitmap(colors[deck[c].color], i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+7, j, 8, 8, true);
+ /* clear the card's spot */
+ rb->lcd_clearrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,
+ j+1, CARD_WIDTH, CARD_HEIGHT-1);
+ /* known card */
+ if(deck[c].known) {
+ rb->lcd_bitmap(numbers[deck[c].num],
+ i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,
+ j, 8, 8, true);
+ rb->lcd_bitmap(colors[deck[c].color],
+ i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+7,
+ j, 8, 8, true);
}
- //draw top line of the card
- rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,j,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+CARD_WIDTH-1,j);
- //selected card
+ /* draw top line of the card */
+ rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,
+ j,i*(LCD_WIDTH - CARD_WIDTH)/
+ COL_NUM+CARD_WIDTH-1,j);
+ /* selected card */
if(c == sel_card && sel_card != NOT_A_CARD){
- rb->lcd_drawrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j+1, CARD_WIDTH-1, CARD_HEIGHT-1);
+ rb->lcd_drawrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,
+ j+1, CARD_WIDTH-1, CARD_HEIGHT-1);
}
- //cursor (or not)
+ /* cursor (or not) */
if(c == cur_card){
- rb->lcd_invertrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1, j+1, CARD_WIDTH-1, CARD_HEIGHT-1);
- //go to the next card
+ rb->lcd_invertrect(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM+1,
+ j+1, CARD_WIDTH-1, CARD_HEIGHT-1);
+ /* go to the next card */
c = deck[c].next;
- if(c == NOT_A_CARD) break;
+ if(c == NOT_A_CARD)
+ break;
j += CARD_HEIGHT - 2;
- } else {
- //go to the next card
+ }
+ else {
+ /* go to the next card */
c = deck[c].next;
- if(c == NOT_A_CARD) break;
- j += min(CARD_HEIGHT - 2, (LCD_HEIGHT - CARD_HEIGHT)/biggest_col_length);
+ if(c == NOT_A_CARD)
+ break;
+ j += min(CARD_HEIGHT - 2,
+ (LCD_HEIGHT - CARD_HEIGHT)/biggest_col_length);
}
}
- //draw line to the left of the column
- rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,j+CARD_HEIGHT-1);
- //draw line to the right of the column
- 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);
- //draw bottom of the last card
- 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);
+ /* draw line to the left of the column */
+ rb->lcd_drawline(i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,
+ 1,i*(LCD_WIDTH - CARD_WIDTH)/COL_NUM,
+ j+CARD_HEIGHT-1);
+ /* draw line to the right of the column */
+ 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);
+ /* draw bottom of the last card */
+ 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);
}
- //draw the stacks
+ /* draw the stacks */
for(i=0; i<COLORS; i++){
c = stacks[i];
if(c!=NOT_A_CARD){
@@ -542,27 +563,39 @@ void solitaire(void){
}
}
if(c != NOT_A_CARD) {
- rb->lcd_bitmap(numbers[deck[c].num], LCD_WIDTH - CARD_WIDTH+1, i*CARD_HEIGHT, 8, 8, true);
+ rb->lcd_bitmap(numbers[deck[c].num], LCD_WIDTH - CARD_WIDTH+1,
+ i*CARD_HEIGHT, 8, 8, true);
}
- rb->lcd_bitmap(colors[i], LCD_WIDTH - CARD_WIDTH+7, i*CARD_HEIGHT, 8, 8, true);
- rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,i*CARD_HEIGHT,LCD_WIDTH - 1,i*CARD_HEIGHT);
- rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,(i+1)*CARD_HEIGHT,LCD_WIDTH - 1,(i+1)*CARD_HEIGHT);
+ rb->lcd_bitmap(colors[i], LCD_WIDTH - CARD_WIDTH+7,
+ i*CARD_HEIGHT, 8, 8, true);
+ rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,
+ i*CARD_HEIGHT,LCD_WIDTH - 1,i*CARD_HEIGHT);
+ rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,
+ (i+1)*CARD_HEIGHT,LCD_WIDTH - 1,
+ (i+1)*CARD_HEIGHT);
}
- //draw the remains
- rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,LCD_HEIGHT-CARD_HEIGHT-1,LCD_WIDTH - 1,LCD_HEIGHT-CARD_HEIGHT-1);
- rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,LCD_HEIGHT-1,LCD_WIDTH - 1,LCD_HEIGHT-1);
+ /* draw the remains */
+ rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,
+ LCD_HEIGHT-CARD_HEIGHT-1,
+ LCD_WIDTH - 1,LCD_HEIGHT-CARD_HEIGHT-1);
+ rb->lcd_drawline(LCD_WIDTH - CARD_WIDTH+1,
+ LCD_HEIGHT-1,LCD_WIDTH - 1,LCD_HEIGHT-1);
if(cur_rem != NOT_A_CARD){
- rb->lcd_bitmap(numbers[deck[cur_rem].num], LCD_WIDTH - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT, 8, 8, true);
- rb->lcd_bitmap(colors[deck[cur_rem].color], LCD_WIDTH - CARD_WIDTH+7, LCD_HEIGHT-CARD_HEIGHT, 8, 8, true);
+ rb->lcd_bitmap(numbers[deck[cur_rem].num],
+ LCD_WIDTH - CARD_WIDTH+1, LCD_HEIGHT-CARD_HEIGHT,
+ 8, 8, true);
+ rb->lcd_bitmap(colors[deck[cur_rem].color],
+ LCD_WIDTH - CARD_WIDTH+7,
+ LCD_HEIGHT-CARD_HEIGHT, 8, 8, true);
}
rb->lcd_update();
- //what to do when a key is pressed ...
+ /* what to do when a key is pressed ... */
switch(rb->button_get(true)){
- //move cursor to the last card of the previous column
+ /* move cursor to the last card of the previous column */
case BUTTON_RIGHT:
cur_col = (cur_col+1)%COL_NUM;
cur_card = cols[cur_col];
@@ -573,7 +606,7 @@ void solitaire(void){
}
break;
- //move cursor to the last card of the next column
+ /* move cursor to the last card of the next column */
case BUTTON_LEFT:
cur_col = (cur_col + COL_NUM - 1)%COL_NUM;
cur_card = cols[cur_col];
@@ -584,7 +617,7 @@ void solitaire(void){
}
break;
- //move cursor to card that's bellow
+ /* move cursor to card that's bellow */
case BUTTON_DOWN:
if(cur_card == NOT_A_CARD) break;
if(deck[cur_card].next != NOT_A_CARD){
@@ -594,7 +627,7 @@ void solitaire(void){
}
break;
- //move cursor to card that's above
+ /* move cursor to card that's above */
case BUTTON_UP:
if(cur_card == NOT_A_CARD) break;
if(cols[cur_col] == cur_card){
@@ -610,61 +643,64 @@ void solitaire(void){
}
break;
- //Try to put card under cursor on one of the stacks
+ /* Try to put card under cursor on one of the stacks */
case BUTTON_F1:
- //check if a card is selected
- //else there would be nothing to move on the stacks !
+ /* check if a card is selected */
+ /* else there would be nothing to move on the stacks ! */
if(cur_card != NOT_A_CARD){
- //find the last card in the color's stack and put it's number in 'c'.
+ /* find the last card in the color's stack and put it's number in 'c'. */
c = stacks[deck[cur_card].color];
if(c!=NOT_A_CARD){
while(deck[c].next!=NOT_A_CARD){
c = deck[c].next;
}
}
- //if 'c' isn't a card, that means that the stack is empty
- //which implies that only an ace can be moved
+ /* if 'c' isn't a card, that means that the stack is empty */
+ /* which implies that only an ace can be moved */
if(c == NOT_A_CARD){
- //check if the selected card is an ace
- //we don't have to check if any card is in the *.next
- //position since the ace is the last possible card
+ /* check if the selected card is an ace */
+ /* we don't have to check if any card is in the *.next */
+ /* position since the ace is the last possible card */
if(deck[cur_card].num == 0){
- //remove 'cur_card' from any *.next postition ...
- //... by looking in the columns
+ /* remove 'cur_card' from any *.next postition ... */
+ /* ... by looking in the columns */
for(i=0;i<COL_NUM;i++){
if(cols[i]==cur_card) cols[i] = NOT_A_CARD;
}
- //... and in the entire deck
- //TODO : check if looking in the cols is really needed
+ /* ... and in the entire deck */
+ /* TODO : check if looking in the cols is really needed */
for(i=0;i<COLORS*CARDS_PER_COLOR;i++){
if(deck[i].next==cur_card) deck[i].next = NOT_A_CARD;
}
- //move cur_card on top of the stack
+ /* move cur_card on top of the stack */
stacks[deck[cur_card].color] = cur_card;
- //assign the card at the bottom of cur_col to cur_card
+ /* assign the card at the bottom of cur_col to cur_card */
cur_card = cols[cur_col];
if(cur_card != NOT_A_CARD){
while(deck[cur_card].next != NOT_A_CARD){
cur_card = deck[cur_card].next;
}
}
- //clear the selection indicator
+ /* clear the selection indicator */
sel_card = NOT_A_CARD;
}
}
- //the stack is not empty
- //so we can move any card other than an ace
- //we thus check that the card we are moving is the next on the stack and that it isn't under any card
- else if(deck[cur_card].num == deck[c].num + 1 && deck[cur_card].next == NOT_A_CARD){
- //same as above
- for(i=0;i<COL_NUM;i++){
- if(cols[i]==cur_card) cols[i] = NOT_A_CARD;
+ /* the stack is not empty */
+ /* so we can move any card other than an ace */
+ /* we thus check that the card we are moving is the next on the stack and that it isn't under any card */
+ else if(deck[cur_card].num == deck[c].num + 1 &&
+ deck[cur_card].next == NOT_A_CARD) {
+ /* same as above */
+ for(i=0;i<COL_NUM;i++) {
+ if(cols[i]==cur_card)
+ cols[i] = NOT_A_CARD;
}
- //re same
+ /* re same */
for(i=0;i<COLORS*CARDS_PER_COLOR;i++){
- if(deck[i].next==cur_card) deck[i].next = NOT_A_CARD;
+ if(deck[i].next==cur_card)
+ deck[i].next = NOT_A_CARD;
}
- //...
+ /* ... */
deck[c].next = cur_card;
cur_card = cols[cur_col];
if(cur_card != NOT_A_CARD){
@@ -677,10 +713,12 @@ void solitaire(void){
}
break;
- //Move cards arround, Uncover cards, ...
+ /* Move cards arround, Uncover cards, ... */
case BUTTON_ON:
if(sel_card == NOT_A_CARD) {
- if((cur_card != NOT_A_CARD?deck[cur_card].next == NOT_A_CARD && deck[cur_card].known==0:0)){
+ if((cur_card != NOT_A_CARD?
+ deck[cur_card].next == NOT_A_CARD &&
+ deck[cur_card].known==0:0)) {
deck[cur_card].known = 1;
} else {
sel_card = cur_card;
@@ -688,12 +726,15 @@ void solitaire(void){
} else if(sel_card == cur_card) {
sel_card = NOT_A_CARD;
} else if(cur_card != NOT_A_CARD){
- if(deck[cur_card].num == deck[sel_card].num + 1 && (deck[cur_card].color + deck[sel_card].color)%2 == 1 ){
+ if(deck[cur_card].num == deck[sel_card].num + 1 &&
+ (deck[cur_card].color + deck[sel_card].color)%2 == 1 ){
for(i=0;i<COL_NUM;i++){
- if(cols[i]==sel_card) cols[i] = NOT_A_CARD;
+ if(cols[i]==sel_card)
+ cols[i] = NOT_A_CARD;
}
for(i=0;i<COLORS*CARDS_PER_COLOR;i++){
- if(deck[i].next==sel_card) deck[i].next = NOT_A_CARD;
+ if(deck[i].next==sel_card)
+ deck[i].next = NOT_A_CARD;
}
deck[cur_card].next = sel_card;
sel_card = NOT_A_CARD;
@@ -701,10 +742,12 @@ void solitaire(void){
} else if(cur_card == NOT_A_CARD){
if(deck[sel_card].num == CARDS_PER_COLOR - 1){
for(i=0;i<COL_NUM;i++){
- if(cols[i]==sel_card) cols[i] = NOT_A_CARD;
+ if(cols[i]==sel_card)
+ cols[i] = NOT_A_CARD;
}
for(i=0;i<COLORS*CARDS_PER_COLOR;i++){
- if(deck[i].next==sel_card) deck[i].next = NOT_A_CARD;
+ if(deck[i].next==sel_card)
+ deck[i].next = NOT_A_CARD;
}
cols[cur_col] = sel_card;
sel_card = NOT_A_CARD;
@@ -712,25 +755,25 @@ void solitaire(void){
}
break;
- //If the card on the top of the remains can be put where
- //the cursor is, go ahead
+ /* If the card on the top of the remains can be put where */
+ /* the cursor is, go ahead */
case BUTTON_PLAY:
- //check if a card is face up on the remains' stack
+ /* check if a card is face up on the remains' stack */
if(cur_rem != NOT_A_CARD){
- //if no card is selected, it means the col is empty
- //thus, only a king can be moved
+ /* if no card is selected, it means the col is empty */
+ /* thus, only a king can be moved */
if(cur_card == NOT_A_CARD){
- //check if selcted card is a king
+ /* check if selcted card is a king */
if(deck[cur_rem].num == CARDS_PER_COLOR - 1){
- //find the previous card on the remains' stack
+ /* find the previous card on the remains' stack */
c = rem;
- //if the current card on the remains' stack
- //is the first card of the stack, then ...
+ /* if the current card on the remains' stack */
+ /* is the first card of the stack, then ... */
if(c == cur_rem){
c = NOT_A_CARD;
rem = deck[cur_rem].next;
}
- //else ...
+ /* else ... */
else {
while(deck[c].next != cur_rem){
c = deck[c].next;
@@ -742,7 +785,9 @@ void solitaire(void){
deck[cur_rem].known = 1;
cur_rem = c;
}
- } else if(deck[cur_rem].num + 1 == deck[cur_card].num && (deck[cur_rem].color + deck[cur_card].color)%2==1) {
+ } else if(deck[cur_rem].num + 1 == deck[cur_card].num &&
+ (deck[cur_rem].color +
+ deck[cur_card].color)%2==1) {
c = rem;
if(c == cur_rem){
c = NOT_A_CARD;
@@ -761,8 +806,8 @@ void solitaire(void){
}
break;
- //If the card on top of the remains can be put on one
- //of the stacks, do so
+ /* If the card on top of the remains can be put on one */
+ /* of the stacks, do so */
case BUTTON_F3:
if(cur_rem != NOT_A_CARD){
if(deck[cur_rem].num == 0){
@@ -807,14 +852,14 @@ void solitaire(void){
}
break;
- //unselect selected card or ...
- //draw new cards from the remains of the deck
+ /* unselect selected card or ... */
+ /* draw new cards from the remains of the deck */
case BUTTON_F2:
if(sel_card != NOT_A_CARD){
- //unselect selected card
+ /* unselect selected card */
sel_card = NOT_A_CARD;
} else if(rem != NOT_A_CARD) {
- //draw new cards form the remains of the deck
+ /* draw new cards form the remains of the deck */
if(cur_rem == NOT_A_CARD){
cur_rem = rem;
i = CARDS_PER_DRAW - 1;
@@ -825,14 +870,14 @@ void solitaire(void){
cur_rem = deck[cur_rem].next;
i--;
}
- //test if any cards are really left on the remains' stack
+ /* test if any cards are really left on the remains' stack */
if(i == CARDS_PER_DRAW){
cur_rem = NOT_A_CARD;
}
}
break;
- //Show the menu
+ /* Show the menu */
case BUTTON_OFF:
switch(solitaire_menu(MENU_DURINGGAME)){
case MENU_QUIT:
@@ -848,19 +893,19 @@ void solitaire(void){
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
- //plugin init
+ /* plugin init */
TEST_PLUGIN_API(api);
(void)parameter;
rb = api;
- //end of plugin init
+ /* end of plugin init */
- //Welcome to Solitaire !
+ /* Welcome to Solitaire ! */
rb->splash(HZ*2, true, "Welcome to Solitaire !");
- //play the game :)
+ /* play the game :) */
solitaire();
- //Exit the plugin
+ /* Exit the plugin */
return PLUGIN_OK;
}