seperate decl. and impl. even if on the same file
This commit is contained in:
@@ -37,6 +37,53 @@ static inline cell set_cell(Minefield* mf, int r, int c, cell cell){
|
||||
return mf->cells[r * mf->col + c] = cell;
|
||||
}
|
||||
|
||||
Minefield make_minefield(int row, int col, int mine_count);
|
||||
void free_minefield(Minefield* mf);
|
||||
char cell_char(cell c);
|
||||
void print_minefield(Minefield *mf, FILE *stream);
|
||||
void draw_minefield(Minefield* mf);
|
||||
cell* clicked_cell(Minefield* mf, int x, int y);
|
||||
void expose_cell(Minefield* mf, int r, int c);
|
||||
void handle_click(Minefield* mf);
|
||||
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
float cell_size;
|
||||
int mark_count;
|
||||
bool dead;
|
||||
|
||||
int main(){
|
||||
srand(time(NULL));
|
||||
Minefield mf = make_minefield(10, 20, 30);
|
||||
/* print_minefield(&mf, stdout); */
|
||||
dead = false;
|
||||
mark_count = 0;
|
||||
{
|
||||
float width = (float) screenWidth / mf.col;
|
||||
float height = (float) screenHeight / mf.row;
|
||||
cell_size = width > height ? height : width;
|
||||
}
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "Minesweeper");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while(!WindowShouldClose()){
|
||||
|
||||
if (!dead){
|
||||
handle_click(&mf);
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
draw_minefield(&mf);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
free_minefield(&mf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Minefield make_minefield(int row, int col, int mine_count){
|
||||
Minefield mf = {.row = row, .col = col};
|
||||
int size = mf.row * mf.col;
|
||||
@@ -96,7 +143,7 @@ char cell_char(cell c){
|
||||
return c > 0 ? c + '0' : ' ';
|
||||
}
|
||||
}
|
||||
void print_minefield(Minefield *mf, FILE *stream) {
|
||||
void print_minefield(Minefield *mf, FILE *stream){
|
||||
for (int i = 0; i < mf->row; i++) {
|
||||
for (int j = 0; j < mf->col; j++) {
|
||||
fputc('|', stream);
|
||||
@@ -107,12 +154,6 @@ void print_minefield(Minefield *mf, FILE *stream) {
|
||||
}
|
||||
}
|
||||
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
float cell_size;
|
||||
int mark_count;
|
||||
bool dead;
|
||||
|
||||
void draw_minefield(Minefield* mf){
|
||||
char str[2] = "0";
|
||||
for (int i = 0; i < mf->row; i++){
|
||||
@@ -195,42 +236,5 @@ void handle_click(Minefield* mf){
|
||||
mark_count += mf->cells[r * mf->col + c] & MARKED ? -1 : 1;
|
||||
mf->cells[r * mf->col + c] ^= MARKED;
|
||||
}
|
||||
|
||||
|
||||
/* putchar(cell_char(*c)); */
|
||||
/* fflush(stdout); */
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
srand(time(NULL));
|
||||
Minefield mf = make_minefield(10, 20, 30);
|
||||
/* print_minefield(&mf, stdout); */
|
||||
dead = false;
|
||||
mark_count = 0;
|
||||
{
|
||||
float width = (float) screenWidth / mf.col;
|
||||
float height = (float) screenHeight / mf.row;
|
||||
cell_size = width > height ? height : width;
|
||||
}
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "Minesweeper");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while(!WindowShouldClose()){
|
||||
|
||||
if (!dead){
|
||||
handle_click(&mf);
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
draw_minefield(&mf);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
free_minefield(&mf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user