6
6
7
7
#include <notification/notification_messages.h>
8
8
#include <dialogs/dialogs.h>
9
+ #include <m-string.h>
9
10
10
11
#include "assets.h"
11
12
14
15
#define TILE_WIDTH 8
15
16
#define TILE_HEIGHT 8
16
17
17
- #define MINECOUNT 12
18
+ #define MINECOUNT 24
18
19
19
20
typedef enum {
20
21
EventTypeTick ,
@@ -27,7 +28,7 @@ typedef struct {
27
28
} PluginEvent ;
28
29
29
30
typedef enum {
30
- TileType0 , // this HAS to be in order, then
31
+ TileType0 , // this HAS to be in order, for hint assignment to be ez pz
31
32
TileType1 ,
32
33
TileType2 ,
33
34
TileType3 ,
@@ -51,9 +52,10 @@ typedef struct {
51
52
TileType playfield [PLAYFIELD_WIDTH ][PLAYFIELD_HEIGHT ];
52
53
int cursor_x ;
53
54
int cursor_y ;
54
- bool game_started ;
55
55
int mines_left ;
56
56
int fields_cleared ;
57
+ int flags_set ;
58
+ bool game_started ;
57
59
bool showing_dialog ;
58
60
} Minesweeper ;
59
61
@@ -73,7 +75,13 @@ static void render_callback(Canvas* const canvas, void* ctx) {
73
75
release_mutex ((ValueMutex * )ctx , minesweeper_state );
74
76
return ;
75
77
}
76
- canvas_set_font (canvas , FontPrimary );
78
+ string_t tempStr ;
79
+ string_init (tempStr );
80
+ string_printf (tempStr , "Mines: %d" , MINECOUNT - minesweeper_state -> flags_set );
81
+ canvas_set_font (canvas , FontSecondary );
82
+ canvas_draw_str_aligned (canvas , 0 , 0 , AlignLeft , AlignTop , string_get_cstr (tempStr ));
83
+ string_clear (tempStr );
84
+
77
85
for (int y = 0 ; y < PLAYFIELD_HEIGHT ; y ++ ) {
78
86
for (int x = 0 ; x < PLAYFIELD_WIDTH ; x ++ ) {
79
87
if ( x == minesweeper_state -> cursor_x && y == minesweeper_state -> cursor_y ) {
@@ -194,6 +202,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
194
202
}
195
203
}
196
204
}
205
+ string_clear (tempStr );
197
206
release_mutex ((ValueMutex * )ctx , minesweeper_state );
198
207
}
199
208
@@ -216,14 +225,17 @@ static void setup_playfield(Minesweeper* minesweeper_state) {
216
225
}
217
226
minesweeper_state -> mines_left = MINECOUNT ;
218
227
minesweeper_state -> fields_cleared = 0 ;
228
+ minesweeper_state -> flags_set = 0 ;
219
229
}
220
230
}
221
231
222
232
static void place_flag (Minesweeper * minesweeper_state ) {
223
233
if (minesweeper_state -> playfield [minesweeper_state -> cursor_x ][minesweeper_state -> cursor_y ] == TileTypeUncleared ) {
224
234
minesweeper_state -> playfield [minesweeper_state -> cursor_x ][minesweeper_state -> cursor_y ] = TileTypeFlag ;
235
+ minesweeper_state -> flags_set ++ ;
225
236
} else if (minesweeper_state -> playfield [minesweeper_state -> cursor_x ][minesweeper_state -> cursor_y ] == TileTypeFlag ) {
226
237
minesweeper_state -> playfield [minesweeper_state -> cursor_x ][minesweeper_state -> cursor_y ] = TileTypeUncleared ;
238
+ minesweeper_state -> flags_set -- ;
227
239
}
228
240
}
229
241
0 commit comments