diff options
author | mRnea <akannemre@gmail.com> | 2024-12-20 18:08:16 +0300 |
---|---|---|
committer | mRnea <akannemre@gmail.com> | 2024-12-20 18:08:16 +0300 |
commit | 40b50d19645218f049b6c913011d078334358058 (patch) | |
tree | 14b4c6ee221316709373bc7b6689de40eb796d68 /minesweeper | |
parent | 76feab4879143565f7313f3cc0d9f89013d4778a (diff) |
seperate decl. and impl. even if on the same file
Diffstat (limited to 'minesweeper')
-rw-r--r-- | minesweeper/mine.c | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/minesweeper/mine.c b/minesweeper/mine.c index ef46bdd..51a7281 100644 --- a/minesweeper/mine.c +++ b/minesweeper/mine.c @@ -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; } |