Skip to content

Commit

Permalink
upd minesweeper
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Jan 12, 2024
1 parent 590288e commit 978271b
Show file tree
Hide file tree
Showing 13 changed files with 428 additions and 74 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.0",
fap_version="1.1",
fap_description="Flipper Zero Minesweeper Implementation",
fap_author="Alexander Rodriguez",
fap_weburl="https://github.com/squee72564/F0_Minesweeper_Fap",
Expand Down
19 changes: 18 additions & 1 deletion base_pack/minesweeper/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@

# Changelog
## TODO:
- Implement LED and haptic feedback
- 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.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

## Version 1.0.0 - 1/10/2024

Expand Down
50 changes: 50 additions & 0 deletions base_pack/minesweeper/helpers/mine_sweeper_haptic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "mine_sweeper_haptic.h"
#include "../minesweeper.h"


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

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_long_ok_bump(void* context) {
MineSweeperApp* app = context;

for (int i = 0; i < 2; i++) {
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);
}
}

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

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);
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
notification_message(app->notification, &sequence_reset_vibro);
furi_thread_flags_wait(0, FuriFlagWaitAny, 400);
}

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);
furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
notification_message(app->notification, &sequence_reset_vibro);
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
}
}
17 changes: 17 additions & 0 deletions base_pack/minesweeper/helpers/mine_sweeper_haptic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef MINESWEEPER_HAPTIC_H
#define MINESWEEPER_HAPTIC_H

#include <notification/notification_messages.h>

void mine_sweeper_play_happy_bump(void* context);

void mine_sweeper_play_long_ok_bump(void* context);

void mine_sweeper_play_oob_bump(void* context);

void mine_sweeper_play_lose_bump(void* context);

void mine_sweeper_play_win_bump(void* context);


#endif
61 changes: 61 additions & 0 deletions base_pack/minesweeper/helpers/mine_sweeper_led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "mine_sweeper_led.h"
#include "../minesweeper.h"



void mine_sweeper_led_set_rgb(void* context, int red, int green, int blue) {
MineSweeperApp* app = context;

NotificationMessage notification_led_message_1;
notification_led_message_1.type = NotificationMessageTypeLedRed;
NotificationMessage notification_led_message_2;
notification_led_message_2.type = NotificationMessageTypeLedGreen;
NotificationMessage notification_led_message_3;
notification_led_message_3.type = NotificationMessageTypeLedBlue;

notification_led_message_1.data.led.value = red;
notification_led_message_2.data.led.value = green;
notification_led_message_3.data.led.value = blue;
const NotificationSequence notification_sequence = {
&notification_led_message_1,
&notification_led_message_2,
&notification_led_message_3,
&message_do_not_reset,
NULL,
};
notification_message(app->notification, &notification_sequence);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
}

void mine_sweeper_led_blink_red(void* context) {
furi_assert(context);
MineSweeperApp* app = context;

notification_message(app->notification, &sequence_blink_red_100);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
}

void mine_sweeper_led_blink_magenta(void* context) {
furi_assert(context);
MineSweeperApp* app = context;

notification_message(app->notification, &sequence_blink_magenta_100);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
}

void mine_sweeper_led_blink_cyan(void* context) {
furi_assert(context);
MineSweeperApp* app = context;

notification_message(app->notification, &sequence_blink_cyan_100);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
}

void mine_sweeper_led_reset(void* context) {
MineSweeperApp* app = context;
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);

furi_thread_flags_wait(0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set
}
15 changes: 15 additions & 0 deletions base_pack/minesweeper/helpers/mine_sweeper_led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef MINESWEEPER_LED_H
#define MINESWEEPER_LED_H

void mine_sweeper_led_set_rgb(void* context, int red, int green, int blue);

void mine_sweeper_led_blink_red(void* context);

void mine_sweeper_led_blink_magenta(void* context);

void mine_sweeper_led_blink_cyan(void* context);

void mine_sweeper_led_reset(void* context);


#endif
64 changes: 64 additions & 0 deletions base_pack/minesweeper/helpers/mine_sweeper_speaker.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "mine_sweeper_speaker.h"
#include "../minesweeper.h"

static const float volume = 0.8f;

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

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_LOSE, volume);
}

}

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

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_FLAG, volume);
}

}

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

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_OOB, volume);
}

}

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

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_WIN, volume);
}

}

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

if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_LOSE, volume);
}

}

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

if(furi_hal_speaker_is_mine()) {
furi_hal_speaker_stop();
furi_hal_speaker_release();
}
}
18 changes: 18 additions & 0 deletions base_pack/minesweeper/helpers/mine_sweeper_speaker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef MINESWEEPER_SPEAKER_H
#define MINESWEEPER_SPEAKER_H

#define NOTE_OK 3078.95f //G_4
#define NOTE_FLAG 384.87f //G_4
#define NOTE_OOB 342.88f //F_4
#define NOTE_WIN 432.00f //Divine
#define NOTE_LOSE 4170.00f //Cursed

void mine_sweeper_play_ok_sound(void* context);
void mine_sweeper_play_flag_sound(void* context);
void mine_sweeper_play_oob_sound(void* context);
void mine_sweeper_play_win_sound(void* context);
void mine_sweeper_play_lose_sound(void* context);
void mine_sweeper_stop_all_sound(void* context);


#endif
5 changes: 4 additions & 1 deletion base_pack/minesweeper/helpers/mine_sweeper_storage.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef MINESWEEPER_STORAGE_H
#define MINESWEEPER_STORAGE_H

#include <stdlib.h>
#include <string.h>
Expand All @@ -22,3 +23,5 @@

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

#endif
Loading

0 comments on commit 978271b

Please sign in to comment.