game.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/gui.h>
  4. #include "common.h"
  5. #include "load.h"
  6. #include "stats.h"
  7. //-----------------------------------------------------------------------------
  8. typedef struct {
  9. uint8_t u;
  10. uint8_t l;
  11. uint8_t d;
  12. uint8_t r;
  13. uint8_t dl;
  14. uint8_t ur;
  15. uint8_t ul;
  16. uint8_t dr;
  17. } Neighbors;
  18. typedef enum {
  19. MODE_BTN = 0,
  20. LEVELSET_BTN = 1,
  21. LEVELNO_BTN = 2,
  22. } MenuButtons;
  23. typedef enum {
  24. MAIN_MENU,
  25. INTRO,
  26. RESET_PROMPT,
  27. INVALID_PROMPT,
  28. ABOUT,
  29. SELECT_BRICK,
  30. SELECT_DIRECTION,
  31. SOLUTION_SELECT,
  32. MOVE_SIDES,
  33. MOVE_GRAVITY,
  34. EXPLODE,
  35. PAUSED,
  36. HISTOGRAM,
  37. SOLUTION_PROMPT,
  38. GAME_OVER,
  39. LEVEL_FINISHED,
  40. } State;
  41. typedef enum {
  42. NEW_GAME,
  43. CONTINUE,
  44. CUSTOM,
  45. } GameMode;
  46. typedef enum {
  47. NOT_GAME_OVER = 0,
  48. CANNOT_MOVE = 1,
  49. BRICKS_LEFT = 2,
  50. } GameOver;
  51. typedef struct {
  52. u_int32_t frameNo;
  53. u_int32_t dir;
  54. u_int32_t x;
  55. u_int32_t y;
  56. u_int32_t delay;
  57. } MoveInfo;
  58. typedef struct {
  59. ViewPort* viewPort;
  60. FuriMutex* mutex;
  61. State state;
  62. LevelSet* levelSet;
  63. LevelData* levelData;
  64. // score
  65. uint8_t currentLevel;
  66. unsigned int gameMoves;
  67. int16_t score;
  68. char parLabel[PAR_LABEL_SIZE];
  69. // board
  70. PlayGround board;
  71. PlayGround boardUndo;
  72. PlayGround toAnimate;
  73. PlayGround movables;
  74. // solution
  75. PlayGround boardBackup;
  76. uint8_t currentMovableBackup;
  77. bool solutionMode;
  78. uint8_t solutionStep;
  79. uint8_t solutionTotal;
  80. // board stats
  81. Stats* stats;
  82. // selections
  83. uint8_t undoMovable;
  84. uint8_t currentMovable;
  85. uint8_t nextMovable;
  86. // menus
  87. uint8_t menuPausedPos;
  88. MenuButtons mainMenuBtn;
  89. GameMode mainMenuMode;
  90. bool mainMenuInfo;
  91. bool hasContinue;
  92. FuriString* selectedSet;
  93. uint8_t selectedLevel;
  94. FuriString* continueSet;
  95. uint8_t continueLevel;
  96. uint8_t setPos;
  97. uint8_t setCount;
  98. // game state
  99. GameOver gameOverReason;
  100. MoveInfo move;
  101. // extra levels
  102. LevelList levelList;
  103. FuriString* errorMsg;
  104. BackGround bg;
  105. } Game;
  106. //-----------------------------------------------------------------------------
  107. Game* alloc_game_state(int* error);
  108. void free_game_state(Game* game);
  109. //-----------------------------------------------------------------------------
  110. void new_game(Game* game);
  111. GameOver is_game_over(PlayGround* mv, Stats* stats);
  112. bool is_level_finished(Stats* stats);
  113. Neighbors find_neighbors(PlayGround* pg, uint8_t x, uint8_t y);
  114. //-----------------------------------------------------------------------------
  115. const char* level_on_pos(Game* game, int pos);
  116. int level_count(Game* game);
  117. void handle_ivalid_set(Game* game, Storage* storage, FuriString* setId, FuriString* errorMsg);
  118. void initial_load_game(Game* game);
  119. void load_gameset_if_needed(Game* game, FuriString* expectedSet);
  120. void start_game_at_level(Game* game, uint8_t levelNo);
  121. void refresh_level(Game* g);
  122. void level_finished(Game* g);
  123. void forget_continue(Game* g);
  124. void score_for_level(Game* g, uint8_t levelNo, char* buf, size_t max);
  125. //-----------------------------------------------------------------------------
  126. void click_selected(Game* game);
  127. void start_gravity(Game* g);
  128. void stop_gravity(Game* g);
  129. void start_explosion(Game* g);
  130. void stop_explosion(Game* g);
  131. void start_move(Game* g, uint8_t direction);
  132. void stop_move(Game* g);
  133. void movement_stoped(Game* g);
  134. bool undo(Game* g);
  135. //-----------------------------------------------------------------------------
  136. void start_solution(Game* g);
  137. void end_solution(Game* g);
  138. void solution_select(Game* g);
  139. void solution_move(Game* g);
  140. void solution_next(Game* g);
  141. bool solution_will_have_penalty(Game* g);