@@ -45,6 +45,8 @@ typedef enum {
45
45
typedef struct {
46
46
Field minefield [PLAYFIELD_WIDTH ][PLAYFIELD_HEIGHT ];
47
47
TileType playfield [PLAYFIELD_WIDTH ][PLAYFIELD_HEIGHT ];
48
+ int cursor_cell_x ;
49
+ int cursor_cell_y ;
48
50
} Minesweeper ;
49
51
50
52
static void input_callback (InputEvent * input_event , FuriMessageQueue * event_queue ) {
@@ -62,22 +64,28 @@ static void render_callback(Canvas* const canvas, void* ctx) {
62
64
canvas_set_font (canvas , FontPrimary );
63
65
for (int y = 0 ; y < PLAYFIELD_HEIGHT ; y ++ ) {
64
66
for (int x = 0 ; x < PLAYFIELD_WIDTH ; x ++ ) {
67
+ if ( x == minesweeper_state -> cursor_cell_x && y == minesweeper_state -> cursor_cell_y ) {
68
+ canvas_invert_color (canvas );
69
+ }
65
70
canvas_draw_xbm (
66
71
canvas ,
67
72
x * TILE_HEIGHT , // x
68
73
8 + (y * TILE_WIDTH ), // y
69
74
TILE_WIDTH ,
70
75
TILE_HEIGHT ,
71
76
tile_uncleared_bits );
77
+ if ( x == minesweeper_state -> cursor_cell_x && y == minesweeper_state -> cursor_cell_y ) {
78
+ canvas_invert_color (canvas );
79
+ }
72
80
}
73
81
}
74
82
release_mutex ((ValueMutex * )ctx , minesweeper_state );
75
83
}
76
84
77
85
78
- // static void minesweeper_state_init(Minesweeper* const plugin_state) {
79
- //
80
- // }
86
+ static void minesweeper_state_init (Minesweeper * const plugin_state ) {
87
+ plugin_state -> cursor_cell_x = plugin_state -> cursor_cell_y = 0 ;
88
+ }
81
89
82
90
int32_t minesweeper_app (void * p ) {
83
91
UNUSED (p );
@@ -86,7 +94,7 @@ int32_t minesweeper_app(void* p) {
86
94
87
95
Minesweeper * minesweeper_state = malloc (sizeof (Minesweeper ));
88
96
// setup
89
- // minesweeper_state_init(minesweeper_state);
97
+ minesweeper_state_init (minesweeper_state );
90
98
91
99
ValueMutex state_mutex ;
92
100
if (!init_mutex (& state_mutex , minesweeper_state , sizeof (minesweeper_state ))) {
@@ -115,9 +123,29 @@ int32_t minesweeper_app(void* p) {
115
123
if (event .input .type == InputTypePress ) {
116
124
switch (event .input .key ) {
117
125
case InputKeyUp :
126
+ minesweeper_state -> cursor_cell_y -- ;
127
+ if (minesweeper_state -> cursor_cell_y < 0 ) {
128
+ minesweeper_state -> cursor_cell_y = 0 ;
129
+ }
130
+ break ;
118
131
case InputKeyDown :
132
+ minesweeper_state -> cursor_cell_y ++ ;
133
+ if (minesweeper_state -> cursor_cell_y > PLAYFIELD_HEIGHT ) {
134
+ minesweeper_state -> cursor_cell_y = PLAYFIELD_HEIGHT ;
135
+ }
136
+ break ;
119
137
case InputKeyRight :
138
+ minesweeper_state -> cursor_cell_x ++ ;
139
+ if (minesweeper_state -> cursor_cell_x > PLAYFIELD_WIDTH ) {
140
+ minesweeper_state -> cursor_cell_x = PLAYFIELD_WIDTH ;
141
+ }
142
+ break ;
120
143
case InputKeyLeft :
144
+ minesweeper_state -> cursor_cell_x -- ;
145
+ if (minesweeper_state -> cursor_cell_x < 0 ) {
146
+ minesweeper_state -> cursor_cell_x = 0 ;
147
+ }
148
+ break ;
121
149
case InputKeyOk :
122
150
break ;
123
151
case InputKeyBack :
0 commit comments