simon_says.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. uint32_t last_shape_displayed_ms; // This is used to time the interval between displaying shapes
  54. enum shape_names simonMoves[1000]; // Store the sequence of shapes that Simon plays
  55. enum shape_names selectedShape; // This is used to track the shape that the player has selected
  56. bool shapeConsumed; // Tracks whether shape has been checked or not
  57. bool set_board_neutral; // This is used to track if the board should be neutral or not
  58. int moveIndex; // This is used to track the current move in the sequence
  59. enum shape_names selected;
  60. enum shape_names board_state; // TODO: This may be redundant by selected
  61. uint32_t last_button_press_tick;
  62. NotificationApp* notification;
  63. } SimonData;
  64. /* ============================== Sequences ============================== */
  65. const NotificationSequence sequence_wrong_move = {
  66. &message_red_255,
  67. &message_vibro_on,
  68. // &message_note_g5, // Play sound but currently disabled
  69. &message_delay_25,
  70. // &message_note_e5,
  71. &message_vibro_off,
  72. &message_sound_off,
  73. NULL,
  74. };
  75. const NotificationSequence sequence_player_submit_move = {
  76. &message_vibro_on,
  77. // &message_note_g5, // Play sound but currently disabled. Need On/Off menu setting
  78. &message_delay_10,
  79. &message_delay_1,
  80. &message_delay_1,
  81. &message_delay_1,
  82. &message_delay_1,
  83. &message_delay_1,
  84. // &message_note_e5,
  85. &message_vibro_off,
  86. &message_sound_off,
  87. NULL,
  88. };
  89. const NotificationSequence sequence_up = {
  90. // &message_vibro_on,
  91. &message_note_g4,
  92. &message_delay_100,
  93. // &message_vibro_off,
  94. &message_sound_off,
  95. NULL,
  96. };
  97. const NotificationSequence sequence_down = {
  98. // &message_vibro_on,
  99. &message_note_c3,
  100. &message_delay_100,
  101. // &message_vibro_off,
  102. &message_sound_off,
  103. NULL,
  104. };
  105. const NotificationSequence sequence_left = {
  106. // &message_vibro_on,
  107. &message_note_e3,
  108. &message_delay_100,
  109. // &message_vibro_off,
  110. &message_sound_off,
  111. NULL,
  112. };
  113. const NotificationSequence sequence_right = {
  114. // &message_vibro_on,
  115. &message_note_g3,
  116. &message_delay_100,
  117. // &message_vibro_off,
  118. &message_sound_off,
  119. NULL,
  120. };
  121. // Indicate that it's Simon's turn
  122. const NotificationSequence sequence_simon_is_playing = {
  123. &message_red_255,
  124. &message_do_not_reset,
  125. NULL,
  126. };
  127. // Indicate that it's the Player's turn
  128. const NotificationSequence sequence_player_is_playing = {
  129. &message_red_0,
  130. &message_do_not_reset,
  131. NULL,
  132. };
  133. const NotificationSequence sequence_cleanup = {
  134. &message_red_0,
  135. &message_green_0,
  136. &message_blue_0,
  137. &message_sound_off,
  138. &message_vibro_off,
  139. NULL,
  140. };
  141. /* ============================ 2D drawing ================================== */
  142. /* Display remaining lives in the center of the board */
  143. void draw_remaining_lives(Canvas* canvas, const SimonData* simon_state) {
  144. // Convert score to string
  145. // int length = snprintf(NULL, 0, "%lu", simon_state->lives);
  146. // char* str_lives_remaining = malloc(length + 1);
  147. // snprintf(str_lives_remaining, length + 1, "%lu", simon_state->lives);
  148. // TODO: Make it a Simon Says icon on top right
  149. canvas_set_color(canvas, ColorBlack);
  150. canvas_set_font(canvas, FontSecondary);
  151. int x = SCREEN_XRES - 6;
  152. int lives = simon_state->lives;
  153. while(lives--) {
  154. canvas_draw_str(canvas, x, 8, "*");
  155. x -= 7;
  156. }
  157. }
  158. void draw_current_score(Canvas* canvas, const SimonData* simon_data) {
  159. /* Draw Game Score. */
  160. canvas_set_color(canvas, ColorXOR);
  161. canvas_set_font(canvas, FontSecondary);
  162. char str_score[32];
  163. snprintf(str_score, sizeof(str_score), "%i", simon_data->currentScore);
  164. canvas_draw_str_aligned(canvas, SCREEN_XRES / 2 + 4, 2, AlignCenter, AlignTop, str_score);
  165. }
  166. void play_sound_up(SimonData* const app) {
  167. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  168. furi_hal_speaker_start(NOTE_UP, app->volume);
  169. }
  170. }
  171. void play_sound_down(SimonData* const app) {
  172. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  173. furi_hal_speaker_start(NOTE_DOWN, app->volume);
  174. }
  175. }
  176. void play_sound_left(SimonData* const app) {
  177. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  178. furi_hal_speaker_start(NOTE_LEFT, app->volume);
  179. }
  180. }
  181. void play_sound_right(SimonData* const app) {
  182. if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
  183. furi_hal_speaker_start(NOTE_RIGHT, app->volume);
  184. }
  185. }
  186. void stop_sound() {
  187. if(furi_hal_speaker_is_mine()) {
  188. furi_hal_speaker_stop();
  189. furi_hal_speaker_release();
  190. }
  191. }
  192. /* Main Render Function */
  193. void simon_draw_callback(Canvas* canvas, void* ctx) {
  194. SimonData* const simon_state = acquire_mutex((ValueMutex*)ctx, 25);
  195. if(simon_state == NULL) {
  196. if(DEBUG_MSG) FURI_LOG_E(TAG, "[simon_draw_callback] Null simon state");
  197. return;
  198. }
  199. UNUSED(ctx);
  200. canvas_clear(canvas);
  201. // ######################### Main Menu #########################
  202. // Show Main Menu
  203. if(simon_state->gameState == mainMenu) {
  204. // Draw border frame
  205. canvas_draw_frame(canvas, 1, 1, SCREEN_XRES - 1, SCREEN_YRES - 1); // Border
  206. // Draw Simon text banner
  207. canvas_set_font(canvas, FontSecondary);
  208. canvas_set_color(canvas, ColorBlack);
  209. canvas_draw_str_aligned(
  210. canvas,
  211. SCREEN_XRES / 2,
  212. SCREEN_YRES / 2 - 4,
  213. AlignCenter,
  214. AlignCenter,
  215. "Welcome to Simon Says");
  216. // Display Press OK to start below title
  217. canvas_set_color(canvas, ColorXOR);
  218. canvas_draw_str_aligned(
  219. canvas,
  220. SCREEN_XRES / 2,
  221. SCREEN_YRES / 2 + 10,
  222. AlignCenter,
  223. AlignCenter,
  224. "Press OK to start");
  225. }
  226. // ######################### in Game #########################
  227. //@todo Render Callback
  228. // We're in an active game
  229. if(simon_state->gameState == inGame) {
  230. // Draw Current Score
  231. draw_current_score(canvas, simon_state);
  232. // Draw Lives
  233. draw_remaining_lives(canvas, simon_state);
  234. // Draw Simon Pose
  235. if(simon_state->activePlayer == player) {
  236. // Player's turn
  237. canvas_draw_icon(canvas, 0, 4, &I_DolphinWait_61x59);
  238. } else {
  239. // Simon's turn
  240. canvas_draw_icon(canvas, 0, 4, &I_DolphinTalking_59x63);
  241. }
  242. if(simon_state->set_board_neutral) {
  243. // Draw Neutral Board
  244. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_board); // Draw Board
  245. // Stop Sound TODO: Move this to a better place
  246. //@todo Sound
  247. stop_sound();
  248. } else {
  249. switch(simon_state->selectedShape) {
  250. case up:
  251. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_up); // Draw Up
  252. play_sound_up(simon_state);
  253. break;
  254. case down:
  255. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_down); // Draw Down
  256. play_sound_down(simon_state);
  257. break;
  258. case left:
  259. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_left); // Draw Left
  260. play_sound_left(simon_state);
  261. break;
  262. case right:
  263. canvas_draw_icon(canvas, BOARD_X, BOARD_Y, &I_right); // Draw Right
  264. play_sound_right(simon_state);
  265. break;
  266. default:
  267. if(DEBUG_MSG)
  268. FURI_LOG_E(
  269. TAG, "Invalid shape: %d", simon_state->simonMoves[simon_state->moveIndex]);
  270. break;
  271. }
  272. }
  273. }
  274. // ######################### Game Over #########################
  275. if(simon_state->gameState == gameOver) {
  276. stop_sound(); //TODO: Make a game over sequence
  277. canvas_set_color(canvas, ColorXOR);
  278. canvas_set_font(canvas, FontPrimary);
  279. // TODO: if new highscore, display blinking "New High Score"
  280. // Display High Score Text
  281. if(simon_state->is_new_highscore) {
  282. canvas_draw_str_aligned(
  283. canvas, SCREEN_XRES / 2, 6, AlignCenter, AlignTop, "New High Score!");
  284. } else {
  285. canvas_draw_str_aligned(
  286. canvas, SCREEN_XRES / 2, 6, AlignCenter, AlignTop, "High Score");
  287. }
  288. // Convert highscore to string
  289. int length = snprintf(NULL, 0, "%i", simon_state->highScore);
  290. char* str_high_score = malloc(length + 1);
  291. snprintf(str_high_score, length + 1, "%i", simon_state->highScore);
  292. // Display High Score
  293. canvas_draw_str_aligned(
  294. canvas, SCREEN_XRES / 2, 22, AlignCenter, AlignCenter, str_high_score);
  295. free(str_high_score);
  296. // Display Game Over
  297. canvas_draw_str_aligned(
  298. canvas, SCREEN_XRES / 2, SCREEN_YRES / 2 + 2, AlignCenter, AlignCenter, "GAME OVER");
  299. // Display Press OK to restart below title
  300. canvas_set_font(canvas, FontSecondary);
  301. canvas_draw_str_aligned(
  302. canvas,
  303. SCREEN_XRES / 2,
  304. SCREEN_YRES / 2 + 15,
  305. AlignCenter,
  306. AlignCenter,
  307. "Press OK to restart");
  308. }
  309. // ######################### Victory #########################
  310. //Player Beat Simon beyond limit! A word record holder here!
  311. //TODO
  312. //release the mutex
  313. release_mutex((ValueMutex*)ctx, simon_state);
  314. }
  315. /* ======================== Input Handling ============================== */
  316. void simon_input_callback(InputEvent* input_event, void* ctx) {
  317. furi_assert(ctx);
  318. FuriMessageQueue* event_queue = ctx;
  319. furi_message_queue_put(event_queue, input_event, FuriWaitForever);
  320. }
  321. /* ======================== Simon Game Engine ======================== */
  322. bool load_game(SimonData* app) {
  323. Storage* storage = furi_record_open(RECORD_STORAGE);
  324. File* file = storage_file_alloc(storage);
  325. uint16_t bytes_readed = 0;
  326. if(storage_file_open(file, SAVING_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
  327. bytes_readed = storage_file_read(file, app, sizeof(SimonData));
  328. }
  329. storage_file_close(file);
  330. storage_file_free(file);
  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. //@todo Sound on select
  423. if(shape == getCurrentSimonMove(app)) {
  424. onPlayerAnsweredCorrect(app);
  425. } else {
  426. onPlayerAnsweredWrong(app);
  427. }
  428. }
  429. //@todo gametick
  430. void game_tick(SimonData* simon_state) {
  431. if(simon_state->gameState == inGame) {
  432. if(simon_state->activePlayer == simon) {
  433. // ############### Simon Turn ###############
  434. notification_message(simon_state->notification, &sequence_simon_is_playing);
  435. //@todo Gameplay
  436. if(simon_state->set_board_neutral) {
  437. if(simon_state->moveIndex < simon_state->currentScore) {
  438. simon_state->selectedShape = getCurrentSimonMove(simon_state);
  439. simon_state->set_board_neutral = false;
  440. simon_state->moveIndex++;
  441. } else {
  442. simon_state->activePlayer = player;
  443. simon_state->set_board_neutral = true;
  444. simon_state->moveIndex = 0;
  445. }
  446. } else {
  447. simon_state->set_board_neutral = true;
  448. }
  449. } else {
  450. // ############### Player Turn ###############
  451. notification_message(simon_state->notification, &sequence_player_is_playing);
  452. // It's Player's Turn
  453. if(isRoundComplete(simon_state)) {
  454. simon_state->activePlayer = simon;
  455. simon_state->currentScore++;
  456. // app->numberOfMillisecondsBeforeShapeDisappears -= 50;
  457. //TODO: Hacky way of handling highscore by subtracting 1 to account for the first move
  458. if(simon_state->currentScore - 1 > simon_state->highScore) {
  459. simon_state->highScore = simon_state->currentScore - 1;
  460. simon_state->is_new_highscore = true;
  461. }
  462. if(simon_state->sound_enabled) {
  463. play_sound_sequence_correct();
  464. }
  465. startNewRound(simon_state);
  466. }
  467. }
  468. }
  469. }
  470. /* ======================== Main Entry Point ============================== */
  471. int32_t simon_says_app_entry(void* p) {
  472. UNUSED(p);
  473. FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  474. SimonData* simon_state = malloc(sizeof(SimonData));
  475. ValueMutex simon_state_value_mutex;
  476. if(!init_mutex(&simon_state_value_mutex, simon_state, sizeof(SimonData))) {
  477. FURI_LOG_E(TAG, "cannot create mutex\r\n");
  478. free(simon_state);
  479. return -1;
  480. }
  481. // Configure view port
  482. ViewPort* view_port = view_port_alloc();
  483. view_port_draw_callback_set(view_port, simon_draw_callback, &simon_state_value_mutex);
  484. view_port_input_callback_set(view_port, simon_input_callback, event_queue);
  485. // Register view port in GUI
  486. Gui* gui = furi_record_open(RECORD_GUI);
  487. gui_add_view_port(gui, view_port, GuiLayerFullscreen);
  488. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  489. simon_state->notification = notification;
  490. InputEvent input;
  491. // Show Main Menu Screen
  492. //TODO: Disable Loading game for debugging
  493. load_game(simon_state);
  494. simon_state->gameState = mainMenu;
  495. while(true) {
  496. game_tick(simon_state);
  497. FuriStatus q_status = furi_message_queue_get(
  498. event_queue, &input, simon_state->numberOfMillisecondsBeforeShapeDisappears);
  499. if(q_status == FuriStatusOk && simon_state->activePlayer == player) {
  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. if(input.type == InputTypeLong) {
  510. // Do Nothing. Ignore long press events
  511. }
  512. //@todo Set Game States
  513. if(input.key == InputKeyOk && simon_state->gameState != inGame) {
  514. restart_game_after_gameover(simon_state);
  515. // Set Simon Board state
  516. startNewRound(simon_state);
  517. view_port_update(view_port);
  518. }
  519. // Keep LED on if it is Simon's turn
  520. if(simon_state->activePlayer == player) {
  521. notification_message(notification, &sequence_player_is_playing);
  522. if(input.type == InputTypePress) {
  523. simon_state->set_board_neutral = false;
  524. switch(input.key) {
  525. case InputKeyUp:
  526. simon_state->selectedShape = up;
  527. onPlayerSelectedShapeCallback(up, simon_state);
  528. break;
  529. case InputKeyDown:
  530. simon_state->selectedShape = down;
  531. onPlayerSelectedShapeCallback(down, simon_state);
  532. break;
  533. case InputKeyLeft:
  534. simon_state->selectedShape = left;
  535. onPlayerSelectedShapeCallback(left, simon_state);
  536. break;
  537. case InputKeyRight:
  538. simon_state->selectedShape = right;
  539. onPlayerSelectedShapeCallback(right, simon_state);
  540. break;
  541. default:
  542. simon_state->set_board_neutral = true;
  543. break;
  544. }
  545. } else {
  546. FURI_LOG_D(TAG, "Input type is not short");
  547. simon_state->set_board_neutral = true;
  548. }
  549. }
  550. } else {
  551. FURI_LOG_E(TAG, "cannot get message from queue\r\n");
  552. }
  553. // @todo Animation Loop for debug
  554. // if(simon_state->gameState == inGame && simon_state->activePlayer == simon) {
  555. // simon_state->currentScore++;
  556. // simon_state->set_board_neutral = !simon_state->set_board_neutral;
  557. // }
  558. view_port_update(view_port);
  559. }
  560. stop_sound();
  561. notification_message(notification, &sequence_cleanup);
  562. gui_remove_view_port(gui, view_port);
  563. view_port_free(view_port);
  564. furi_message_queue_free(event_queue);
  565. free(simon_state);
  566. furi_record_close(RECORD_NOTIFICATION);
  567. furi_record_close(RECORD_GUI);
  568. return 0;
  569. }