Skip to content

Commit b3ec5e7

Browse files
committed
moving cursor
1 parent b8aa5fe commit b3ec5e7

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

application.fam

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
App(
22
appid="minesweeper",
3-
name="BPM Tapper",
3+
name="Minesweeper",
44
apptype=FlipperAppType.PLUGIN,
55
entry_point="minesweeper_app",
66
cdefines=["APP_MINESWEEPER"],

minesweeper.c

+32-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ typedef enum {
4545
typedef struct {
4646
Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
4747
TileType playfield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
48+
int cursor_cell_x;
49+
int cursor_cell_y;
4850
} Minesweeper;
4951

5052
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@@ -62,22 +64,28 @@ static void render_callback(Canvas* const canvas, void* ctx) {
6264
canvas_set_font(canvas, FontPrimary);
6365
for (int y = 0; y < PLAYFIELD_HEIGHT; y++) {
6466
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+
}
6570
canvas_draw_xbm(
6671
canvas,
6772
x*TILE_HEIGHT, // x
6873
8 + (y * TILE_WIDTH), // y
6974
TILE_WIDTH,
7075
TILE_HEIGHT,
7176
tile_uncleared_bits);
77+
if ( x == minesweeper_state->cursor_cell_x && y == minesweeper_state->cursor_cell_y) {
78+
canvas_invert_color(canvas);
79+
}
7280
}
7381
}
7482
release_mutex((ValueMutex*)ctx, minesweeper_state);
7583
}
7684

7785

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+
}
8189

8290
int32_t minesweeper_app(void* p) {
8391
UNUSED(p);
@@ -86,7 +94,7 @@ int32_t minesweeper_app(void* p) {
8694

8795
Minesweeper* minesweeper_state = malloc(sizeof(Minesweeper));
8896
// setup
89-
//minesweeper_state_init(minesweeper_state);
97+
minesweeper_state_init(minesweeper_state);
9098

9199
ValueMutex state_mutex;
92100
if (!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) {
@@ -115,9 +123,29 @@ int32_t minesweeper_app(void* p) {
115123
if(event.input.type == InputTypePress) {
116124
switch(event.input.key) {
117125
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;
118131
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;
119137
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;
120143
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;
121149
case InputKeyOk:
122150
break;
123151
case InputKeyBack:

0 commit comments

Comments
 (0)