From 4e7970f53f759093bbfbbf6246d2dc2d19161d1b Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Fri, 23 Sep 2022 21:55:58 +0200 Subject: [PATCH] timer --- assets/asset | 48 +++++++++++++++++++++++++++++++++++++++ assets/tile_0.xbm | 4 ++++ assets/tile_1.xbm | 4 ++++ assets/tile_2.xbm | 4 ++++ assets/tile_3.xbm | 4 ++++ assets/tile_4.xbm | 4 ++++ assets/tile_5.xbm | 4 ++++ assets/tile_6.xbm | 4 ++++ assets/tile_7.xbm | 4 ++++ assets/tile_8.xbm | 4 ++++ assets/tile_flag.xbm | 4 ++++ assets/tile_mine.xbm | 4 ++++ assets/tile_uncleared.xbm | 2 +- minesweeper.c | 15 +++++++++++- 14 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 assets/asset create mode 100644 assets/tile_0.xbm create mode 100644 assets/tile_1.xbm create mode 100644 assets/tile_2.xbm create mode 100644 assets/tile_3.xbm create mode 100644 assets/tile_4.xbm create mode 100644 assets/tile_5.xbm create mode 100644 assets/tile_6.xbm create mode 100644 assets/tile_7.xbm create mode 100644 assets/tile_8.xbm create mode 100644 assets/tile_flag.xbm create mode 100644 assets/tile_mine.xbm diff --git a/assets/asset b/assets/asset new file mode 100644 index 0000000..80a6c89 --- /dev/null +++ b/assets/asset @@ -0,0 +1,48 @@ +#define tile_0_width 8 +#define tile_0_height 8 +static uint8_t tile_0_bits[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; +#define tile_1_width 8 +#define tile_1_height 8 +static uint8_t tile_1_bits[] = { + 0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, }; +#define tile_2_width 8 +#define tile_2_height 8 +static uint8_t tile_2_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, }; +#define tile_3_width 8 +#define tile_3_height 8 +static uint8_t tile_3_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, }; +#define tile_4_width 8 +#define tile_4_height 8 +static uint8_t tile_4_bits[] = { + 0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, }; +#define tile_5_width 8 +#define tile_5_height 8 +static uint8_t tile_5_bits[] = { + 0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, }; +#define tile_6_width 8 +#define tile_6_height 8 +static uint8_t tile_6_bits[] = { + 0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, }; +#define tile_7_width 8 +#define tile_7_height 8 +static uint8_t tile_7_bits[] = { + 0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, }; +#define tile_8_width 8 +#define tile_8_height 8 +static uint8_t tile_8_bits[] = { + 0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, }; +#define tile_flag_width 8 +#define tile_flag_height 8 +static uint8_t tile_flag_bits[] = { + 0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, }; +#define tile_mine_width 8 +#define tile_mine_height 8 +static uint8_t tile_mine_bits[] = { + 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, }; +#define tile_uncleared_width 8 +#define tile_uncleared_height 8 +static uint8_t tile_uncleared_bits[] = { + 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, }; diff --git a/assets/tile_0.xbm b/assets/tile_0.xbm new file mode 100644 index 0000000..3da1fa7 --- /dev/null +++ b/assets/tile_0.xbm @@ -0,0 +1,4 @@ +#define tile_0_width 8 +#define tile_0_height 8 +static char tile_0_bits[] = { + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, }; diff --git a/assets/tile_1.xbm b/assets/tile_1.xbm new file mode 100644 index 0000000..568c721 --- /dev/null +++ b/assets/tile_1.xbm @@ -0,0 +1,4 @@ +#define tile_1_width 8 +#define tile_1_height 8 +static uint8_t tile_1_bits[] = { + 0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, }; diff --git a/assets/tile_2.xbm b/assets/tile_2.xbm new file mode 100644 index 0000000..198ae08 --- /dev/null +++ b/assets/tile_2.xbm @@ -0,0 +1,4 @@ +#define tile_2_width 8 +#define tile_2_height 8 +static uint8_t tile_2_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, }; diff --git a/assets/tile_3.xbm b/assets/tile_3.xbm new file mode 100644 index 0000000..022bd3c --- /dev/null +++ b/assets/tile_3.xbm @@ -0,0 +1,4 @@ +#define tile_3_width 8 +#define tile_3_height 8 +static uint8_t tile_3_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, }; diff --git a/assets/tile_4.xbm b/assets/tile_4.xbm new file mode 100644 index 0000000..5828717 --- /dev/null +++ b/assets/tile_4.xbm @@ -0,0 +1,4 @@ +#define tile_4_width 8 +#define tile_4_height 8 +static uint8_t tile_4_bits[] = { + 0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, }; diff --git a/assets/tile_5.xbm b/assets/tile_5.xbm new file mode 100644 index 0000000..e36f51a --- /dev/null +++ b/assets/tile_5.xbm @@ -0,0 +1,4 @@ +#define tile_5_width 8 +#define tile_5_height 8 +static uint8_t tile_5_bits[] = { + 0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, }; diff --git a/assets/tile_6.xbm b/assets/tile_6.xbm new file mode 100644 index 0000000..74b290e --- /dev/null +++ b/assets/tile_6.xbm @@ -0,0 +1,4 @@ +#define tile_6_width 8 +#define tile_6_height 8 +static uint8_t tile_6_bits[] = { + 0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, }; diff --git a/assets/tile_7.xbm b/assets/tile_7.xbm new file mode 100644 index 0000000..6aafa6a --- /dev/null +++ b/assets/tile_7.xbm @@ -0,0 +1,4 @@ +#define tile_7_width 8 +#define tile_7_height 8 +static uint8_t tile_7_bits[] = { + 0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, }; diff --git a/assets/tile_8.xbm b/assets/tile_8.xbm new file mode 100644 index 0000000..05ab210 --- /dev/null +++ b/assets/tile_8.xbm @@ -0,0 +1,4 @@ +#define tile_8_width 8 +#define tile_8_height 8 +static uint8_t tile_8_bits[] = { + 0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, }; diff --git a/assets/tile_flag.xbm b/assets/tile_flag.xbm new file mode 100644 index 0000000..ed4b9c0 --- /dev/null +++ b/assets/tile_flag.xbm @@ -0,0 +1,4 @@ +#define tile_flag_width 8 +#define tile_flag_height 8 +static uint8_t tile_flag_bits[] = { + 0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, }; diff --git a/assets/tile_mine.xbm b/assets/tile_mine.xbm new file mode 100644 index 0000000..6e05347 --- /dev/null +++ b/assets/tile_mine.xbm @@ -0,0 +1,4 @@ +#define tile_mine_width 8 +#define tile_mine_height 8 +static uint8_t tile_mine_bits[] = { + 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, }; diff --git a/assets/tile_uncleared.xbm b/assets/tile_uncleared.xbm index ad05436..e8a8ef6 100644 --- a/assets/tile_uncleared.xbm +++ b/assets/tile_uncleared.xbm @@ -1,4 +1,4 @@ #define tile_uncleared_width 8 #define tile_uncleared_height 8 -static char tile_uncleared_bits[] = { +static uint8_t tile_uncleared_bits[] = { 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, }; diff --git a/minesweeper.c b/minesweeper.c index 369dd37..483d52e 100644 --- a/minesweeper.c +++ b/minesweeper.c @@ -57,6 +57,7 @@ typedef struct { int flags_set; bool game_started; bool showing_dialog; + uint32_t game_started_tick; } Minesweeper; static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { @@ -81,7 +82,18 @@ static void render_callback(Canvas* const canvas, void* ctx) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, string_get_cstr(tempStr)); string_clear(tempStr); - + int seconds = 0; + int minutes = 0; + if (minesweeper_state->game_started) { + uint32_t ticks_elapsed = furi_get_tick() - minesweeper_state->game_started_tick; + seconds = (int) ticks_elapsed / furi_kernel_get_tick_frequency(); + minutes = (int) seconds / 60; + seconds = seconds % 60; + } + string_printf(tempStr, "%01d:%02d", minutes, seconds); + canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, string_get_cstr(tempStr)); + string_clear(tempStr); + for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { for (int x = 0; x < PLAYFIELD_WIDTH; x++) { if ( x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) { @@ -226,6 +238,7 @@ static void setup_playfield(Minesweeper* minesweeper_state) { minesweeper_state->mines_left = MINECOUNT; minesweeper_state->fields_cleared = 0; minesweeper_state->flags_set = 0; + minesweeper_state->game_started_tick = furi_get_tick(); } }