diff options
author | mRnea <akannemre@gmail.com> | 2024-12-20 17:58:35 +0300 |
---|---|---|
committer | mRnea <akannemre@gmail.com> | 2024-12-20 17:58:35 +0300 |
commit | 3fce5522e006c2735dbd922927f1ace91e3f2f84 (patch) | |
tree | c2739fbca42209174f99fed37ea6af053075c75e | |
parent | 0944b03fc0bdd86b467330ae1909ef5f32aef57c (diff) |
display time and mark info
-rw-r--r-- | minesweeper/mine.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/minesweeper/mine.c b/minesweeper/mine.c index 7ea5ec8..ede3441 100644 --- a/minesweeper/mine.c +++ b/minesweeper/mine.c @@ -26,6 +26,7 @@ typedef struct minefield_t { int row; int col; cell* cells; + int mine_count; } Minefield; static inline cell get_cell(Minefield* mf, int r, int c){ @@ -40,7 +41,7 @@ Minefield make_minefield(int row, int col, int mine_count){ Minefield mf = {.row = row, .col = col}; int size = mf.row * mf.col; mf.cells = (cell *)calloc(size, sizeof(cell)); - + mf.mine_count = mine_count; // 0 initialization for (int i = 0; i < size; i++) { mf.cells[i] = 0; @@ -109,6 +110,7 @@ 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){ @@ -128,6 +130,12 @@ void draw_minefield(Minefield* mf){ } } } + char time_str[20]; + float time = GetTime(); + snprintf(time_str, 100, "%02d.%02d - %d/%d", + (int) time / 60, (int) time % 60, + mark_count, mf->mine_count); + DrawText(time_str, screenWidth / 2 - 20, screenHeight - 30, 20, BLACK); } cell* clicked_cell(Minefield* mf, int x, int y){ @@ -196,7 +204,7 @@ void handle_click(Minefield* mf){ printf("Click outside range, (%d, %d)\n", r, c); return; } - + mark_count += mf->cells[r * mf->col + c] & MARKED ? -1 : 1; mf->cells[r * mf->col + c] ^= MARKED; } @@ -211,7 +219,7 @@ int main(){ 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; |