simon_says.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. #include <furi.h>
  2. #include <furi_hal.h>
  3. #include <storage/storage.h>
  4. #include <gui/gui.h>
  5. #include <gui/elements.h>
  6. #include <gui/icon.h>
  7. #include <input/input.h>
  8. #include <notification/notification.h>
  9. #include <notification/notification_messages.h>
  10. #include <stdbool.h> // Header-file for boolean data-type.
  11. #include <stdio.h>
  12. #include <string.h>
  13. /* generated by fbt from .png files in images folder */
  14. #include <simon_says_icons.h>
  15. #define TAG "Simon" // Used for logging
  16. #define DEBUG_MSG 1
  17. #define SCREEN_XRES 128
  18. #define SCREEN_YRES 64
  19. #define BOARD_X 72 // Used for board placement
  20. #define BOARD_Y 8
  21. #define GAME_START_LIVES 3
  22. #define SAVING_DIRECTORY "/ext/apps/Games"
  23. #define SAVING_FILENAME SAVING_DIRECTORY "/game_simon_says.save"
  24. // Define Notes
  25. // Shamelessly stolen from Ocarina application
  26. // https://github.com/invalidna-me/flipperzero-ocarina
  27. #define NOTE_UP 587.33f
  28. #define NOTE_LEFT 493.88f
  29. #define NOTE_RIGHT 440.00f
  30. #define NOTE_DOWN 349.23
  31. #define NOTE_OK 293.66f
  32. /* ============================ Data structures ============================= */
  33. typedef enum game_state { preloading, mainMenu, inGame, gameOver, gameVictory } game_state;
  34. typedef enum difficulty_mode { normal, hard } difficulty_mode;
  35. typedef enum shape_names { up, down, left, right, number_of_shapes } Direction;
  36. typedef enum currently_playing { simon, player } currently_playing;
  37. typedef struct {
  38. /* Game state. */
  39. enum game_state gameState; // This is the current game state
  40. bool gameover; /* if true then switch to the game over state */
  41. bool is_wrong_direction; /* Is the last direction wrong? */
  42. enum currently_playing activePlayer; // This is used to track who is playing at the moment
  43. uint32_t lives; /* Number of lives in the current game. */
  44. enum difficulty_mode difficultyMode; // This is the difficulty mode for the current game
  45. bool sound_enabled; // This is the sound enabled flag for the current game
  46. float volume; // This is the volume for the current game
  47. /* Handle Score */
  48. int currentScore; // This is the score for the current
  49. int highScore; /* Highscore. Shown on Game Over Screen */
  50. bool is_new_highscore; /* Is the last score a new highscore? */
  51. /* Handle Shape Display */
  52. uint32_t numberOfMillisecondsBeforeShapeDisappears; // This defines the speed of the game
  53. enum shape_names simonMoves[1000]; // Store the sequence of shapes that Simon plays
  54. enum shape_names selectedShape; // This is used to track the shape that the player has selected
  55. bool set_board_neutral; // This is used to track if the board should be neutral or not
  56. int moveIndex; // This is used to track the current move in the sequence
  57. uint32_t last_button_press_tick;
  58. NotificationApp* notification;
  59. FuriMutex* mutex;
  60. } SimonData;
  61. /* ============================== Sequences ============================== */
  62. const NotificationSequence sequence_wrong_move = {
  63. &message_red_255,
  64. &message_vibro_on,
  65. // &message_note_g5, // Play sound but currently disabled
  66. &message_delay_25,
  67. // &message_note_e5,
  68. &message_vibro_off,
  69. &message_sound_off,
  70. NULL,
  71. };
  72. const NotificationSequence sequence_player_submit_move = {
  73. &message_vibro_on,
  74. // &message_note_g5, // Play sound but currently disabled. Need On/Off menu setting
  75. &message_delay_10,
  76. &message_delay_1,
  77. &message_delay_1,
  78. &message_delay_1,
  79. &message_delay_1,
  80. &message_delay_1,
  81. // &message_note_e5,
  82. &message_vibro_off,
  83. &message_sound_off,
  84. NULL,
  85. };
  86. const NotificationSequence sequence_up = {
  87. // &message_vibro_on,
  88. &message_note_g4,
  89. &message_delay_100,
  90. // &message_vibro_off,
  91. &message_sound_off,
  92. NULL,
  93. };
  94. const NotificationSequence sequence_down = {
  95. // &message_vibro_on,
  96. &message_note_c3,
  97. &message_delay_100,
  98. // &message_vibro_off,
  99. &message_sound_off,
  100. NULL,
  101. };
  102. const NotificationSequence sequence_left = {
  103. // &message_vibro_on,
  104. &message_note_e3,
  105. &message_delay_100,
  106. // &message_vibro_off,
  107. &message_sound_off,
  108. NULL,
  109. };
  110. const NotificationSequence sequence_right = {
  111. // &message_vibro_on,
  112. &message_note_g3,
  113. &message_delay_100,
  114. // &message_vibro_off,
  115. &message_sound_off,
  116. NULL,
  117. };
  118. // Indicate that it's Simon's turn
  119. const NotificationSequence sequence_simon_is_playing = {
  120. &message_red_255,
  121. &message_do_not_reset,
  122. NULL,
  123. };
  124. // Indicate that it's the Player's turn
  125. const NotificationSequence sequence_player_is_playing = {
  126. &message_red_0,
  127. &message_do_not_reset,
  128. NULL,
  129. };
  130. const NotificationSequence sequence_cleanup = {
  131. &message_red_0,
  132. &message_green_0,
  133. &message_blue_0,
  134. &message_sound_off,
  135. &message_vibro_off,
  136. NULL,
  137. };
  138. /* ============================ 2D drawing ================================== */
  139. /* Display remaining lives in the center of the board */
  140. void draw_remaining_lives(Canvas* canvas, const SimonData* simon_state) {
  141. // Convert score to string
  142. // int length = snprintf(NULL, 0, "%lu", simon_state->lives);
  143. // char* str_lives_remaining = malloc(length + 1);
  144. // snprintf(str_lives_remaining, length + 1, "%lu", simon_state->lives);
  145. // TODO: Make it a Simon Says icon on top right
  146. canvas_set_color(canvas, ColorBlack);
  147. canvas_set_font(canvas, FontSecondary);
  148. int x = SCREEN_XRES - 6;
  149. int lives = simon_state->lives;
  150. while(lives--) {
  151. canvas_draw_str(canvas, x, 8, "*");
  152. x -= 7;
  153. }
  154. }
  155. void draw_current_score(Canvas* canvas, const SimonData* simon_data) {
  156. /* Draw Game Score. */
  157. canvas_set_color(canvas, ColorXOR);
  158. canvas_set_font(canvas, FontSecondary);
  159. char str_score[32];
  160. snprintf(str_score, sizeof(str_score), "%i", simon_data->currentScore);
  161. canvas_draw_str_aligned(canvas, SCREEN_XRES / 2 + 4, 2, AlignCenter, AlignTop, str_score);
  162. }
  163. void play_sound_up(const SimonData* app) {
  164. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  165. furi_hal_speaker_start(NOTE_UP, app->volume);
  166. }
  167. }
  168. void play_sound_down(const SimonData* app) {
  169. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  170. furi_hal_speaker_start(NOTE_DOWN, app->volume);
  171. }
  172. }
  173. void play_sound_left(const SimonData* app) {
  174. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  175. furi_hal_speaker_start(NOTE_LEFT, app->volume);
  176. }
  177. }
  178. void play_sound_right(const SimonData* app) {
  179. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  180. furi_hal_speaker_start(NOTE_RIGHT, app->volume);
  181. }
  182. }
  183. void stop_sound() {
  184. if(furi_hal_speaker_is_mine()) {
  185. furi_hal_speaker_stop();
  186. furi_hal_speaker_release();
  187. }
  188. }
  189. /* Main Render Function */
  190. void simon_draw_callback(Canvas* canvas, void* ctx) {
  191. furi_assert(ctx);
  192. const SimonData* simon_state = ctx;
  193. furi_mutex_acquire(simon_state->mutex, FuriWaitForever);
  194. canvas_clear(canvas);
  195. // ######################### Main Menu #########################
  196. // Show Main Menu
  197. if(simon_state->gameState == mainMenu) {
  198. // Draw border frame
  199. canvas_draw_frame(canvas, 1, 1, SCREEN_XRES - 1, SCREEN_YRES - 1); // Border
  200. // Draw Simon text banner
  201. canvas_set_font(canvas, FontSecondary);
  202. canvas_set_color(canvas, ColorBlack);
  203. canvas_draw_str_aligned(
  204. canvas,
  205. SCREEN_XRES / 2,
  206. SCREEN_YRES / 2 - 4,
  207. AlignCenter,
  208. AlignCenter,
  209. "Welcome to Simon Says");
  210. // Display Press OK to start below title
  211. canvas_set_color(canvas, ColorXOR);
  212. canvas_draw_str_aligned(
  213. canvas,
  214. SCREEN_XRES / 2,
  215. SCREEN_YRES / 2 + 10,
  216. AlignCenter,
  217. AlignCenter,
  218. "Press OK to start");
  219. }
  220. // ######################### in Game #########################
  221. //@todo Render Callback
  222. // We're in an active game
  223. if(simon_state->gameState == inGame) {
  224. // Draw Current Score
  225. draw_current_score(canvas, simon_state);
  226. // Draw Lives
  227. draw_remaining_lives(canvas, simon_state);
  228. // Draw Simon Pose
  229. if(simon_state->activePlayer == player) {
  230. // Player's turn
  231. canvas_draw_icon(canvas, 0, 4, &I_DolphinWait_61x59);
  232. } else {
  233. // Simon's turn
  234. canvas_draw_icon(canvas, 0, 4, &I_DolphinTalking_59x63);
  235. }
  236. if(simon_state->set_board_neutral) {
  237. // Draw Neutral Board
  238. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_board); // Draw Board
  239. // Stop Sound TODO: Move this to a better place
  240. //@todo Sound
  241. stop_sound();
  242. } else {
  243. switch(simon_state->selectedShape) {
  244. case up:
  245. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_up); // Draw Up
  246. play_sound_up(simon_state);
  247. break;
  248. case down:
  249. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_down); // Draw Down
  250. play_sound_down(simon_state);
  251. break;
  252. case left:
  253. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_left); // Draw Left
  254. play_sound_left(simon_state);
  255. break;
  256. case right:
  257. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_right); // Draw Right
  258. play_sound_right(simon_state);
  259. break;
  260. default:
  261. if(DEBUG_MSG)
  262. FURI_LOG_E(
  263. TAG, "Invalid shape: %d", simon_state->simonMoves[simon_state->moveIndex]);
  264. break;
  265. }
  266. }
  267. }
  268. // ######################### Game Over #########################
  269. if(simon_state->gameState == gameOver) {
  270. stop_sound(); //TODO: Make a game over sequence
  271. canvas_set_color(canvas, ColorXOR);
  272. canvas_set_font(canvas, FontPrimary);
  273. // TODO: if new highscore, display blinking "New High Score"
  274. // Display High Score Text
  275. if(simon_state->is_new_highscore) {
  276. canvas_draw_str_aligned(
  277. canvas, SCREEN_XRES / 2, 6, AlignCenter, AlignTop, "New High Score!");
  278. } else {
  279. canvas_draw_str_aligned(
  280. canvas, SCREEN_XRES / 2, 6, AlignCenter, AlignTop, "High Score");
  281. }
  282. // Convert highscore to string
  283. int length = snprintf(NULL, 0, "%i", simon_state->highScore);
  284. char* str_high_score = malloc(length + 1);
  285. snprintf(str_high_score, length + 1, "%i", simon_state->highScore);
  286. // Display High Score
  287. canvas_draw_str_aligned(
  288. canvas, SCREEN_XRES / 2, 22, AlignCenter, AlignCenter, str_high_score);
  289. free(str_high_score);
  290. // Display Game Over
  291. canvas_draw_str_aligned(
  292. canvas, SCREEN_XRES / 2, SCREEN_YRES / 2 + 2, AlignCenter, AlignCenter, "GAME OVER");
  293. // Display Press OK to restart below title
  294. canvas_set_font(canvas, FontSecondary);
  295. canvas_draw_str_aligned(
  296. canvas,
  297. SCREEN_XRES / 2,
  298. SCREEN_YRES / 2 + 15,
  299. AlignCenter,
  300. AlignCenter,
  301. "Press OK to restart");
  302. }
  303. // ######################### Victory #########################
  304. //Player Beat Simon beyond limit! A word record holder here!
  305. //TODO
  306. //release the mutex
  307. furi_mutex_release(simon_state->mutex);
  308. }
  309. /* ======================== Input Handling ============================== */
  310. void simon_input_callback(InputEvent* input_event, void* ctx) {
  311. furi_assert(ctx);
  312. FuriMessageQueue* event_queue = ctx;
  313. furi_message_queue_put(event_queue, input_event, FuriWaitForever);
  314. }
  315. /* ======================== Simon Game Engine ======================== */
  316. bool load_game(SimonData* app) {
  317. Storage* storage = furi_record_open(RECORD_STORAGE);
  318. File* file = storage_file_alloc(storage);
  319. uint16_t bytes_readed = 0;
  320. if(storage_file_open(file, SAVING_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
  321. if(storage_file_size(file) > sizeof(SimonData)) {
  322. storage_simply_remove(storage, SAVING_FILENAME);
  323. FURI_LOG_E(
  324. TAG, "Error: file is larger than the data structure! The file has been deleted.");
  325. } else {
  326. bytes_readed = storage_file_read(file, app, sizeof(SimonData));
  327. }
  328. storage_file_close(file);
  329. storage_file_free(file);
  330. }
  331. furi_record_close(RECORD_STORAGE);
  332. return bytes_readed == sizeof(SimonData);
  333. }
  334. void save_game(SimonData* app) {
  335. Storage* storage = furi_record_open(RECORD_STORAGE);
  336. if(storage_common_stat(storage, SAVING_DIRECTORY, NULL) == FSE_NOT_EXIST) {
  337. if(!storage_simply_mkdir(storage, SAVING_DIRECTORY)) {
  338. return;
  339. }
  340. }
  341. File* file = storage_file_alloc(storage);
  342. if(storage_file_open(file, SAVING_FILENAME, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
  343. storage_file_write(file, app, sizeof(SimonData));
  344. }
  345. storage_file_close(file);
  346. storage_file_free(file);
  347. furi_record_close(RECORD_STORAGE);
  348. }
  349. int getRandomIntInRange(int lower, int upper) {
  350. return (rand() % (upper - lower + 1)) + lower;
  351. }
  352. void play_sound_sequence_correct() {
  353. notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_success);
  354. }
  355. void play_sound_wrong_move() {
  356. //TODO: play wrong sound: Try sequence_audiovisual_alert
  357. notification_message(furi_record_open(RECORD_NOTIFICATION), &sequence_error);
  358. }
  359. /* Restart game and give player a chance to try again on same sequence */
  360. // @todo restartGame
  361. void resetGame(SimonData* app) {
  362. app->moveIndex = 0;
  363. app->numberOfMillisecondsBeforeShapeDisappears = 500;
  364. app->activePlayer = simon;
  365. app->is_wrong_direction = false;
  366. app->last_button_press_tick = 0;
  367. app->set_board_neutral = true;
  368. app->activePlayer = simon;
  369. }
  370. /* Set gameover state */
  371. void game_over(SimonData* app) {
  372. if(app->is_new_highscore) save_game(app); // Save highscore but only on change
  373. app->gameover = true;
  374. app->lives = GAME_START_LIVES; // Show 3 lives in game over screen to match new game start
  375. app->gameState = gameOver;
  376. }
  377. /* Called after gameover to restart the game. This function
  378. * also calls restart_game(). */
  379. void restart_game_after_gameover(SimonData* app) {
  380. app->volume = 1.0f; //TODO: make this a setting
  381. app->gameState = inGame;
  382. app->gameover = false;
  383. app->currentScore = 0;
  384. app->is_new_highscore = false;
  385. app->lives = GAME_START_LIVES;
  386. app->simonMoves[0] = rand() % number_of_shapes;
  387. resetGame(app);
  388. }
  389. void addNewSimonMove(int addAtIndex, SimonData* app) {
  390. app->simonMoves[addAtIndex] = getRandomIntInRange(0, 3);
  391. }
  392. void startNewRound(SimonData* app) {
  393. addNewSimonMove(app->currentScore, app);
  394. app->moveIndex = 0;
  395. app->activePlayer = simon;
  396. }
  397. void onPlayerAnsweredCorrect(SimonData* app) {
  398. app->moveIndex++;
  399. }
  400. void onPlayerAnsweredWrong(SimonData* app) {
  401. if(app->lives > 0) {
  402. app->lives--;
  403. // Play the wrong sound
  404. if(app->sound_enabled) {
  405. play_sound_wrong_move();
  406. }
  407. resetGame(app);
  408. } else {
  409. // The player has no lives left
  410. // Game over
  411. game_over(app);
  412. //TODO: Play unique game over sound
  413. }
  414. }
  415. bool isRoundComplete(SimonData* app) {
  416. return app->moveIndex == app->currentScore;
  417. }
  418. enum shape_names getCurrentSimonMove(SimonData* app) {
  419. return app->simonMoves[app->moveIndex];
  420. }
  421. void onPlayerSelectedShapeCallback(enum shape_names shape, SimonData* app) {
  422. if(shape == getCurrentSimonMove(app)) {
  423. onPlayerAnsweredCorrect(app);
  424. } else {
  425. onPlayerAnsweredWrong(app);
  426. }
  427. }
  428. //@todo gametick
  429. void game_tick(SimonData* simon_state) {
  430. if(simon_state->gameState == inGame) {
  431. if(simon_state->activePlayer == simon) {
  432. // ############### Simon Turn ###############
  433. notification_message(simon_state->notification, &sequence_simon_is_playing);
  434. //@todo Gameplay
  435. if(simon_state->set_board_neutral) {
  436. if(simon_state->moveIndex < simon_state->currentScore) {
  437. simon_state->selectedShape = getCurrentSimonMove(simon_state);
  438. simon_state->set_board_neutral = false;
  439. simon_state->moveIndex++;
  440. } else {
  441. simon_state->activePlayer = player;
  442. simon_state->set_board_neutral = true;
  443. simon_state->moveIndex = 0;
  444. }
  445. } else {
  446. simon_state->set_board_neutral = true;
  447. }
  448. } else {
  449. // ############### Player Turn ###############
  450. notification_message(simon_state->notification, &sequence_player_is_playing);
  451. // It's Player's Turn
  452. if(isRoundComplete(simon_state)) {
  453. simon_state->activePlayer = simon;
  454. simon_state->currentScore++;
  455. // app->numberOfMillisecondsBeforeShapeDisappears -= 50;
  456. //TODO: Hacky way of handling highscore by subtracting 1 to account for the first move
  457. if(simon_state->currentScore - 1 > simon_state->highScore) {
  458. simon_state->highScore = simon_state->currentScore - 1;
  459. simon_state->is_new_highscore = true;
  460. }
  461. if(simon_state->sound_enabled) {
  462. play_sound_sequence_correct();
  463. }
  464. startNewRound(simon_state);
  465. }
  466. }
  467. }
  468. }
  469. /* ======================== Main Entry Point ============================== */
  470. int32_t simon_says_app_entry(void* p) {
  471. UNUSED(p);
  472. FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  473. SimonData* simon_state = malloc(sizeof(SimonData));
  474. simon_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
  475. if(!simon_state->mutex) {
  476. FURI_LOG_E(TAG, "cannot create mutex\r\n");
  477. free(simon_state);
  478. return -1;
  479. }
  480. // Configure view port
  481. ViewPort* view_port = view_port_alloc();
  482. view_port_draw_callback_set(view_port, simon_draw_callback, simon_state);
  483. view_port_input_callback_set(view_port, simon_input_callback, event_queue);
  484. // Register view port in GUI
  485. Gui* gui = furi_record_open(RECORD_GUI);
  486. gui_add_view_port(gui, view_port, GuiLayerFullscreen);
  487. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  488. simon_state->notification = notification;
  489. InputEvent input;
  490. // Show Main Menu Screen
  491. //load_game(simon_state);
  492. restart_game_after_gameover(simon_state);
  493. simon_state->gameState = mainMenu;
  494. while(true) {
  495. game_tick(simon_state);
  496. FuriStatus q_status = furi_message_queue_get(
  497. event_queue, &input, simon_state->numberOfMillisecondsBeforeShapeDisappears);
  498. furi_mutex_acquire(simon_state->mutex, FuriWaitForever);
  499. if(q_status == FuriStatusOk) {
  500. //FURI_LOG_D(TAG, "Got input event: %d", input.key);
  501. //break out of the loop if the back key is pressed
  502. if(input.key == InputKeyBack && input.type == InputTypeLong) {
  503. // Save high score before quitting
  504. //if(simon_state->is_new_highscore) {
  505. // save_game(simon_state);
  506. //}
  507. break;
  508. }
  509. //@todo Set Game States
  510. if(input.key == InputKeyOk && simon_state->gameState != inGame) {
  511. restart_game_after_gameover(simon_state);
  512. // Set Simon Board state
  513. startNewRound(simon_state);
  514. view_port_update(view_port);
  515. }
  516. // Keep LED on if it is Simon's turn
  517. if(simon_state->activePlayer == player) {
  518. notification_message(notification, &sequence_player_is_playing);
  519. if(input.type == InputTypePress) {
  520. simon_state->set_board_neutral = false;
  521. switch(input.key) {
  522. case InputKeyUp:
  523. simon_state->selectedShape = up;
  524. onPlayerSelectedShapeCallback(up, simon_state);
  525. break;
  526. case InputKeyDown:
  527. simon_state->selectedShape = down;
  528. onPlayerSelectedShapeCallback(down, simon_state);
  529. break;
  530. case InputKeyLeft:
  531. simon_state->selectedShape = left;
  532. onPlayerSelectedShapeCallback(left, simon_state);
  533. break;
  534. case InputKeyRight:
  535. simon_state->selectedShape = right;
  536. onPlayerSelectedShapeCallback(right, simon_state);
  537. break;
  538. default:
  539. simon_state->set_board_neutral = true;
  540. break;
  541. }
  542. } else {
  543. //FURI_LOG_D(TAG, "Input type is not short");
  544. simon_state->set_board_neutral = true;
  545. }
  546. }
  547. }
  548. // @todo Animation Loop for debug
  549. // if(simon_state->gameState == inGame && simon_state->activePlayer == simon) {
  550. // simon_state->currentScore++;
  551. // simon_state->set_board_neutral = !simon_state->set_board_neutral;
  552. // }
  553. view_port_update(view_port);
  554. furi_mutex_release(simon_state->mutex);
  555. }
  556. stop_sound();
  557. notification_message(notification, &sequence_cleanup);
  558. gui_remove_view_port(gui, view_port);
  559. view_port_free(view_port);
  560. furi_message_queue_free(event_queue);
  561. furi_mutex_free(simon_state->mutex);
  562. furi_record_close(RECORD_NOTIFICATION);
  563. furi_record_close(RECORD_GUI);
  564. free(simon_state);
  565. return 0;
  566. }