seperate decl. and impl. even if on the same file

This commit is contained in:
2024-12-20 18:08:16 +03:00
parent 76feab4879
commit 40b50d1964

View File

@@ -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;
@@ -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;
}