react-native-games 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +58 -7
  2. package/lib/module/games/balloon-blaster/BalloonBlaster.js +1 -167
  3. package/lib/module/games/balloon-blaster/BalloonBlaster.js.map +1 -1
  4. package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js +1 -182
  5. package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js.map +1 -1
  6. package/lib/module/games/balloon-blaster/BalloonBlasterService.js +1 -318
  7. package/lib/module/games/balloon-blaster/BalloonBlasterStore.js +1 -183
  8. package/lib/module/games/balloon-blaster/components/BalloonComponent.js +1 -237
  9. package/lib/module/games/balloon-blaster/components/GameArea.js +1 -156
  10. package/lib/module/games/balloon-blaster/components/GameBackground.js +1 -476
  11. package/lib/module/games/balloon-blaster/components/ScoreBoard.js +1 -112
  12. package/lib/module/games/balloon-blaster/components/ScoreBoard.js.map +1 -1
  13. package/lib/module/games/balloon-blaster/components/index.js +1 -7
  14. package/lib/module/games/candy-crush/CandyCrush.js +1 -131
  15. package/lib/module/games/candy-crush/CandyCrush.js.map +1 -1
  16. package/lib/module/games/candy-crush/CandyCrushConstants.js +1 -125
  17. package/lib/module/games/candy-crush/CandyCrushConstants.js.map +1 -1
  18. package/lib/module/games/candy-crush/CandyCrushService.js +1 -370
  19. package/lib/module/games/candy-crush/CandyCrushStore.js +1 -303
  20. package/lib/module/games/candy-crush/components/CandyItem.js +1 -191
  21. package/lib/module/games/candy-crush/components/GameBackground.js +1 -85
  22. package/lib/module/games/candy-crush/components/GameGrid.js +1 -314
  23. package/lib/module/games/candy-crush/components/ScoreBoard.js +1 -79
  24. package/lib/module/games/candy-crush/components/index.js +1 -7
  25. package/lib/module/games/candy-crush/index.js +1 -6
  26. package/lib/module/games/colors-sort/ColorsSort.js +1 -143
  27. package/lib/module/games/colors-sort/ColorsSort.js.map +1 -1
  28. package/lib/module/games/colors-sort/ColorsSortConstants.js +1 -72
  29. package/lib/module/games/colors-sort/ColorsSortConstants.js.map +1 -1
  30. package/lib/module/games/colors-sort/ColorsSortService.js +1 -255
  31. package/lib/module/games/colors-sort/ColorsSortStore.js +1 -257
  32. package/lib/module/games/colors-sort/ColorsSortStore.js.map +1 -1
  33. package/lib/module/games/colors-sort/components/ColorContainer.js +1 -140
  34. package/lib/module/games/colors-sort/components/GameBackground.js +1 -135
  35. package/lib/module/games/colors-sort/components/ScoreBoard.js +1 -70
  36. package/lib/module/games/colors-sort/components/index.js +1 -6
  37. package/lib/module/games/dino-jump/DinoJump.js +1 -209
  38. package/lib/module/games/dino-jump/DinoJump.js.map +1 -1
  39. package/lib/module/games/dino-jump/DinoJumpConstants.js +1 -189
  40. package/lib/module/games/dino-jump/DinoJumpConstants.js.map +1 -1
  41. package/lib/module/games/dino-jump/DinoJumpService.js +1 -270
  42. package/lib/module/games/dino-jump/DinoJumpStore.js +1 -381
  43. package/lib/module/games/dino-jump/components/DinoSprite.js +1 -418
  44. package/lib/module/games/dino-jump/components/DinoSprite.js.map +1 -1
  45. package/lib/module/games/dino-jump/components/GameArea.js +1 -68
  46. package/lib/module/games/dino-jump/components/GameBackground.js +1 -444
  47. package/lib/module/games/dino-jump/components/ObstacleSprite.js +1 -306
  48. package/lib/module/games/dino-jump/components/ScoreBoard.js +1 -105
  49. package/lib/module/games/dino-jump/components/ScoreBoard.js.map +1 -1
  50. package/lib/module/games/dino-jump/components/StarSprite.js +1 -45
  51. package/lib/module/games/dino-jump/components/index.js +1 -9
  52. package/lib/module/games/flappy-bird/FlappyBird.js +1 -126
  53. package/lib/module/games/flappy-bird/FlappyBird.js.map +1 -1
  54. package/lib/module/games/flappy-bird/FlappyBirdConstants.js +1 -90
  55. package/lib/module/games/flappy-bird/FlappyBirdConstants.js.map +1 -1
  56. package/lib/module/games/flappy-bird/FlappyBirdStore.js +1 -300
  57. package/lib/module/games/flappy-bird/components/Bird.js +1 -87
  58. package/lib/module/games/flappy-bird/components/GameArea.js +1 -87
  59. package/lib/module/games/flappy-bird/components/GameBackground.js +1 -79
  60. package/lib/module/games/flappy-bird/components/Pipes.js +1 -172
  61. package/lib/module/games/flappy-bird/components/ScoreBoard.js +1 -73
  62. package/lib/module/games/flappy-bird/components/index.js +1 -8
  63. package/lib/module/games/fruit-merger/FruitMerger.js +1 -120
  64. package/lib/module/games/fruit-merger/FruitMerger.js.map +1 -1
  65. package/lib/module/games/fruit-merger/FruitMergerConstants.js +1 -119
  66. package/lib/module/games/fruit-merger/FruitMergerConstants.js.map +1 -1
  67. package/lib/module/games/fruit-merger/FruitMergerService.js +1 -13
  68. package/lib/module/games/fruit-merger/FruitMergerStore.js +1 -315
  69. package/lib/module/games/fruit-merger/components/FruitItem.js +1 -102
  70. package/lib/module/games/fruit-merger/components/GameArea.js +1 -103
  71. package/lib/module/games/fruit-merger/components/GameBackground.js +1 -498
  72. package/lib/module/games/fruit-merger/components/ScoreBoard.js +1 -58
  73. package/lib/module/games/fruit-merger/components/index.js +1 -7
  74. package/lib/module/games/fruit-ninja/FruitNinja.js +1 -134
  75. package/lib/module/games/fruit-ninja/FruitNinja.js.map +1 -1
  76. package/lib/module/games/fruit-ninja/FruitNinjaConstants.js +1 -148
  77. package/lib/module/games/fruit-ninja/FruitNinjaConstants.js.map +1 -1
  78. package/lib/module/games/fruit-ninja/FruitNinjaService.js +1 -311
  79. package/lib/module/games/fruit-ninja/FruitNinjaStore.js +1 -191
  80. package/lib/module/games/fruit-ninja/FruitNinjaStore.js.map +1 -1
  81. package/lib/module/games/fruit-ninja/components/FruitComponent.js +1 -99
  82. package/lib/module/games/fruit-ninja/components/GameArea.js +1 -215
  83. package/lib/module/games/fruit-ninja/components/GameBackground.js +1 -1267
  84. package/lib/module/games/fruit-ninja/components/ScoreBoard.js +1 -92
  85. package/lib/module/games/fruit-ninja/components/ScoreBoard.js.map +1 -1
  86. package/lib/module/games/fruit-ninja/components/index.js +1 -7
  87. package/lib/module/games/game-2048/Game2048.js +1 -149
  88. package/lib/module/games/game-2048/Game2048.js.map +1 -1
  89. package/lib/module/games/game-2048/Game2048Constants.js +1 -263
  90. package/lib/module/games/game-2048/Game2048Constants.js.map +1 -1
  91. package/lib/module/games/game-2048/Game2048Service.js +1 -457
  92. package/lib/module/games/game-2048/Game2048Store.js +1 -236
  93. package/lib/module/games/game-2048/components/GameBackground.js +1 -247
  94. package/lib/module/games/game-2048/components/GameGrid.js +1 -139
  95. package/lib/module/games/game-2048/components/GameTile.js +1 -72
  96. package/lib/module/games/game-2048/components/ScoreBoard.js +1 -52
  97. package/lib/module/games/game-2048/components/index.js +1 -7
  98. package/lib/module/games/maze-runner/MazeRunner.js +1 -267
  99. package/lib/module/games/maze-runner/MazeRunner.js.map +1 -1
  100. package/lib/module/games/maze-runner/MazeRunnerConstants.js +1 -100
  101. package/lib/module/games/maze-runner/MazeRunnerConstants.js.map +1 -1
  102. package/lib/module/games/maze-runner/MazeRunnerService.js +1 -586
  103. package/lib/module/games/maze-runner/components/EnhancedBallComponent.js +1 -150
  104. package/lib/module/games/maze-runner/components/EnhancedGameArea.js +1 -370
  105. package/lib/module/games/maze-runner/components/GameBackground.js +1 -175
  106. package/lib/module/games/maze-runner/components/ScoreBoard.js +1 -61
  107. package/lib/module/games/maze-runner/components/SkiaPipeComponent.js +1 -209
  108. package/lib/module/games/maze-runner/components/StaticGameBackground.js +1 -169
  109. package/lib/module/games/maze-runner/components/WallComponent.js +1 -91
  110. package/lib/module/games/maze-runner/components/index.js +1 -8
  111. package/lib/module/games/popit-fidget/PopitFidget.js +1 -285
  112. package/lib/module/games/popit-fidget/PopitFidget.js.map +1 -1
  113. package/lib/module/games/popit-fidget/PopitFidgetConstants.js +1 -113
  114. package/lib/module/games/popit-fidget/PopitFidgetConstants.js.map +1 -1
  115. package/lib/module/games/popit-fidget/PopitFidgetService.js +1 -132
  116. package/lib/module/games/popit-fidget/PopitFidgetStore.js +1 -125
  117. package/lib/module/games/popit-fidget/components/BubbleComponent.js +1 -198
  118. package/lib/module/games/popit-fidget/components/FidgetGrid.js +1 -165
  119. package/lib/module/games/popit-fidget/components/GameBackground.js +1 -177
  120. package/lib/module/games/popit-fidget/components/ScoreBoard.js +1 -61
  121. package/lib/module/games/popit-fidget/components/index.js +1 -7
  122. package/lib/module/games/sliding-numbers/SlidingNumbers.js +1 -159
  123. package/lib/module/games/sliding-numbers/SlidingNumbers.js.map +1 -1
  124. package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js +1 -207
  125. package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js.map +1 -1
  126. package/lib/module/games/sliding-numbers/SlidingNumbersService.js +1 -248
  127. package/lib/module/games/sliding-numbers/SlidingNumbersStore.js +1 -274
  128. package/lib/module/games/sliding-numbers/components/GameBackground.js +1 -259
  129. package/lib/module/games/sliding-numbers/components/NumbersGrid.js +1 -174
  130. package/lib/module/games/sliding-numbers/components/NumbersTile.js +1 -116
  131. package/lib/module/games/sliding-numbers/components/ScoreBoard.js +1 -64
  132. package/lib/module/games/sliding-numbers/components/index.js +1 -7
  133. package/lib/module/games/snake/Snake.js +1 -189
  134. package/lib/module/games/snake/Snake.js.map +1 -1
  135. package/lib/module/games/snake/SnakeConstants.js +1 -138
  136. package/lib/module/games/snake/SnakeConstants.js.map +1 -1
  137. package/lib/module/games/snake/SnakeService.js +1 -148
  138. package/lib/module/games/snake/SnakeStore.js +1 -182
  139. package/lib/module/games/snake/components/GameBackground.js +1 -221
  140. package/lib/module/games/snake/components/GameGrid.js +1 -153
  141. package/lib/module/games/snake/components/ScoreBoard.js +1 -51
  142. package/lib/module/games/snake/components/index.js +1 -6
  143. package/lib/module/games/snake/index.js +1 -6
  144. package/lib/module/games/space-fighter/SpaceFighter.js +1 -165
  145. package/lib/module/games/space-fighter/SpaceFighter.js.map +1 -1
  146. package/lib/module/games/space-fighter/SpaceFighterConstants.js +1 -108
  147. package/lib/module/games/space-fighter/SpaceFighterConstants.js.map +1 -1
  148. package/lib/module/games/space-fighter/SpaceFighterService.js +1 -326
  149. package/lib/module/games/space-fighter/SpaceFighterStore.js +1 -209
  150. package/lib/module/games/space-fighter/components/AsteroidComponent.js +1 -113
  151. package/lib/module/games/space-fighter/components/GameArea.js +1 -289
  152. package/lib/module/games/space-fighter/components/GameBackground.js +1 -239
  153. package/lib/module/games/space-fighter/components/ScoreBoard.js +1 -136
  154. package/lib/module/games/space-fighter/components/Spacecraft3D.js +1 -202
  155. package/lib/module/games/space-fighter/components/SpacecraftPath.js +1 -52
  156. package/lib/module/games/space-fighter/components/index.js +1 -9
  157. package/lib/module/games/whack-a-mole/WhackAMole.js +1 -270
  158. package/lib/module/games/whack-a-mole/WhackAMole.js.map +1 -1
  159. package/lib/module/games/whack-a-mole/WhackAMoleConstants.js +1 -115
  160. package/lib/module/games/whack-a-mole/WhackAMoleConstants.js.map +1 -1
  161. package/lib/module/games/whack-a-mole/WhackAMoleService.js +1 -120
  162. package/lib/module/games/whack-a-mole/WhackAMoleStore.js +1 -172
  163. package/lib/module/games/whack-a-mole/components/GameBackground.js +1 -477
  164. package/lib/module/games/whack-a-mole/components/GameGrid.js +1 -97
  165. package/lib/module/games/whack-a-mole/components/GameHole.js +1 -196
  166. package/lib/module/games/whack-a-mole/components/MoleCharacter.js +1 -241
  167. package/lib/module/games/whack-a-mole/components/ScoreBoard.js +1 -67
  168. package/lib/module/games/whack-a-mole/components/ScoreBoard.js.map +1 -1
  169. package/lib/module/games/whack-a-mole/components/index.js +1 -8
  170. package/lib/module/helpers/AnimationFrame.js +1 -120
  171. package/lib/module/helpers/AnimationTracker.js +1 -89
  172. package/lib/module/helpers/ErrorHandler.js +1 -269
  173. package/lib/module/helpers/GameControlButton.js +1 -219
  174. package/lib/module/helpers/GameOverModal.js +1 -144
  175. package/lib/module/helpers/GameOverModal.js.map +1 -1
  176. package/lib/module/helpers/GameSettingsModal.js +1 -287
  177. package/lib/module/helpers/ParticleBlast.js +1 -134
  178. package/lib/module/helpers/ScoreBoardContainer.js +1 -34
  179. package/lib/module/helpers/index.js +1 -12
  180. package/lib/module/index.js +1 -22
  181. package/lib/module/services/GamesConstants.js +1 -178
  182. package/lib/module/services/GamesService.js +1 -112
  183. package/lib/module/services/GamesService.js.map +1 -1
  184. package/lib/module/services/HapticsService.js +1 -77
  185. package/lib/module/services/SoundsService.js +1 -302
  186. package/lib/module/services/UtilsService.js +1 -32
  187. package/lib/typescript/src/games/balloon-blaster/BalloonBlaster.d.ts.map +1 -1
  188. package/lib/typescript/src/games/balloon-blaster/BalloonBlasterConstants.d.ts +1 -1
  189. package/lib/typescript/src/games/balloon-blaster/components/ScoreBoard.d.ts.map +1 -1
  190. package/lib/typescript/src/games/candy-crush/CandyCrushConstants.d.ts +7 -7
  191. package/lib/typescript/src/games/colors-sort/ColorsSort.d.ts.map +1 -1
  192. package/lib/typescript/src/games/colors-sort/ColorsSortStore.d.ts.map +1 -1
  193. package/lib/typescript/src/games/dino-jump/DinoJump.d.ts.map +1 -1
  194. package/lib/typescript/src/games/dino-jump/components/DinoSprite.d.ts.map +1 -1
  195. package/lib/typescript/src/games/flappy-bird/FlappyBird.d.ts.map +1 -1
  196. package/lib/typescript/src/games/flappy-bird/FlappyBirdConstants.d.ts.map +1 -1
  197. package/lib/typescript/src/games/fruit-merger/FruitMerger.d.ts.map +1 -1
  198. package/lib/typescript/src/games/fruit-merger/FruitMergerConstants.d.ts.map +1 -1
  199. package/lib/typescript/src/games/fruit-ninja/FruitNinja.d.ts.map +1 -1
  200. package/lib/typescript/src/games/fruit-ninja/components/ScoreBoard.d.ts.map +1 -1
  201. package/lib/typescript/src/games/game-2048/Game2048.d.ts.map +1 -1
  202. package/lib/typescript/src/games/maze-runner/MazeRunner.d.ts.map +1 -1
  203. package/lib/typescript/src/games/popit-fidget/PopitFidget.d.ts.map +1 -1
  204. package/lib/typescript/src/games/sliding-numbers/SlidingNumbers.d.ts.map +1 -1
  205. package/lib/typescript/src/games/space-fighter/SpaceFighter.d.ts.map +1 -1
  206. package/lib/typescript/src/games/whack-a-mole/WhackAMole.d.ts.map +1 -1
  207. package/lib/typescript/src/games/whack-a-mole/WhackAMoleConstants.d.ts +1 -1
  208. package/lib/typescript/src/games/whack-a-mole/components/ScoreBoard.d.ts.map +1 -1
  209. package/lib/typescript/src/helpers/GameOverModal.d.ts +3 -0
  210. package/lib/typescript/src/helpers/GameOverModal.d.ts.map +1 -1
  211. package/lib/typescript/src/services/GamesConstants.d.ts +7 -7
  212. package/package.json +2 -2
