Skip to content

Commit

Permalink
upd minesweeper
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Jan 28, 2024
1 parent a3015b0 commit d50f8b7
Show file tree
Hide file tree
Showing 12 changed files with 530 additions and 543 deletions.
2 changes: 1 addition & 1 deletion base_pack/minesweeper/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ App(
fap_icon="assets/minesweeper.png", # 10x10 1-bit PNG
fap_category="Games",
# Optional values
fap_version="1.1",
fap_version="1.2",
fap_description="Flipper Zero Minesweeper Implementation",
fap_author="Alexander Rodriguez",
fap_weburl="https://github.com/squee72564/F0_Minesweeper_Fap",
Expand Down
31 changes: 8 additions & 23 deletions base_pack/minesweeper/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@

# Changelog
## TODO:
- Add settings options to toggle hardware feedback
- Maybe take a look at the board verifier algo and try to make faster/multi-thread or anything to allow better maps

## Version 1.2.0 - 1/25/2024

Added ability to toggle sound and haptic feedback.

Minor reformats and fixes.

## Version 1.1.0 - 1/11/2024

Added haptic / led functionality

## Added
- Haptic feedback on all button presses.
- Out of bounds movement
- Ok to clear tiles
- Holding back for flags
- Different haptic feedback on win/loss
- LED changes on win loss
- Initially LED is just reset
- Set to red on loss
- Set to blue on win
- Sound on some presses
Code Reformats

## Version 1.0.0 - 1/10/2024

Initial Full release for the game.

## Added
- Mine sweeper game with settings menu to choose variable board dimensions from 16x7 to 32x32.
- Ability to set difficulty, width, and height for the game board in settings.
- Ability to enable solvable boards only
- The core game functionality is complete for the game with multiple types of button presses registered for different inputs.
- The game will save your settings (besides "enable solvable") when you leave the game.
Initial Full release for the game.
15 changes: 10 additions & 5 deletions base_pack/minesweeper/helpers/mine_sweeper_haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
void mine_sweeper_play_happy_bump(void* context) {
MineSweeperApp* app = context;

notification_message(app->notification, &sequence_set_vibro_on);
if (app->feedback_enabled)
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
notification_message(app->notification, &sequence_reset_vibro);
}
Expand All @@ -14,7 +15,8 @@ void mine_sweeper_play_long_ok_bump(void* context) {
MineSweeperApp* app = context;

for (int i = 0; i < 2; i++) {
notification_message(app->notification, &sequence_set_vibro_on);
if (app->feedback_enabled)
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
notification_message(app->notification, &sequence_reset_vibro);
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
Expand All @@ -24,15 +26,17 @@ void mine_sweeper_play_long_ok_bump(void* context) {
void mine_sweeper_play_oob_bump(void* context) {
MineSweeperApp* app = context;

notification_message(app->notification, &sequence_set_vibro_on);
if (app->feedback_enabled)
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
notification_message(app->notification, &sequence_reset_vibro);
}

void mine_sweeper_play_lose_bump(void* context) {
MineSweeperApp* app = context;

notification_message(app->notification, &sequence_set_vibro_on);
if (app->feedback_enabled)
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
notification_message(app->notification, &sequence_reset_vibro);
furi_thread_flags_wait(0, FuriFlagWaitAny, 400);
Expand All @@ -42,7 +46,8 @@ void mine_sweeper_play_win_bump(void* context) {
MineSweeperApp* app = context;

for (int i = 0; i < 4; i++) {
notification_message(app->notification, &sequence_set_vibro_on);
if (app->feedback_enabled)
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
notification_message(app->notification, &sequence_reset_vibro);
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
Expand Down
29 changes: 23 additions & 6 deletions base_pack/minesweeper/helpers/mine_sweeper_speaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ static const float volume = 0.8f;

void mine_sweeper_play_ok_sound(void* context) {
MineSweeperApp* app = context;
UNUSED(app);

if (!app->feedback_enabled) {
return;
}

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_LOSE, volume);
Expand All @@ -15,7 +18,10 @@ void mine_sweeper_play_ok_sound(void* context) {

void mine_sweeper_play_flag_sound(void* context) {
MineSweeperApp* app = context;
UNUSED(app);

if (!app->feedback_enabled) {
return;
}

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_FLAG, volume);
Expand All @@ -25,7 +31,10 @@ void mine_sweeper_play_flag_sound(void* context) {

void mine_sweeper_play_oob_sound(void* context) {
MineSweeperApp* app = context;
UNUSED(app);

if (!app->feedback_enabled) {
return;
}

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_OOB, volume);
Expand All @@ -35,7 +44,10 @@ void mine_sweeper_play_oob_sound(void* context) {

void mine_sweeper_play_win_sound(void* context) {
MineSweeperApp* app = context;
UNUSED(app);

if (!app->feedback_enabled) {
return;
}

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_WIN, volume);
Expand All @@ -45,8 +57,10 @@ void mine_sweeper_play_win_sound(void* context) {

void mine_sweeper_play_lose_sound(void* context) {
MineSweeperApp* app = context;
UNUSED(app);

if (!app->feedback_enabled) {
return;
}
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_LOSE, volume);
}
Expand All @@ -55,7 +69,10 @@ void mine_sweeper_play_lose_sound(void* context) {

void mine_sweeper_stop_all_sound(void* context) {
MineSweeperApp* app = context;
UNUSED(app);

if (!app->feedback_enabled) {
return;
}

if(furi_hal_speaker_is_mine()) {
furi_hal_speaker_stop();
Expand Down
25 changes: 12 additions & 13 deletions base_pack/minesweeper/helpers/mine_sweeper_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,20 @@ void mine_sweeper_save_settings(void* context) {
// Store Settings
flipper_format_write_header_cstr(
fff_file, MINESWEEPER_SETTINGS_HEADER, MINESWEEPER_SETTINGS_FILE_VERSION);
flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_LED, &app->led, 1);

uint32_t w = app->settings_info.board_width, h = app->settings_info.board_height, d = app->settings_info.difficulty;
uint32_t w = app->settings_info.board_width,
h = app->settings_info.board_height,
d = app->settings_info.difficulty,
f = app->feedback_enabled;

flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_WIDTH, &w, 1);
flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_HEIGHT, &h, 1);
flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_DIFFICULTY, &d, 1);
flipper_format_write_uint32(
fff_file, MINESWEEPER_SETTINGS_KEY_FEEDBACK, &f, 1);

if(!flipper_format_rewind(fff_file)) {
FURI_LOG_E(TAG, "Rewind error");
Expand Down Expand Up @@ -115,24 +114,24 @@ bool mine_sweeper_read_settings(void* context) {
return false;
}

uint32_t w = 7, h = 16, d = 0;
uint32_t w = 7, h = 16, d = 0, f = 1;
flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_WIDTH, &w, 1);
flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_HEIGHT, &h, 1);
flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_DIFFICULTY, &d, 1);
flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_FEEDBACK, &f, 1);

if (w > 146) {w = 146;}
if (w > 32) {w = 32;}
if (w < 16 ) {w = 16;}
if (h > 64 ) {h = 64;}
if (h > 32 ) {h = 32;}
if (h < 7 ) {h = 7;}
if (d > 2 ) {d = 2;}
if (f > 1) {f = 1;}

app->settings_info.board_width = (uint8_t) w;
app->settings_info.board_height = (uint8_t) h;
app->settings_info.difficulty = (uint8_t) d;
app->feedback_enabled = (uint8_t) f;

flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_read_uint32(fff_file, MINESWEEPER_SETTINGS_KEY_LED, &app->led, 1);

flipper_format_rewind(fff_file);

Expand Down
16 changes: 7 additions & 9 deletions base_pack/minesweeper/helpers/mine_sweeper_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@
#include <flipper_format/flipper_format.h>
#include "../minesweeper.h"

#define MINESWEEPER_SETTINGS_FILE_VERSION 1
#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/f0_mine_sweeper")
#define MINESWEEPER_SETTINGS_SAVE_PATH CONFIG_FILE_DIRECTORY_PATH "/f0_mine_sweeper.conf"
#define MINESWEEPER_SETTINGS_FILE_VERSION 2
#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/mine_sweeper_redux")
#define MINESWEEPER_SETTINGS_SAVE_PATH CONFIG_FILE_DIRECTORY_PATH "/mine_sweeper_redux.conf"
#define MINESWEEPER_SETTINGS_SAVE_PATH_TMP MINESWEEPER_SETTINGS_SAVE_PATH ".tmp"
#define MINESWEEPER_SETTINGS_HEADER "Mine Sweeper Config File"
#define MINESWEEPER_SETTINGS_HEADER "Mine Sweeper Redux Config File"

#define MINESWEEPER_SETTINGS_KEY_WIDTH "BoardWidth"
#define MINESWEEPER_SETTINGS_KEY_HEIGHT "BoardHeight"
#define MINESWEEPER_SETTINGS_KEY_DIFFICULTY "BoardDifficulty"
#define MINESWEEPER_SETTINGS_KEY_FEEDBACK "FeedbackEnabled"

#define MINESWEEPER_SETTINGS_KEY_HAPTIC "Haptic"
#define MINESWEEPER_SETTINGS_KEY_LED "Led"
#define MINESWEEPER_SETTINGS_KEY_SPEAKER "Speaker"

void mine_sweeper_quick_save_feedback(void* context);
void mine_sweeper_save_settings(void* context);
bool mine_sweeper_read_settings(void* context);

#endif
#endif
4 changes: 1 addition & 3 deletions base_pack/minesweeper/minesweeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ static MineSweeperApp* app_alloc() {
app->settings_info.board_width = 16;
app->settings_info.board_height = 7;
app->settings_info.difficulty = 0;
app->haptic = 1;
app->speaker = 1;
app->led = 1;
app->feedback_enabled = 1;

mine_sweeper_save_settings(app);
} else {
Expand Down
6 changes: 2 additions & 4 deletions base_pack/minesweeper/minesweeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ typedef struct MineSweeperApp {
MineSweeperAppSettings settings_info;
MineSweeperAppSettings t_settings_info;

bool is_settings_changed;
uint8_t is_settings_changed;
bool ensure_map_solvable;

uint32_t haptic;
uint32_t speaker;
uint32_t led;
uint8_t feedback_enabled;
} MineSweeperApp;

// View Id Enumeration
Expand Down
18 changes: 13 additions & 5 deletions base_pack/minesweeper/scenes/info_scene.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../minesweeper.h"
static const char* info_string= "GAME INFO BELOW\n\n"
static const char* info_string= "-- GAME INFO BELOW --\n\n"
"1. Press OK to clear a tile.\n\n"
"2. Hold OK on a numbered tile\n"
"to clear all surrounding\n"
Expand All @@ -10,18 +10,26 @@ static const char* info_string= "GAME INFO BELOW\n\n"
"4. Hold back on a cleared\n"
"tile to jump to the\n"
"closest tile.\n\n"
"SETTINGS INFO\n\n"
"--- SETTINGS INFO ---\n\n"
"Difficulty and map\n"
"dimensions can be changed\n"
"in the settings with a\n"
"max map size of 1024\n"
"tiles (32x32).\n\n"
"ENSURE SOLVABLE\n"
"tiles (32x32).\n"
"You will be prompted to\n"
"confirm any changes to these\n"
"settings as it will reset the\n"
"board.\n\n"
"---- FEEDBACK ----\n"
"This settings enables/disables\n"
"Haptic/Sound feedback for the\n"
"game.\n\n"
"- ENSURE SOLVABLE -\n"
"This is a setting that\n"
"enables a board verifier\n"
"when generating a new\n"
"board.\n\n"
"-- WARNING --\n"
"WARNING!:\n"
"This setting will introduce\n"
"a variable amount of\n"
"overhead when generating\n"
Expand Down
Loading

0 comments on commit d50f8b7

Please sign in to comment.