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