mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 00:48:35 -07:00
Temporarily backport app updates from apps repo
This commit is contained in:
3
applications/external/slots/application.fam
vendored
3
applications/external/slots/application.fam
vendored
@@ -7,10 +7,11 @@ App(
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
fap_icon="ddgame_icon.png",
|
||||
order=30,
|
||||
fap_category="Games",
|
||||
fap_icon_assets="assets",
|
||||
fap_author="@Daniel-dev-s",
|
||||
fap_weburl="https://github.com/Daniel-dev-s/flipperzero-slots",
|
||||
fap_version="1.1",
|
||||
fap_version="1.2",
|
||||
fap_description="Simple Slots simulator game",
|
||||
)
|
||||
|
||||
85
applications/external/slots/slotmachine.c
vendored
85
applications/external/slots/slotmachine.c
vendored
@@ -2,11 +2,11 @@
|
||||
#include <gui/gui.h>
|
||||
#include <gui/elements.h>
|
||||
#include <stdlib.h>
|
||||
#include <storage/storage.h>
|
||||
#include <stdio.h>
|
||||
#include <input/input.h>
|
||||
#include <furi_hal.h>
|
||||
#include "slotmachine_icons.h"
|
||||
#include <assets_icons.h>
|
||||
#include <slotmachine_icons.h>
|
||||
|
||||
const Icon* slot_frames[] = {&I_x2, &I_x3, &I_x4, &I_x2_2, &I_x5};
|
||||
|
||||
@@ -28,19 +28,54 @@ typedef struct {
|
||||
uint16_t bet;
|
||||
double money, winamount;
|
||||
SlotColumn* columns[4];
|
||||
bool winview;
|
||||
bool winview, loseview;
|
||||
} SlotMachineApp;
|
||||
|
||||
typedef struct {
|
||||
int highscore;
|
||||
} SlotsHighscore;
|
||||
|
||||
#define START_MONEY 1500;
|
||||
#define START_BET 300;
|
||||
#define SSRAND_MAX 5;
|
||||
#define SLOTS_RAND_MAX 5;
|
||||
#define DEFAULT_SPEED 16;
|
||||
#define HIGHSCORES_FILENAME APP_DATA_PATH("slotmachine.save")
|
||||
|
||||
uint8_t DEFAULT_SPINNING_TIMES = 10;
|
||||
static SlotsHighscore highscore;
|
||||
|
||||
static bool highscores_load() {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_migrate(storage, EXT_PATH("apps/Games/slotmachine.save"), HIGHSCORES_FILENAME);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
uint16_t bytes_readed = 0;
|
||||
|
||||
if(storage_file_open(file, HIGHSCORES_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
bytes_readed = storage_file_read(file, &highscore, sizeof(SlotsHighscore));
|
||||
}
|
||||
storage_file_close(file);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return bytes_readed == sizeof(SlotsHighscore);
|
||||
}
|
||||
|
||||
static void highscores_save() {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
if(storage_file_open(file, HIGHSCORES_FILENAME, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
||||
storage_file_write(file, &highscore, sizeof(SlotsHighscore));
|
||||
}
|
||||
storage_file_close(file);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
void game_results(SlotMachineApp* app) {
|
||||
int matches[] = {0, 0, 0, 0, 0};
|
||||
|
||||
double total = 0;
|
||||
|
||||
for(int i = 0; i < COLUMNS_COUNT; i++) {
|
||||
@@ -57,6 +92,15 @@ void game_results(SlotMachineApp* app) {
|
||||
app->money += total;
|
||||
app->winamount = total;
|
||||
app->winview = true;
|
||||
|
||||
if(total > highscore.highscore) {
|
||||
highscore.highscore = total;
|
||||
highscores_save();
|
||||
}
|
||||
}
|
||||
|
||||
if(app->money < 10) {
|
||||
app->loseview = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,18 +146,23 @@ void slotmachine_draw_callback(Canvas* canvas, void* ctx) {
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 10, "Slots");
|
||||
canvas_draw_icon(canvas, 30, 3, &I_little_coin);
|
||||
const Icon* litl_icon = &I_little_coin;
|
||||
canvas_draw_icon(canvas, 30, 3, litl_icon);
|
||||
|
||||
char moneyStr[15];
|
||||
snprintf(moneyStr, sizeof(moneyStr), "$%.0f", slotmachine->money);
|
||||
|
||||
char highscoresStr[25];
|
||||
snprintf(highscoresStr, sizeof(highscoresStr), "HS:$%d", highscore.highscore);
|
||||
|
||||
char betStr[7];
|
||||
snprintf(betStr, sizeof(betStr), "$%d", slotmachine->bet);
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 45, 10, moneyStr);
|
||||
canvas_draw_str(canvas, 40, 10, moneyStr);
|
||||
canvas_draw_str(canvas, 2, canvas_height(canvas) - 3, "Bet:");
|
||||
canvas_draw_str(canvas, 20, canvas_height(canvas) - 3, betStr);
|
||||
canvas_draw_str(canvas, 75, 10, highscoresStr);
|
||||
|
||||
if(slotmachine->winview) {
|
||||
char winamountStr[30];
|
||||
@@ -123,6 +172,13 @@ void slotmachine_draw_callback(Canvas* canvas, void* ctx) {
|
||||
canvas_draw_str(canvas, 2, 35, winamountStr);
|
||||
drawButton(canvas, 95, 52, "Ok", false);
|
||||
|
||||
furi_mutex_release(slotmachine->model_mutex);
|
||||
return;
|
||||
} else if(slotmachine->loseview) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 35, "You lose ;(");
|
||||
drawButton(canvas, 95, 52, "Ok", false);
|
||||
|
||||
furi_mutex_release(slotmachine->model_mutex);
|
||||
return;
|
||||
}
|
||||
@@ -135,7 +191,7 @@ void slotmachine_draw_callback(Canvas* canvas, void* ctx) {
|
||||
slotmachine->columns[i]->y = 13;
|
||||
slotmachine->columns[i]->times--;
|
||||
slotmachine->columns[i]->speed--;
|
||||
slotmachine->columns[i]->value = rand() % SSRAND_MAX;
|
||||
slotmachine->columns[i]->value = rand() % SLOTS_RAND_MAX;
|
||||
|
||||
if(slotmachine->columns[i]->times == 0) {
|
||||
slotmachine->columns[i]->y = 23;
|
||||
@@ -185,6 +241,7 @@ SlotMachineApp* slotmachine_app_alloc() {
|
||||
app->money = START_MONEY;
|
||||
app->bet = START_BET;
|
||||
app->winview = false;
|
||||
app->loseview = false;
|
||||
app->winamount = 0;
|
||||
|
||||
int x = 7;
|
||||
@@ -222,6 +279,9 @@ int32_t slotmachine_app(void* p) {
|
||||
SlotMachineApp* slotmachine = slotmachine_app_alloc();
|
||||
InputEvent input;
|
||||
|
||||
if(!highscores_load()) {
|
||||
memset(&highscore, 0, sizeof(highscore));
|
||||
}
|
||||
// endless input cycle
|
||||
while(1) {
|
||||
if(furi_message_queue_get(slotmachine->input_queue, &input, 100) == FuriStatusOk) {
|
||||
@@ -231,13 +291,15 @@ int32_t slotmachine_app(void* p) {
|
||||
|
||||
if(!checkIsSpinning(slotmachine)) {
|
||||
if(input.key == InputKeyBack) {
|
||||
highscores_save();
|
||||
// exit on back button
|
||||
furi_mutex_release(slotmachine->model_mutex);
|
||||
break;
|
||||
} else if(
|
||||
input.key == InputKeyOk && input.type == InputTypeShort &&
|
||||
slotmachine->winview) {
|
||||
(slotmachine->winview || slotmachine->loseview)) {
|
||||
slotmachine->winview = false;
|
||||
slotmachine->loseview = false;
|
||||
} else if(
|
||||
input.key == InputKeyOk && input.type == InputTypeShort &&
|
||||
slotmachine->bet <= slotmachine->money) {
|
||||
@@ -250,13 +312,16 @@ int32_t slotmachine_app(void* p) {
|
||||
slotmachine->columns[i]->speed = DEFAULT_SPEED;
|
||||
}
|
||||
} else if(input.key == InputKeyUp) {
|
||||
if(slotmachine->bet + 10 < slotmachine->money) {
|
||||
if(slotmachine->bet + 10 <= slotmachine->money) {
|
||||
slotmachine->bet += 10;
|
||||
}
|
||||
} else if(input.key == InputKeyDown) {
|
||||
if(slotmachine->bet - 10 > 0) {
|
||||
slotmachine->bet -= 10;
|
||||
}
|
||||
} else if(input.key == InputKeyLeft && input.type == InputTypeLong) {
|
||||
memset(&highscore, 0, sizeof(highscore));
|
||||
highscores_save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user