mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 20:49:49 +04:00
add sec+ 1.0/2.0 433mhz in add manually, and run fbt fmt
This commit is contained in:
@@ -24,9 +24,11 @@ typedef enum {
|
||||
SubmenuIndexLinear_300_00,
|
||||
SubmenuIndexLiftMaster_315_00,
|
||||
SubmenuIndexLiftMaster_390_00,
|
||||
SubmenuIndexLiftMaster_433_00,
|
||||
SubmenuIndexSecPlus_v2_310_00,
|
||||
SubmenuIndexSecPlus_v2_315_00,
|
||||
SubmenuIndexSecPlus_v2_390_00,
|
||||
SubmenuIndexSecPlus_v2_433_00,
|
||||
|
||||
//SubGhzCustomEvent
|
||||
SubGhzCustomEventSceneDeleteSuccess = 100,
|
||||
|
||||
@@ -167,6 +167,12 @@ void subghz_scene_set_type_on_enter(void* context) {
|
||||
SubmenuIndexLiftMaster_390_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Security+1.0 433MHz",
|
||||
SubmenuIndexLiftMaster_433_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Security+2.0 310MHz",
|
||||
@@ -185,6 +191,12 @@ void subghz_scene_set_type_on_enter(void* context) {
|
||||
SubmenuIndexSecPlus_v2_390_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Security+2.0 433MHz",
|
||||
SubmenuIndexSecPlus_v2_433_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType));
|
||||
@@ -359,6 +371,20 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexLiftMaster_433_00:
|
||||
while(!subghz_protocol_secplus_v1_check_fixed(key)) {
|
||||
key = subghz_random_serial();
|
||||
}
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_SECPLUS_V1_NAME,
|
||||
(uint64_t)key << 32 | 0xE6000000,
|
||||
42,
|
||||
433920000,
|
||||
"AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexSecPlus_v2_310_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
@@ -413,6 +439,24 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
break;
|
||||
case SubmenuIndexSecPlus_v2_433_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 433920000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
subghz->txrx->fff_data,
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
|
||||
@@ -1,48 +1,144 @@
|
||||
#define tile_0_width 8
|
||||
#define tile_0_height 8
|
||||
static uint8_t tile_0_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
#define tile_1_width 8
|
||||
#define tile_1_height 8
|
||||
static uint8_t tile_1_bits[] = {
|
||||
0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
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, };
|
||||
0xFF,
|
||||
0x81,
|
||||
0x81,
|
||||
0x81,
|
||||
0x81,
|
||||
0x81,
|
||||
0x81,
|
||||
0xFF,
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
|
||||
|
||||
static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
const Minesweeper* minesweeper_state = acquire_mutex((ValueMutex*)ctx, 25);
|
||||
if (minesweeper_state == NULL) {
|
||||
if(minesweeper_state == NULL) {
|
||||
return;
|
||||
}
|
||||
FuriString* mineStr;
|
||||
@@ -90,25 +90,25 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
|
||||
int seconds = 0;
|
||||
int minutes = 0;
|
||||
if (minesweeper_state->game_started) {
|
||||
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 = (int)ticks_elapsed / furi_kernel_get_tick_frequency();
|
||||
minutes = (int)seconds / 60;
|
||||
seconds = seconds % 60;
|
||||
}
|
||||
furi_string_printf(timeStr, "%01d:%02d", minutes, seconds);
|
||||
canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(timeStr));
|
||||
|
||||
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) {
|
||||
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) {
|
||||
canvas_invert_color(canvas);
|
||||
}
|
||||
switch (minesweeper_state->playfield[x][y]) {
|
||||
switch(minesweeper_state->playfield[x][y]) {
|
||||
case TileType0:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -117,7 +117,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType1:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -126,7 +126,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType2:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -135,7 +135,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType3:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -144,7 +144,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType4:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -153,7 +153,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType5:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -162,7 +162,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType6:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -171,7 +171,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType7:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -180,7 +180,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileType8:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -189,7 +189,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileTypeFlag:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -198,7 +198,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileTypeUncleared:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
@@ -207,14 +207,14 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
case TileTypeMine:
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
x*TILE_HEIGHT, // x
|
||||
x * TILE_HEIGHT, // x
|
||||
8 + (y * TILE_WIDTH), // y
|
||||
TILE_WIDTH,
|
||||
TILE_HEIGHT,
|
||||
tile_mine_bits);
|
||||
break;
|
||||
}
|
||||
if ( x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
|
||||
if(x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
|
||||
canvas_invert_color(canvas);
|
||||
}
|
||||
}
|
||||
@@ -227,8 +227,8 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
|
||||
static void setup_playfield(Minesweeper* minesweeper_state) {
|
||||
int mines_left = MINECOUNT;
|
||||
for (int y = 0; y < PLAYFIELD_HEIGHT; y++) {
|
||||
for (int x = 0; x < PLAYFIELD_WIDTH; x++){
|
||||
for(int y = 0; y < PLAYFIELD_HEIGHT; y++) {
|
||||
for(int x = 0; x < PLAYFIELD_WIDTH; x++) {
|
||||
minesweeper_state->minefield[x][y] = FieldEmpty;
|
||||
minesweeper_state->playfield[x][y] = TileTypeUncleared;
|
||||
}
|
||||
@@ -237,8 +237,8 @@ static void setup_playfield(Minesweeper* minesweeper_state) {
|
||||
int rand_x = rand() % PLAYFIELD_WIDTH;
|
||||
int rand_y = rand() % PLAYFIELD_HEIGHT;
|
||||
// make sure first guess isn't a mine
|
||||
if (minesweeper_state->minefield[rand_x][rand_y] == FieldEmpty &&
|
||||
(minesweeper_state->cursor_x != rand_x && minesweeper_state->cursor_y != rand_y )) {
|
||||
if(minesweeper_state->minefield[rand_x][rand_y] == FieldEmpty &&
|
||||
(minesweeper_state->cursor_x != rand_x && minesweeper_state->cursor_y != rand_y)) {
|
||||
minesweeper_state->minefield[rand_x][rand_y] = FieldMine;
|
||||
mines_left--;
|
||||
}
|
||||
@@ -251,18 +251,23 @@ static void setup_playfield(Minesweeper* minesweeper_state) {
|
||||
}
|
||||
|
||||
static void place_flag(Minesweeper* minesweeper_state) {
|
||||
if (minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] == TileTypeUncleared) {
|
||||
minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] = TileTypeFlag;
|
||||
if(minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] ==
|
||||
TileTypeUncleared) {
|
||||
minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] =
|
||||
TileTypeFlag;
|
||||
minesweeper_state->flags_set++;
|
||||
} else if (minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] == TileTypeFlag) {
|
||||
minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] = TileTypeUncleared;
|
||||
} else if(
|
||||
minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] ==
|
||||
TileTypeFlag) {
|
||||
minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] =
|
||||
TileTypeUncleared;
|
||||
minesweeper_state->flags_set--;
|
||||
}
|
||||
}
|
||||
|
||||
static bool game_lost(Minesweeper* minesweeper_state) {
|
||||
// returns true if the player wants to restart, otherwise false
|
||||
DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
const char* header_text = "Game Over";
|
||||
@@ -277,7 +282,7 @@ static bool game_lost(Minesweeper* minesweeper_state) {
|
||||
NotificationApp* notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
notification_message(notifications, &sequence_set_vibro_on);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_timer_start(minesweeper_state->timer, (uint32_t) furi_kernel_get_tick_frequency() * 0.2);
|
||||
furi_timer_start(minesweeper_state->timer, (uint32_t)furi_kernel_get_tick_frequency() * 0.2);
|
||||
|
||||
DialogMessageButton choice = dialog_message_show(dialogs, message);
|
||||
dialog_message_free(message);
|
||||
@@ -287,7 +292,7 @@ static bool game_lost(Minesweeper* minesweeper_state) {
|
||||
}
|
||||
|
||||
static bool game_won(Minesweeper* minesweeper_state) {
|
||||
DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
|
||||
FuriString* tempStr;
|
||||
tempStr = furi_string_alloc();
|
||||
@@ -295,15 +300,16 @@ static bool game_won(Minesweeper* minesweeper_state) {
|
||||
int seconds = 0;
|
||||
int minutes = 0;
|
||||
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 = (int)ticks_elapsed / furi_kernel_get_tick_frequency();
|
||||
minutes = (int)seconds / 60;
|
||||
seconds = seconds % 60;
|
||||
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
const char* header_text = "Game won!";
|
||||
furi_string_cat_printf(tempStr, "Minefield cleared in %01d:%02d", minutes, seconds);
|
||||
dialog_message_set_header(message, header_text, 64, 3, AlignCenter, AlignTop);
|
||||
dialog_message_set_text(message, furi_string_get_cstr(tempStr), 64, 32, AlignCenter, AlignCenter);
|
||||
dialog_message_set_text(
|
||||
message, furi_string_get_cstr(tempStr), 64, 32, AlignCenter, AlignCenter);
|
||||
dialog_message_set_buttons(message, NULL, "Play again", NULL);
|
||||
dialog_message_set_icon(message, NULL, 72, 17);
|
||||
|
||||
@@ -316,44 +322,46 @@ static bool game_won(Minesweeper* minesweeper_state) {
|
||||
|
||||
// returns false if the move loses the game - otherwise true
|
||||
static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y) {
|
||||
if (minesweeper_state->playfield[cursor_x][cursor_y] == TileTypeFlag) {
|
||||
if(minesweeper_state->playfield[cursor_x][cursor_y] == TileTypeFlag) {
|
||||
// we're on a flagged field, do nothing
|
||||
return true;
|
||||
}
|
||||
if (minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
|
||||
if(minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) {
|
||||
// player loses - draw mine
|
||||
minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (minesweeper_state->playfield[cursor_x][cursor_y] >= TileType1 && minesweeper_state->playfield[cursor_x][cursor_y] <= TileType8) {
|
||||
if(minesweeper_state->playfield[cursor_x][cursor_y] >= TileType1 &&
|
||||
minesweeper_state->playfield[cursor_x][cursor_y] <= TileType8) {
|
||||
// click on a cleared cell with a number
|
||||
// count the flags around
|
||||
int flags = 0;
|
||||
for (int y = cursor_y-1; y <= cursor_y+1; y++) {
|
||||
for (int x = cursor_x-1; x <= cursor_x+1; x++) {
|
||||
if ( x == cursor_x && y == cursor_y ) {
|
||||
for(int y = cursor_y - 1; y <= cursor_y + 1; y++) {
|
||||
for(int x = cursor_x - 1; x <= cursor_x + 1; x++) {
|
||||
if(x == cursor_x && y == cursor_y) {
|
||||
// we're on the cell the user selected, so ignore.
|
||||
continue;
|
||||
}
|
||||
// make sure we don't go OOB
|
||||
if ( x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) {
|
||||
if (minesweeper_state->playfield[x][y] == TileTypeFlag) {
|
||||
flags ++;
|
||||
if(x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) {
|
||||
if(minesweeper_state->playfield[x][y] == TileTypeFlag) {
|
||||
flags++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int mines = minesweeper_state->playfield[cursor_x][cursor_y]; // ¯\_(ツ)_/¯
|
||||
if (flags == mines) {
|
||||
if(flags == mines) {
|
||||
// auto uncover all non-flags around (to win faster ;)
|
||||
for (int auto_y = cursor_y-1; auto_y <= cursor_y+1; auto_y++) {
|
||||
for (int auto_x = cursor_x-1; auto_x <= cursor_x+1; auto_x++) {
|
||||
if ( auto_x == cursor_x && auto_y == cursor_y ) {
|
||||
for(int auto_y = cursor_y - 1; auto_y <= cursor_y + 1; auto_y++) {
|
||||
for(int auto_x = cursor_x - 1; auto_x <= cursor_x + 1; auto_x++) {
|
||||
if(auto_x == cursor_x && auto_y == cursor_y) {
|
||||
continue;
|
||||
}
|
||||
if ( auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 && auto_y < PLAYFIELD_HEIGHT) {
|
||||
if (minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
|
||||
if(auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 &&
|
||||
auto_y < PLAYFIELD_HEIGHT) {
|
||||
if(minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
|
||||
if(!play_move(minesweeper_state, auto_x, auto_y)) {
|
||||
// flags were wrong, we got a mine!
|
||||
return false;
|
||||
@@ -369,16 +377,16 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
|
||||
|
||||
// calculate number of surrounding mines.
|
||||
int hint = 0;
|
||||
for (int y = cursor_y-1; y <= cursor_y+1; y++) {
|
||||
for (int x = cursor_x-1; x <= cursor_x+1; x++) {
|
||||
if ( x == cursor_x && y == cursor_y ) {
|
||||
for(int y = cursor_y - 1; y <= cursor_y + 1; y++) {
|
||||
for(int x = cursor_x - 1; x <= cursor_x + 1; x++) {
|
||||
if(x == cursor_x && y == cursor_y) {
|
||||
// we're on the cell the user selected, so ignore.
|
||||
continue;
|
||||
}
|
||||
// make sure we don't go OOB
|
||||
if ( x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) {
|
||||
if(x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) {
|
||||
if(minesweeper_state->minefield[x][y] == FieldMine) {
|
||||
hint ++;
|
||||
hint++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -387,16 +395,17 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
|
||||
minesweeper_state->playfield[cursor_x][cursor_y] = hint;
|
||||
minesweeper_state->fields_cleared++;
|
||||
FURI_LOG_D("Minesweeper", "Setting %d,%d to %d", cursor_x, cursor_y, hint);
|
||||
if (hint == 0) {
|
||||
if(hint == 0) {
|
||||
// the field is "empty"
|
||||
// auto open surrounding fields.
|
||||
for (int auto_y = cursor_y-1; auto_y <= cursor_y+1; auto_y++) {
|
||||
for (int auto_x = cursor_x-1; auto_x <= cursor_x+1; auto_x++) {
|
||||
if ( auto_x == cursor_x && auto_y == cursor_y ) {
|
||||
for(int auto_y = cursor_y - 1; auto_y <= cursor_y + 1; auto_y++) {
|
||||
for(int auto_x = cursor_x - 1; auto_x <= cursor_x + 1; auto_x++) {
|
||||
if(auto_x == cursor_x && auto_y == cursor_y) {
|
||||
continue;
|
||||
}
|
||||
if ( auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 && auto_y < PLAYFIELD_HEIGHT) {
|
||||
if (minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
|
||||
if(auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 &&
|
||||
auto_y < PLAYFIELD_HEIGHT) {
|
||||
if(minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) {
|
||||
play_move(minesweeper_state, auto_x, auto_y);
|
||||
}
|
||||
}
|
||||
@@ -409,8 +418,8 @@ static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y
|
||||
static void minesweeper_state_init(Minesweeper* const minesweeper_state) {
|
||||
minesweeper_state->cursor_x = minesweeper_state->cursor_y = 0;
|
||||
minesweeper_state->game_started = false;
|
||||
for (int y = 0; y < PLAYFIELD_HEIGHT; y++) {
|
||||
for (int x = 0; x < PLAYFIELD_WIDTH; x++){
|
||||
for(int y = 0; y < PLAYFIELD_HEIGHT; y++) {
|
||||
for(int x = 0; x < PLAYFIELD_WIDTH; x++) {
|
||||
minesweeper_state->playfield[x][y] = TileTypeUncleared;
|
||||
}
|
||||
}
|
||||
@@ -418,7 +427,7 @@ static void minesweeper_state_init(Minesweeper* const minesweeper_state) {
|
||||
|
||||
int32_t minesweeper_app(void* p) {
|
||||
UNUSED(p);
|
||||
DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
const char* header_text = "Minesweeper";
|
||||
@@ -441,7 +450,7 @@ int32_t minesweeper_app(void* p) {
|
||||
minesweeper_state_init(minesweeper_state);
|
||||
|
||||
ValueMutex state_mutex;
|
||||
if (!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) {
|
||||
if(!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) {
|
||||
FURI_LOG_E("Minesweeper", "cannot create mutex\r\n");
|
||||
free(minesweeper_state);
|
||||
return 255;
|
||||
@@ -459,7 +468,7 @@ int32_t minesweeper_app(void* p) {
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
PluginEvent event;
|
||||
for (bool processing = true; processing;) {
|
||||
for(bool processing = true; processing;) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
Minesweeper* minesweeper_state = (Minesweeper*)acquire_mutex_block(&state_mutex);
|
||||
if(event_status == FuriStatusOk) {
|
||||
@@ -476,13 +485,13 @@ int32_t minesweeper_app(void* p) {
|
||||
case InputKeyDown:
|
||||
minesweeper_state->cursor_y++;
|
||||
if(minesweeper_state->cursor_y >= PLAYFIELD_HEIGHT) {
|
||||
minesweeper_state->cursor_y = PLAYFIELD_HEIGHT-1;
|
||||
minesweeper_state->cursor_y = PLAYFIELD_HEIGHT - 1;
|
||||
}
|
||||
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 = PLAYFIELD_WIDTH - 1;
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
@@ -492,13 +501,16 @@ int32_t minesweeper_app(void* p) {
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
if (!minesweeper_state->game_started) {
|
||||
if(!minesweeper_state->game_started) {
|
||||
setup_playfield(minesweeper_state);
|
||||
minesweeper_state->game_started = true;
|
||||
}
|
||||
if (!play_move(minesweeper_state, minesweeper_state->cursor_x, minesweeper_state->cursor_y)) {
|
||||
if(!play_move(
|
||||
minesweeper_state,
|
||||
minesweeper_state->cursor_x,
|
||||
minesweeper_state->cursor_y)) {
|
||||
// ooops. looks like we hit a mine!
|
||||
if (game_lost(minesweeper_state)) {
|
||||
if(game_lost(minesweeper_state)) {
|
||||
// player wants to restart.
|
||||
setup_playfield(minesweeper_state);
|
||||
} else {
|
||||
@@ -507,8 +519,9 @@ int32_t minesweeper_app(void* p) {
|
||||
}
|
||||
} else {
|
||||
// check win condition.
|
||||
if (minesweeper_state->fields_cleared == (PLAYFIELD_HEIGHT*PLAYFIELD_WIDTH) - MINECOUNT){
|
||||
if (game_won(minesweeper_state)) {
|
||||
if(minesweeper_state->fields_cleared ==
|
||||
(PLAYFIELD_HEIGHT * PLAYFIELD_WIDTH) - MINECOUNT) {
|
||||
if(game_won(minesweeper_state)) {
|
||||
//player wants to restart
|
||||
setup_playfield(minesweeper_state);
|
||||
} else {
|
||||
@@ -522,7 +535,7 @@ int32_t minesweeper_app(void* p) {
|
||||
processing = false;
|
||||
break;
|
||||
}
|
||||
} else if (event.input.type == InputTypeLong) {
|
||||
} else if(event.input.type == InputTypeLong) {
|
||||
// hold events
|
||||
FURI_LOG_D("Minesweeper", "Got a long press!");
|
||||
switch(event.input.key) {
|
||||
|
||||
Reference in New Issue
Block a user