Compare commits

..

6 Commits

Author SHA1 Message Date
Felix Pankratz 34b645c51e
Merge pull request #7 from gelin/fix-v0.72.1
fix build for firmware v0.72.1
2 years ago
Denis Nelubin 94924fa550 fix build for firmware v0.72.1 2 years ago
Felix Pankratz bb6e54cb34 fix data type 2 years ago
Felix Pankratz cf138cd9be cursor wraps around 2 years ago
Felix Pankratz dc2c8d51ef cleanup 2 years ago
Felix Pankratz addd984e4e
Merge pull request #3 from panki27/flagsbased-uncover
Uncover surrounding fields if number of set flags is correct. Thanks @gelin
2 years ago

@ -43,7 +43,7 @@ typedef enum {
} TileType;
typedef enum {
FieldEmpty, // <-- same goes for this
FieldEmpty,
FieldMine
} Field;
@ -99,6 +99,8 @@ static void render_callback(Canvas* const canvas, void* ctx) {
furi_string_printf(timeStr, "%01d:%02d", minutes, seconds);
canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(timeStr));
uint8_t* tile_to_draw;
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) {
@ -106,114 +108,53 @@ static void render_callback(Canvas* const canvas, void* ctx) {
}
switch (minesweeper_state->playfield[x][y]) {
case TileType0:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_0_bits);
tile_to_draw = tile_0_bits;
break;
case TileType1:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_1_bits);
tile_to_draw = tile_1_bits;
break;
case TileType2:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_2_bits);
tile_to_draw = tile_2_bits;
break;
case TileType3:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_3_bits);
tile_to_draw = tile_3_bits;
break;
case TileType4:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_4_bits);
tile_to_draw = tile_4_bits;
break;
case TileType5:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_5_bits);
tile_to_draw = tile_5_bits;
break;
case TileType6:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_6_bits);
tile_to_draw = tile_6_bits;
break;
case TileType7:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_7_bits);
tile_to_draw = tile_7_bits;
break;
case TileType8:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_8_bits);
tile_to_draw = tile_8_bits;
break;
case TileTypeFlag:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_flag_bits);
tile_to_draw = tile_flag_bits;
break;
case TileTypeUncleared:
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_uncleared_bits);
tile_to_draw = tile_uncleared_bits;
break;
case TileTypeMine:
tile_to_draw = tile_mine_bits;
break;
default:
// this should never happen
tile_to_draw = tile_mine_bits;
break;
}
canvas_draw_xbm(
canvas,
x*TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_mine_bits);
break;
}
tile_to_draw);
if ( x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
canvas_invert_color(canvas);
}
@ -470,25 +411,25 @@ int32_t minesweeper_app(void* p) {
case InputKeyUp:
minesweeper_state->cursor_y--;
if(minesweeper_state->cursor_y < 0) {
minesweeper_state->cursor_y = 0;
minesweeper_state->cursor_y = PLAYFIELD_HEIGHT - 1;
}
break;
case InputKeyDown:
minesweeper_state->cursor_y++;
if(minesweeper_state->cursor_y >= PLAYFIELD_HEIGHT) {
minesweeper_state->cursor_y = PLAYFIELD_HEIGHT-1;
minesweeper_state->cursor_y = 0;
}
break;
case InputKeyRight:
minesweeper_state->cursor_x++;
if(minesweeper_state->cursor_x >= PLAYFIELD_WIDTH) {
minesweeper_state->cursor_x = PLAYFIELD_WIDTH-1;
minesweeper_state->cursor_x = 0;
}
break;
case InputKeyLeft:
minesweeper_state->cursor_x--;
if(minesweeper_state->cursor_x < 0) {
minesweeper_state->cursor_x = 0;
minesweeper_state->cursor_x = PLAYFIELD_WIDTH-1;
}
break;
case InputKeyOk:
@ -521,6 +462,8 @@ int32_t minesweeper_app(void* p) {
// Exit the plugin
processing = false;
break;
case InputKeyMAX:
break;
}
} else if (event.input.type == InputTypeLong) {
// hold events
@ -538,6 +481,8 @@ int32_t minesweeper_app(void* p) {
case InputKeyBack:
processing = false;
break;
case InputKeyMAX:
break;
}
}
}

Loading…
Cancel
Save