@@ -1,115 +1 @@
1
- "use strict";
2
-
3
- import { Dimensions } from 'react-native';
4
- // Memoize screen dimensions for better performance
5
- const {
6
- width
7
- } = Dimensions.get('window');
8
-
9
- // Whack A Mole Game Constants
10
- export const WHACK_A_MOLE_CONSTANTS = {
11
- moleSpawnInterval: {
12
- easy: 2000,
13
- medium: 1500,
14
- hard: 1000
15
- },
16
- moleAppearDuration: {
17
- easy: 2500,
18
- medium: 2000,
19
- hard: 1500
20
- },
21
- moleVisibleDuration: {
22
- easy: 2500,
23
- medium: 2000,
24
- hard: 1500
25
- },
26
- gridSize: {
27
- easy: 3,
28
- medium: 3,
29
- hard: 4
30
- },
31
- pointsPerMole: {
32
- easy: 10,
33
- medium: 15,
34
- hard: 20
35
- }
36
- };
37
- export const WHACK_A_MOLE_GAME_CONFIG = {
38
- GRID_SIZE: 3,
39
- HOLE_SIZE: width * 0.25,
40
- MOLE_APPEAR_DURATION: 1500,
41
- // ms
42
- MOLE_DISAPPEAR_DURATION: 500,
43
- // ms
44
- GAME_DURATION: 60,
45
- // seconds
46
- INITIAL_SPAWN_DELAY: 1000,
47
- // ms
48
- MAX_SPAWN_INTERVAL: 2000 // ms
49
- };
50
- export const WHACK_A_MOLE_ANIMATION_CONFIG = {
51
- MOLE_SPRING: {
52
- damping: 15,
53
- stiffness: 200
54
- },
55
- HOLE_SPRING: {
56
- damping: 20,
57
- stiffness: 300
58
- },
59
- HIT_TIMING: {
60
- duration: 300
61
- }
62
- };
63
- export const WHACK_A_MOLE_COLORS = {
64
- BACKGROUND: '#2E7D32',
65
- SCORE_BOARD: '#1B5E20',
66
- HOLE: '#3E2723',
67
- HOLE_BORDER: '#5D4037',
68
- HOLE_SHADOW: '#2E2E2E',
69
- MOLE_SHADOW: 'rgba(0,0,0,0.3)',
70
- SCORE: '#FFEB3B',
71
- SCORE_TEXT: '#FFD700',
72
- TIMER_TEXT: '#FF5722',
73
- UI: '#4CAF50',
74
- BUTTON_ACTIVE: '#66BB6A',
75
- BUTTON_INACTIVE: '#A5D6A7',
76
- TEXT_PRIMARY: '#FFFFFF',
77
- TEXT_SECONDARY: '#E8F5E8',
78
- WHITE: '#FFFFFF',
79
- START_BUTTON: '#4CAF50',
80
- HIT_EFFECT_OUTER: '#FFD700',
81
- HIT_EFFECT_INNER: '#FFA500',
82
- GAME_OVER_OVERLAY: 'rgba(0, 0, 0, 0.85)',
83
- BUTTON_BORDER: '#66BB6A'
84
- };
85
-
86
- // Whack A Mole Game Theme - Matches scoreboard green with sky blue background like Fruit Ninja
87
- export const WHACK_A_MOLE_THEME = {
88
- backgroundColor: '#87CEEB',
89
- // Sky blue background like Fruit Ninja
90
- headerBackgroundColor: 'rgba(22, 101, 52, 0.9)',
91
- // Green header to match scoreboard
92
- headerTextColor: '#ffffff',
93
- sectionBackgroundColor: 'rgba(22, 101, 52, 0.4)',
94
- // Match scoreboard transparency
95
- sectionTitleColor: '#ffffff',
96
- // White text on green sections
97
- buttonSelectedColor: '#166534',
98
- // Darker green for better contrast
99
- buttonUnselectedColor: 'rgba(255, 255, 255, 0.3)',
100
- buttonSelectedTextColor: '#ffffff',
101
- buttonUnselectedTextColor: '#1f2937',
102
- switchTrackColorFalse: 'rgba(22, 101, 52, 0.5)',
103
- switchTrackColorTrue: '#166534',
104
- // Darker green for better contrast
105
- switchThumbColor: '#ffffff',
106
- infoTextColor: '#1f2937' // Dark text for readability on sky blue background
107
- };
108
-
109
- // Whack A Mole Difficulty Descriptions
110
- export const WHACK_A_MOLE_DIFFICULTY_DESCRIPTIONS = {
111
- easy: 'Moles appear slower and stay longer',
112
- medium: 'Balanced mole speed and timing',
113
- hard: 'Fast moles, quick reflexes needed!'
114
- };
115
- //# sourceMappingURL=WhackAMoleConstants.js.map
1
+ "use strict";import{Dimensions}from 'react-native';const{width}= Dimensions.get('window');export const WHACK_A_MOLE_CONSTANTS ={moleSpawnInterval:{easy:2000,medium:1500,hard:1000},moleAppearDuration:{easy:2500,medium:2000,hard:1500},moleVisibleDuration:{easy:2500,medium:2000,hard:1500},gridSize:{easy:3,medium:3,hard:4},pointsPerMole:{easy:10,medium:15,hard:20}};export const WHACK_A_MOLE_GAME_CONFIG ={GRID_SIZE:3,HOLE_SIZE:width * 0.25,MOLE_APPEAR_DURATION:1500,MOLE_DISAPPEAR_DURATION:500,GAME_DURATION:120,INITIAL_SPAWN_DELAY:1000,MAX_SPAWN_INTERVAL:2000};export const WHACK_A_MOLE_ANIMATION_CONFIG ={MOLE_SPRING:{damping:15,stiffness:200},HOLE_SPRING:{damping:20,stiffness:300},HIT_TIMING:{duration:300}};export const WHACK_A_MOLE_COLORS ={BACKGROUND:'#2E7D32',SCORE_BOARD:'#1B5E20',HOLE:'#3E2723',HOLE_BORDER:'#5D4037',HOLE_SHADOW:'#2E2E2E',MOLE_SHADOW:'rgba(0,0,0,0.3)',SCORE:'#FFEB3B',SCORE_TEXT:'#FFD700',TIMER_TEXT:'#FF5722',UI:'#4CAF50',BUTTON_ACTIVE:'#66BB6A',BUTTON_INACTIVE:'#A5D6A7',TEXT_PRIMARY:'#FFFFFF',TEXT_SECONDARY:'#E8F5E8',WHITE:'#FFFFFF',START_BUTTON:'#4CAF50',HIT_EFFECT_OUTER:'#FFD700',HIT_EFFECT_INNER:'#FFA500',GAME_OVER_OVERLAY:'rgba(0,0,0,0.85)',BUTTON_BORDER:'#66BB6A'};export const WHACK_A_MOLE_THEME ={backgroundColor:'rgba(0,0,0,0.7)',headerBackgroundColor:'#10b981',headerTextColor:'#ffffff',sectionBackgroundColor:'rgba(16,185,129,0.15)',sectionTitleColor:'#10b981',buttonSelectedColor:'#10b981',buttonUnselectedColor:'rgba(255,255,255,0.2)',buttonSelectedTextColor:'#ffffff',buttonUnselectedTextColor:'rgba(255,255,255,0.7)',switchTrackColorFalse:'rgba(16,185,129,0.3)',switchTrackColorTrue:'#10b981',switchThumbColor:'#ffffff',infoTextColor:'rgba(255,255,255,0.9)'};export const WHACK_A_MOLE_DIFFICULTY_DESCRIPTIONS ={easy:'Moles appear slower and stay longer',medium:'Balanced mole speed and timing',hard:'Fast moles,quick reflexes needed!'};
@@ -1 +1 @@
1
- {"version":3,"names":["Dimensions","width","get","WHACK_A_MOLE_CONSTANTS","moleSpawnInterval","easy","medium","hard","moleAppearDuration","moleVisibleDuration","gridSize","pointsPerMole","WHACK_A_MOLE_GAME_CONFIG","GRID_SIZE","HOLE_SIZE","MOLE_APPEAR_DURATION","MOLE_DISAPPEAR_DURATION","GAME_DURATION","INITIAL_SPAWN_DELAY","MAX_SPAWN_INTERVAL","WHACK_A_MOLE_ANIMATION_CONFIG","MOLE_SPRING","damping","stiffness","HOLE_SPRING","HIT_TIMING","duration","WHACK_A_MOLE_COLORS","BACKGROUND","SCORE_BOARD","HOLE","HOLE_BORDER","HOLE_SHADOW","MOLE_SHADOW","SCORE","SCORE_TEXT","TIMER_TEXT","UI","BUTTON_ACTIVE","BUTTON_INACTIVE","TEXT_PRIMARY","TEXT_SECONDARY","WHITE","START_BUTTON","HIT_EFFECT_OUTER","HIT_EFFECT_INNER","GAME_OVER_OVERLAY","BUTTON_BORDER","WHACK_A_MOLE_THEME","backgroundColor","headerBackgroundColor","headerTextColor","sectionBackgroundColor","sectionTitleColor","buttonSelectedColor","buttonUnselectedColor","buttonSelectedTextColor","buttonUnselectedTextColor","switchTrackColorFalse","switchTrackColorTrue","switchThumbColor","infoTextColor","WHACK_A_MOLE_DIFFICULTY_DESCRIPTIONS"],"sourceRoot":"../../../../src","sources":["games/whack-a-mole/WhackAMoleConstants.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AAGzC;AACA,MAAM;EAAEC;AAAM,CAAC,GAAGD,UAAU,CAACE,GAAG,CAAC,QAAQ,CAAC;;AAE1C;AACA,OAAO,MAAMC,sBAAsB,GAAG;EACpCC,iBAAiB,EAAE;IACjBC,IAAI,EAAE,IAAI;IACVC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDC,kBAAkB,EAAE;IAClBH,IAAI,EAAE,IAAI;IACVC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDE,mBAAmB,EAAE;IACnBJ,IAAI,EAAE,IAAI;IACVC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDG,QAAQ,EAAE;IACRL,IAAI,EAAE,CAAC;IACPC,MAAM,EAAE,CAAC;IACTC,IAAI,EAAE;EACR,CAAC;EACDI,aAAa,EAAE;IACbN,IAAI,EAAE,EAAE;IACRC,MAAM,EAAE,EAAE;IACVC,IAAI,EAAE;EACR;AACF,CAAU;AAEV,OAAO,MAAMK,wBAAwB,GAAG;EACtCC,SAAS,EAAE,CAAC;EACZC,SAAS,EAAEb,KAAK,GAAG,IAAI;EACvBc,oBAAoB,EAAE,IAAI;EAAE;EAC5BC,uBAAuB,EAAE,GAAG;EAAE;EAC9BC,aAAa,EAAE,EAAE;EAAE;EACnBC,mBAAmB,EAAE,IAAI;EAAE;EAC3BC,kBAAkB,EAAE,IAAI,CAAC;AAC3B,CAAU;AAEV,OAAO,MAAMC,6BAA6B,GAAG;EAC3CC,WAAW,EAAE;IACXC,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb,CAAC;EACDC,WAAW,EAAE;IACXF,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb,CAAC;EACDE,UAAU,EAAE;IACVC,QAAQ,EAAE;EACZ;AACF,CAAU;AAEV,OAAO,MAAMC,mBAAmB,GAAG;EACjCC,UAAU,EAAE,SAAS;EACrBC,WAAW,EAAE,SAAS;EACtBC,IAAI,EAAE,SAAS;EACfC,WAAW,EAAE,SAAS;EACtBC,WAAW,EAAE,SAAS;EACtBC,WAAW,EAAE,iBAAiB;EAC9BC,KAAK,EAAE,SAAS;EAChBC,UAAU,EAAE,SAAS;EACrBC,UAAU,EAAE,SAAS;EACrBC,EAAE,EAAE,SAAS;EACbC,aAAa,EAAE,SAAS;EACxBC,eAAe,EAAE,SAAS;EAC1BC,YAAY,EAAE,SAAS;EACvBC,cAAc,EAAE,SAAS;EACzBC,KAAK,EAAE,SAAS;EAChBC,YAAY,EAAE,SAAS;EACvBC,gBAAgB,EAAE,SAAS;EAC3BC,gBAAgB,EAAE,SAAS;EAC3BC,iBAAiB,EAAE,qBAAqB;EACxCC,aAAa,EAAE;AACjB,CAAU;;AAEV;AACA,OAAO,MAAMC,kBAAqC,GAAG;EACnDC,eAAe,EAAE,SAAS;EAAE;EAC5BC,qBAAqB,EAAE,wBAAwB;EAAE;EACjDC,eAAe,EAAE,SAAS;EAC1BC,sBAAsB,EAAE,wBAAwB;EAAE;EAClDC,iBAAiB,EAAE,SAAS;EAAE;EAC9BC,mBAAmB,EAAE,SAAS;EAAE;EAChCC,qBAAqB,EAAE,0BAA0B;EACjDC,uBAAuB,EAAE,SAAS;EAClCC,yBAAyB,EAAE,SAAS;EACpCC,qBAAqB,EAAE,wBAAwB;EAC/CC,oBAAoB,EAAE,SAAS;EAAE;EACjCC,gBAAgB,EAAE,SAAS;EAC3BC,aAAa,EAAE,SAAS,CAAE;AAC5B,CAAC;;AAED;AACA,OAAO,MAAMC,oCAAoC,GAAG;EAClDzD,IAAI,EAAE,qCAAqC;EAC3CC,MAAM,EAAE,gCAAgC;EACxCC,IAAI,EAAE;AACR,CAAU","ignoreList":[]}
1
+ {"version":3,"names":["Dimensions","width","get","WHACK_A_MOLE_CONSTANTS","moleSpawnInterval","easy","medium","hard","moleAppearDuration","moleVisibleDuration","gridSize","pointsPerMole","WHACK_A_MOLE_GAME_CONFIG","GRID_SIZE","HOLE_SIZE","MOLE_APPEAR_DURATION","MOLE_DISAPPEAR_DURATION","GAME_DURATION","INITIAL_SPAWN_DELAY","MAX_SPAWN_INTERVAL","WHACK_A_MOLE_ANIMATION_CONFIG","MOLE_SPRING","damping","stiffness","HOLE_SPRING","HIT_TIMING","duration","WHACK_A_MOLE_COLORS","BACKGROUND","SCORE_BOARD","HOLE","HOLE_BORDER","HOLE_SHADOW","MOLE_SHADOW","SCORE","SCORE_TEXT","TIMER_TEXT","UI","BUTTON_ACTIVE","BUTTON_INACTIVE","TEXT_PRIMARY","TEXT_SECONDARY","WHITE","START_BUTTON","HIT_EFFECT_OUTER","HIT_EFFECT_INNER","GAME_OVER_OVERLAY","BUTTON_BORDER","WHACK_A_MOLE_THEME","backgroundColor","headerBackgroundColor","headerTextColor","sectionBackgroundColor","sectionTitleColor","buttonSelectedColor","buttonUnselectedColor","buttonSelectedTextColor","buttonUnselectedTextColor","switchTrackColorFalse","switchTrackColorTrue","switchThumbColor","infoTextColor","WHACK_A_MOLE_DIFFICULTY_DESCRIPTIONS"],"sourceRoot":"../../../../src","sources":["games/whack-a-mole/WhackAMoleConstants.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AAGzC;AACA,MAAM;EAAEC;AAAM,CAAC,GAAGD,UAAU,CAACE,GAAG,CAAC,QAAQ,CAAC;;AAE1C;AACA,OAAO,MAAMC,sBAAsB,GAAG;EACpCC,iBAAiB,EAAE;IACjBC,IAAI,EAAE,IAAI;IACVC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDC,kBAAkB,EAAE;IAClBH,IAAI,EAAE,IAAI;IACVC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDE,mBAAmB,EAAE;IACnBJ,IAAI,EAAE,IAAI;IACVC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDG,QAAQ,EAAE;IACRL,IAAI,EAAE,CAAC;IACPC,MAAM,EAAE,CAAC;IACTC,IAAI,EAAE;EACR,CAAC;EACDI,aAAa,EAAE;IACbN,IAAI,EAAE,EAAE;IACRC,MAAM,EAAE,EAAE;IACVC,IAAI,EAAE;EACR;AACF,CAAU;AAEV,OAAO,MAAMK,wBAAwB,GAAG;EACtCC,SAAS,EAAE,CAAC;EACZC,SAAS,EAAEb,KAAK,GAAG,IAAI;EACvBc,oBAAoB,EAAE,IAAI;EAAE;EAC5BC,uBAAuB,EAAE,GAAG;EAAE;EAC9BC,aAAa,EAAE,GAAG;EAAE;EACpBC,mBAAmB,EAAE,IAAI;EAAE;EAC3BC,kBAAkB,EAAE,IAAI,CAAC;AAC3B,CAAU;AAEV,OAAO,MAAMC,6BAA6B,GAAG;EAC3CC,WAAW,EAAE;IACXC,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb,CAAC;EACDC,WAAW,EAAE;IACXF,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb,CAAC;EACDE,UAAU,EAAE;IACVC,QAAQ,EAAE;EACZ;AACF,CAAU;AAEV,OAAO,MAAMC,mBAAmB,GAAG;EACjCC,UAAU,EAAE,SAAS;EACrBC,WAAW,EAAE,SAAS;EACtBC,IAAI,EAAE,SAAS;EACfC,WAAW,EAAE,SAAS;EACtBC,WAAW,EAAE,SAAS;EACtBC,WAAW,EAAE,iBAAiB;EAC9BC,KAAK,EAAE,SAAS;EAChBC,UAAU,EAAE,SAAS;EACrBC,UAAU,EAAE,SAAS;EACrBC,EAAE,EAAE,SAAS;EACbC,aAAa,EAAE,SAAS;EACxBC,eAAe,EAAE,SAAS;EAC1BC,YAAY,EAAE,SAAS;EACvBC,cAAc,EAAE,SAAS;EACzBC,KAAK,EAAE,SAAS;EAChBC,YAAY,EAAE,SAAS;EACvBC,gBAAgB,EAAE,SAAS;EAC3BC,gBAAgB,EAAE,SAAS;EAC3BC,iBAAiB,EAAE,qBAAqB;EACxCC,aAAa,EAAE;AACjB,CAAU;;AAEV;AACA,OAAO,MAAMC,kBAAqC,GAAG;EACnDC,eAAe,EAAE,oBAAoB;EAAE;EACvCC,qBAAqB,EAAE,SAAS;EAAE;EAClCC,eAAe,EAAE,SAAS;EAC1BC,sBAAsB,EAAE,0BAA0B;EAAE;EACpDC,iBAAiB,EAAE,SAAS;EAAE;EAC9BC,mBAAmB,EAAE,SAAS;EAAE;EAChCC,qBAAqB,EAAE,0BAA0B;EACjDC,uBAAuB,EAAE,SAAS;EAClCC,yBAAyB,EAAE,0BAA0B;EAAE;EACvDC,qBAAqB,EAAE,yBAAyB;EAChDC,oBAAoB,EAAE,SAAS;EAAE;EACjCC,gBAAgB,EAAE,SAAS;EAC3BC,aAAa,EAAE,0BAA0B,CAAE;AAC7C,CAAC;;AAED;AACA,OAAO,MAAMC,oCAAoC,GAAG;EAClDzD,IAAI,EAAE,qCAAqC;EAC3CC,MAAM,EAAE,gCAAgC;EACxCC,IAAI,EAAE;AACR,CAAU","ignoreList":[]}
@@ -1,120 +1 @@
1
- "use strict";
2
-
3
- import { WHACK_A_MOLE_GAME_CONFIG as GAME_CONFIG, WHACK_A_MOLE_ANIMATION_CONFIG as ANIMATION_CONFIG, WHACK_A_MOLE_COLORS as COLORS } from "./WhackAMoleConstants.js";
4
-
5
- // Constants now imported from WhackAMoleConstants.ts
6
- // Re-export for backward compatibility
7
- export { GAME_CONFIG, ANIMATION_CONFIG, COLORS };
8
-
9
- // Types
10
-
11
- export class WhackAMoleService {
12
- gameTimerRef = null;
13
- moleTimerRef = null;
14
- // Optimized: Use Map instead of object for better performance
15
- activeMoleTimers = new Map();
16
- constructor(moleAnimations, hitAnimations) {
17
- this.moleAnimations = moleAnimations;
18
- this.hitAnimations = hitAnimations;
19
- }
20
-
21
- // Optimized random number generation
22
- fastRandom(max) {
23
- return Math.floor(Math.random() * max);
24
- }
25
-
26
- // Efficient hole selection algorithm
27
- selectRandomHole(availableHoles) {
28
- if (availableHoles.length === 0) return -1;
29
- if (availableHoles.length === 1) return availableHoles[0];
30
- const randomIndex = this.fastRandom(availableHoles.length);
31
- return availableHoles[randomIndex];
32
- }
33
- startGameTimer(onTick) {
34
- this.clearGameTimer();
35
- this.gameTimerRef = setInterval(onTick, 1000);
36
- }
37
- startMoleSpawning(spawnMole, customSpawnInterval) {
38
- this.clearMoleTimer();
39
- const baseInterval = customSpawnInterval || GAME_CONFIG.MAX_SPAWN_INTERVAL;
40
- const minInterval = Math.max(500, baseInterval * 0.7); // 30% faster minimum
41
- const maxInterval = baseInterval;
42
- const spawnLoop = () => {
43
- spawnMole();
44
- const nextSpawnTime = Math.random() * (maxInterval - minInterval) + minInterval;
45
- this.moleTimerRef = setTimeout(spawnLoop, nextSpawnTime);
46
- };
47
- this.moleTimerRef = setTimeout(spawnLoop, GAME_CONFIG.INITIAL_SPAWN_DELAY);
48
- }
49
- spawnRandomMole(availableHoles, onMoleSpawned, onMoleHidden, customVisibleDuration) {
50
- if (availableHoles.length === 0) return;
51
-
52
- // Optimized hole selection
53
- const randomHoleId = this.selectRandomHole(availableHoles);
54
- if (randomHoleId === -1) return;
55
-
56
- // Clear any existing timeout for this hole using optimized Map
57
- const existingTimer = this.activeMoleTimers.get(randomHoleId);
58
- if (existingTimer) {
59
- clearTimeout(existingTimer);
60
- this.activeMoleTimers.delete(randomHoleId);
61
- }
62
-
63
- // Trigger mole spawn
64
- onMoleSpawned(randomHoleId);
65
-
66
- // Schedule mole hide with custom duration and optimized cleanup
67
- const visibleDuration = customVisibleDuration || GAME_CONFIG.MOLE_APPEAR_DURATION;
68
- const deactivationTimer = setTimeout(() => {
69
- onMoleHidden(randomHoleId);
70
- this.activeMoleTimers.delete(randomHoleId);
71
- }, visibleDuration);
72
- this.activeMoleTimers.set(randomHoleId, deactivationTimer);
73
- }
74
- whackMole(holeId, onWhacked) {
75
- // Optimized: Clear the timer using Map for better performance
76
- const timer = this.activeMoleTimers.get(holeId);
77
- if (timer) {
78
- clearTimeout(timer);
79
- this.activeMoleTimers.delete(holeId);
80
- }
81
-
82
- // Execute callback immediately for responsive feedback
83
- onWhacked();
84
- }
85
- resetAnimations() {
86
- // Optimized: Reset all animations efficiently
87
- this.moleAnimations.forEach(anim => {
88
- anim.value = 0;
89
- });
90
- this.hitAnimations.forEach(anim => {
91
- anim.value = 0;
92
- });
93
- }
94
- cleanup() {
95
- this.clearGameTimer();
96
- this.clearMoleTimer();
97
- this.clearAllMoleHideTimeouts();
98
- }
99
- clearGameTimer() {
100
- if (this.gameTimerRef) {
101
- clearInterval(this.gameTimerRef);
102
- this.gameTimerRef = null;
103
- }
104
- }
105
- clearMoleTimer() {
106
- if (this.moleTimerRef) {
107
- clearTimeout(this.moleTimerRef);
108
- this.moleTimerRef = null;
109
- }
110
- }
111
- clearAllMoleHideTimeouts() {
112
- // Optimized: Batch clear all active mole timers using Map
113
- this.activeMoleTimers.forEach(timer => clearTimeout(timer));
114
- this.activeMoleTimers.clear();
115
- }
116
- }
117
- export const createWhackAMoleService = (moleAnimations, hitAnimations) => {
118
- return new WhackAMoleService(moleAnimations, hitAnimations);
119
- };
120
- //# sourceMappingURL=WhackAMoleService.js.map
1
+ "use strict";import{WHACK_A_MOLE_GAME_CONFIG as GAME_CONFIG,WHACK_A_MOLE_ANIMATION_CONFIG as ANIMATION_CONFIG,WHACK_A_MOLE_COLORS as COLORS}from "./WhackAMoleConstants.js";export{GAME_CONFIG,ANIMATION_CONFIG,COLORS};export class WhackAMoleService{gameTimerRef = null;moleTimerRef = null;activeMoleTimers = new Map();constructor(moleAnimations,hitAnimations){this.moleAnimations = moleAnimations;this.hitAnimations = hitAnimations;}fastRandom(max){return Math.floor(Math.random()* max);}selectRandomHole(availableHoles){if(availableHoles.length === 0)return -1;if(availableHoles.length === 1)return availableHoles[0];const randomIndex = this.fastRandom(availableHoles.length);return availableHoles[randomIndex];}startGameTimer(onTick){this.clearGameTimer();this.gameTimerRef = setInterval(onTick,1000);}startMoleSpawning(spawnMole,customSpawnInterval){this.clearMoleTimer();const baseInterval = customSpawnInterval || GAME_CONFIG.MAX_SPAWN_INTERVAL;const minInterval = Math.max(500,baseInterval * 0.7);const maxInterval = baseInterval;const spawnLoop =()=>{spawnMole();const nextSpawnTime = Math.random()*(maxInterval - minInterval)+ minInterval;this.moleTimerRef = setTimeout(spawnLoop,nextSpawnTime);};this.moleTimerRef = setTimeout(spawnLoop,GAME_CONFIG.INITIAL_SPAWN_DELAY);}spawnRandomMole(availableHoles,onMoleSpawned,onMoleHidden,customVisibleDuration){if(availableHoles.length === 0)return;const randomHoleId = this.selectRandomHole(availableHoles);if(randomHoleId === -1)return;const existingTimer = this.activeMoleTimers.get(randomHoleId);if(existingTimer){clearTimeout(existingTimer);this.activeMoleTimers.delete(randomHoleId);}onMoleSpawned(randomHoleId);const visibleDuration = customVisibleDuration || GAME_CONFIG.MOLE_APPEAR_DURATION;const deactivationTimer = setTimeout(()=>{onMoleHidden(randomHoleId);this.activeMoleTimers.delete(randomHoleId);},visibleDuration);this.activeMoleTimers.set(randomHoleId,deactivationTimer);}whackMole(holeId,onWhacked){const timer = this.activeMoleTimers.get(holeId);if(timer){clearTimeout(timer);this.activeMoleTimers.delete(holeId);}onWhacked();}resetAnimations(){this.moleAnimations.forEach(anim =>{anim.value = 0;});this.hitAnimations.forEach(anim =>{anim.value = 0;});}cleanup(){this.clearGameTimer();this.clearMoleTimer();this.clearAllMoleHideTimeouts();}clearGameTimer(){if(this.gameTimerRef){clearInterval(this.gameTimerRef);this.gameTimerRef = null;}}clearMoleTimer(){if(this.moleTimerRef){clearTimeout(this.moleTimerRef);this.moleTimerRef = null;}}clearAllMoleHideTimeouts(){this.activeMoleTimers.forEach(timer => clearTimeout(timer));this.activeMoleTimers.clear();}}export const createWhackAMoleService =(moleAnimations,hitAnimations)=>{return new WhackAMoleService(moleAnimations,hitAnimations);};
@@ -1,172 +1 @@
1
- "use strict";
2
-
3
- import { create } from 'zustand';
4
- import { subscribeWithSelector } from 'zustand/middleware';
5
- import { GAME_CONFIG } from "./WhackAMoleService.js";
6
- import { immerMiddleware } from "../../services/UtilsService.js";
7
- const createInitialHoles = (gridSize = GAME_CONFIG.GRID_SIZE) => {
8
- const totalHoles = gridSize * gridSize;
9
- return Array.from({
10
- length: totalHoles
11
- }, (_, i) => ({
12
- id: i,
13
- isActive: false,
14
- position: {
15
- x: (i % gridSize - 1) * (GAME_CONFIG.HOLE_SIZE + 20),
16
- y: Math.floor(i / gridSize - 1) * (GAME_CONFIG.HOLE_SIZE + 20),
17
- z: 0
18
- }
19
- }));
20
- };
21
-
22
- // Optimized store with selective subscriptions for low-end devices
23
- export const useWhackAMoleStore = create()(subscribeWithSelector(immerMiddleware((set, get) => ({
24
- // Initial state
25
- score: 0,
26
- timeLeft: GAME_CONFIG.GAME_DURATION,
27
- // Fixed duration regardless of difficulty
28
- isPlaying: false,
29
- gameOver: false,
30
- holes: createInitialHoles(),
31
- // Actions
32
- startGame: (_gameDuration, gridSize) => {
33
- // Always use fixed duration regardless of difficulty or passed duration
34
- const duration = GAME_CONFIG.GAME_DURATION;
35
- const grid = gridSize || GAME_CONFIG.GRID_SIZE;
36
- set(draft => {
37
- draft.score = 0;
38
- draft.timeLeft = duration;
39
- draft.isPlaying = true;
40
- draft.gameOver = false;
41
- draft.holes = createInitialHoles(grid);
42
- });
43
- },
44
- stopGame: () => {
45
- set(draft => {
46
- draft.score = 0;
47
- draft.timeLeft = GAME_CONFIG.GAME_DURATION; // Use constant for consistency
48
- draft.isPlaying = false;
49
- draft.gameOver = false;
50
- });
51
- },
52
- resetGame: () => {
53
- set(draft => {
54
- draft.score = 0;
55
- draft.timeLeft = GAME_CONFIG.GAME_DURATION; // Use constant for consistency
56
- draft.isPlaying = false;
57
- draft.gameOver = false;
58
- draft.holes = createInitialHoles();
59
- });
60
- },
61
- whackMole: (holeId, points = 1) => {
62
- const {
63
- holes,
64
- isPlaying
65
- } = get();
66
- if (!isPlaying) return;
67
-
68
- // Optimized: Use direct array access instead of find for better performance
69
- if (holeId < 0 || holeId >= holes.length || !holes[holeId] || !holes[holeId].isActive) return;
70
- set(draft => {
71
- draft.score = draft.score + points;
72
- // Optimized: Direct array access instead of find
73
- if (draft.holes[holeId]) {
74
- draft.holes[holeId].isActive = false;
75
- }
76
- });
77
- },
78
- updateScore: points => {
79
- set(draft => {
80
- draft.score = draft.score + points;
81
- });
82
- },
83
- decrementTime: () => {
84
- const currentState = get();
85
- if (currentState.timeLeft <= 1) {
86
- // Batch final state update to prevent multiple re-renders
87
- set(draft => {
88
- draft.timeLeft = 0;
89
- draft.isPlaying = false;
90
- draft.gameOver = true;
91
- // Deactivate all holes when game ends
92
- draft.holes.forEach(hole => {
93
- hole.isActive = false;
94
- });
95
- });
96
- } else {
97
- // Only update time to minimize re-renders
98
- set(draft => {
99
- draft.timeLeft = currentState.timeLeft - 1;
100
- });
101
- }
102
- },
103
- setHoles: holes => {
104
- set(draft => {
105
- draft.holes = holes;
106
- });
107
- },
108
- activateHole: holeId => {
109
- // Optimized hole activation with direct array access
110
- const state = get();
111
- if (holeId >= 0 && holeId < state.holes.length && !state.holes[holeId].isActive) {
112
- set(draft => {
113
- if (draft.holes[holeId]) {
114
- draft.holes[holeId].isActive = true;
115
- }
116
- });
117
- }
118
- },
119
- deactivateHole: holeId => {
120
- // Optimized hole deactivation with direct array access
121
- const state = get();
122
- if (holeId >= 0 && holeId < state.holes.length && state.holes[holeId].isActive) {
123
- set(draft => {
124
- if (draft.holes[holeId]) {
125
- draft.holes[holeId].isActive = false;
126
- }
127
- });
128
- }
129
- },
130
- // Batch operations for better performance
131
- batchUpdateHoles: updates => {
132
- const state = get();
133
- const hasChanges = updates.some(update => update.holeId >= 0 && update.holeId < state.holes.length && state.holes[update.holeId].isActive !== update.isActive);
134
- if (hasChanges) {
135
- set(draft => {
136
- updates.forEach(({
137
- holeId,
138
- isActive
139
- }) => {
140
- if (holeId >= 0 && holeId < draft.holes.length) {
141
- if (draft.holes[holeId]) {
142
- draft.holes[holeId].isActive = isActive;
143
- }
144
- }
145
- });
146
- });
147
- }
148
- }
149
- }))));
150
-
151
- // Optimized selectors for low-end devices - prevent unnecessary re-renders
152
- export const useGameState = () => useWhackAMoleStore(state => ({
153
- isPlaying: state.isPlaying,
154
- gameOver: state.gameOver
155
- }));
156
- export const useScore = () => useWhackAMoleStore(state => state.score);
157
- export const useTimeLeft = () => useWhackAMoleStore(state => state.timeLeft);
158
-
159
- // Memoized active holes selector for better performance
160
- export const useActiveHoles = () => useWhackAMoleStore(state => {
161
- const activeHoles = [];
162
- for (let i = 0; i < state.holes.length; i++) {
163
- if (state.holes[i] && state.holes[i].isActive) {
164
- activeHoles.push(state.holes[i]);
165
- }
166
- }
167
- return activeHoles;
168
- });
169
-
170
- // Optimized hole selector with direct array access
171
- export const useHoleById = holeId => useWhackAMoleStore(state => holeId >= 0 && holeId < state.holes.length ? state.holes[holeId] : undefined);
172
- //# sourceMappingURL=WhackAMoleStore.js.map
1
+ "use strict";import{create}from 'zustand';import{subscribeWithSelector}from 'zustand/middleware';import{GAME_CONFIG}from "./WhackAMoleService.js";import{immerMiddleware}from "../../services/UtilsService.js";const createInitialHoles =(gridSize = GAME_CONFIG.GRID_SIZE)=>{const totalHoles = gridSize * gridSize;return Array.from({length:totalHoles},(_,i)=>({id:i,isActive:false,position:{x:(i % gridSize - 1)*(GAME_CONFIG.HOLE_SIZE + 20),y:Math.floor(i / gridSize - 1)*(GAME_CONFIG.HOLE_SIZE + 20),z:0}}));};export const useWhackAMoleStore = create()(subscribeWithSelector(immerMiddleware((set,get)=>({score:0,timeLeft:GAME_CONFIG.GAME_DURATION,isPlaying:false,gameOver:false,holes:createInitialHoles(),startGame:(_gameDuration,gridSize)=>{const duration = GAME_CONFIG.GAME_DURATION;const grid = gridSize || GAME_CONFIG.GRID_SIZE;set(draft =>{draft.score = 0;draft.timeLeft = duration;draft.isPlaying = true;draft.gameOver = false;draft.holes = createInitialHoles(grid);});},stopGame:()=>{set(draft =>{draft.score = 0;draft.timeLeft = GAME_CONFIG.GAME_DURATION;draft.isPlaying = false;draft.gameOver = false;});},resetGame:()=>{set(draft =>{draft.score = 0;draft.timeLeft = GAME_CONFIG.GAME_DURATION;draft.isPlaying = false;draft.gameOver = false;draft.holes = createInitialHoles();});},whackMole:(holeId,points = 1)=>{const{holes,isPlaying}= get();if(!isPlaying)return;if(holeId < 0 || holeId >= holes.length || !holes[holeId] || !holes[holeId].isActive)return;set(draft =>{draft.score = draft.score + points;if(draft.holes[holeId]){draft.holes[holeId].isActive = false;}});},updateScore:points =>{set(draft =>{draft.score = draft.score + points;});},decrementTime:()=>{const currentState = get();if(currentState.timeLeft <= 1){set(draft =>{draft.timeLeft = 0;draft.isPlaying = false;draft.gameOver = true;draft.holes.forEach(hole =>{hole.isActive = false;});});}else{set(draft =>{draft.timeLeft = currentState.timeLeft - 1;});}},setHoles:holes =>{set(draft =>{draft.holes = holes;});},activateHole:holeId =>{const state = get();if(holeId >= 0 && holeId < state.holes.length && !state.holes[holeId].isActive){set(draft =>{if(draft.holes[holeId]){draft.holes[holeId].isActive = true;}});}},deactivateHole:holeId =>{const state = get();if(holeId >= 0 && holeId < state.holes.length && state.holes[holeId].isActive){set(draft =>{if(draft.holes[holeId]){draft.holes[holeId].isActive = false;}});}},batchUpdateHoles:updates =>{const state = get();const hasChanges = updates.some(update => update.holeId >= 0 && update.holeId < state.holes.length && state.holes[update.holeId].isActive !== update.isActive);if(hasChanges){set(draft =>{updates.forEach(({holeId,isActive})=>{if(holeId >= 0 && holeId < draft.holes.length){if(draft.holes[holeId]){draft.holes[holeId].isActive = isActive;}}});});}}}))));export const useGameState =()=> useWhackAMoleStore(state =>({isPlaying:state.isPlaying,gameOver:state.gameOver}));export const useScore =()=> useWhackAMoleStore(state => state.score);export const useTimeLeft =()=> useWhackAMoleStore(state => state.timeLeft);export const useActiveHoles =()=> useWhackAMoleStore(state =>{const activeHoles = [];for(let i = 0;i < state.holes.length;i++){if(state.holes[i] && state.holes[i].isActive){activeHoles.push(state.holes[i]);}}return activeHoles;});export const useHoleById = holeId => useWhackAMoleStore(state => holeId >= 0 && holeId < state.holes.length ? state.holes[holeId]:undefined);