display time and mark info
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user