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.
- package/README.md +58 -7
- package/lib/module/games/balloon-blaster/BalloonBlaster.js +1 -167
- package/lib/module/games/balloon-blaster/BalloonBlaster.js.map +1 -1
- package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js +1 -182
- package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js.map +1 -1
- package/lib/module/games/balloon-blaster/BalloonBlasterService.js +1 -318
- package/lib/module/games/balloon-blaster/BalloonBlasterStore.js +1 -183
- package/lib/module/games/balloon-blaster/components/BalloonComponent.js +1 -237
- package/lib/module/games/balloon-blaster/components/GameArea.js +1 -156
- package/lib/module/games/balloon-blaster/components/GameBackground.js +1 -476
- package/lib/module/games/balloon-blaster/components/ScoreBoard.js +1 -112
- package/lib/module/games/balloon-blaster/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/balloon-blaster/components/index.js +1 -7
- package/lib/module/games/candy-crush/CandyCrush.js +1 -131
- package/lib/module/games/candy-crush/CandyCrush.js.map +1 -1
- package/lib/module/games/candy-crush/CandyCrushConstants.js +1 -125
- package/lib/module/games/candy-crush/CandyCrushConstants.js.map +1 -1
- package/lib/module/games/candy-crush/CandyCrushService.js +1 -370
- package/lib/module/games/candy-crush/CandyCrushStore.js +1 -303
- package/lib/module/games/candy-crush/components/CandyItem.js +1 -191
- package/lib/module/games/candy-crush/components/GameBackground.js +1 -85
- package/lib/module/games/candy-crush/components/GameGrid.js +1 -314
- package/lib/module/games/candy-crush/components/ScoreBoard.js +1 -79
- package/lib/module/games/candy-crush/components/index.js +1 -7
- package/lib/module/games/candy-crush/index.js +1 -6
- package/lib/module/games/colors-sort/ColorsSort.js +1 -143
- package/lib/module/games/colors-sort/ColorsSort.js.map +1 -1
- package/lib/module/games/colors-sort/ColorsSortConstants.js +1 -72
- package/lib/module/games/colors-sort/ColorsSortConstants.js.map +1 -1
- package/lib/module/games/colors-sort/ColorsSortService.js +1 -255
- package/lib/module/games/colors-sort/ColorsSortStore.js +1 -257
- package/lib/module/games/colors-sort/ColorsSortStore.js.map +1 -1
- package/lib/module/games/colors-sort/components/ColorContainer.js +1 -140
- package/lib/module/games/colors-sort/components/GameBackground.js +1 -135
- package/lib/module/games/colors-sort/components/ScoreBoard.js +1 -70
- package/lib/module/games/colors-sort/components/index.js +1 -6
- package/lib/module/games/dino-jump/DinoJump.js +1 -209
- package/lib/module/games/dino-jump/DinoJump.js.map +1 -1
- package/lib/module/games/dino-jump/DinoJumpConstants.js +1 -189
- package/lib/module/games/dino-jump/DinoJumpConstants.js.map +1 -1
- package/lib/module/games/dino-jump/DinoJumpService.js +1 -270
- package/lib/module/games/dino-jump/DinoJumpStore.js +1 -381
- package/lib/module/games/dino-jump/components/DinoSprite.js +1 -418
- package/lib/module/games/dino-jump/components/DinoSprite.js.map +1 -1
- package/lib/module/games/dino-jump/components/GameArea.js +1 -68
- package/lib/module/games/dino-jump/components/GameBackground.js +1 -444
- package/lib/module/games/dino-jump/components/ObstacleSprite.js +1 -306
- package/lib/module/games/dino-jump/components/ScoreBoard.js +1 -105
- package/lib/module/games/dino-jump/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/dino-jump/components/StarSprite.js +1 -45
- package/lib/module/games/dino-jump/components/index.js +1 -9
- package/lib/module/games/flappy-bird/FlappyBird.js +1 -126
- package/lib/module/games/flappy-bird/FlappyBird.js.map +1 -1
- package/lib/module/games/flappy-bird/FlappyBirdConstants.js +1 -90
- package/lib/module/games/flappy-bird/FlappyBirdConstants.js.map +1 -1
- package/lib/module/games/flappy-bird/FlappyBirdStore.js +1 -300
- package/lib/module/games/flappy-bird/components/Bird.js +1 -87
- package/lib/module/games/flappy-bird/components/GameArea.js +1 -87
- package/lib/module/games/flappy-bird/components/GameBackground.js +1 -79
- package/lib/module/games/flappy-bird/components/Pipes.js +1 -172
- package/lib/module/games/flappy-bird/components/ScoreBoard.js +1 -73
- package/lib/module/games/flappy-bird/components/index.js +1 -8
- package/lib/module/games/fruit-merger/FruitMerger.js +1 -120
- package/lib/module/games/fruit-merger/FruitMerger.js.map +1 -1
- package/lib/module/games/fruit-merger/FruitMergerConstants.js +1 -119
- package/lib/module/games/fruit-merger/FruitMergerConstants.js.map +1 -1
- package/lib/module/games/fruit-merger/FruitMergerService.js +1 -13
- package/lib/module/games/fruit-merger/FruitMergerStore.js +1 -315
- package/lib/module/games/fruit-merger/components/FruitItem.js +1 -102
- package/lib/module/games/fruit-merger/components/GameArea.js +1 -103
- package/lib/module/games/fruit-merger/components/GameBackground.js +1 -498
- package/lib/module/games/fruit-merger/components/ScoreBoard.js +1 -58
- package/lib/module/games/fruit-merger/components/index.js +1 -7
- package/lib/module/games/fruit-ninja/FruitNinja.js +1 -134
- package/lib/module/games/fruit-ninja/FruitNinja.js.map +1 -1
- package/lib/module/games/fruit-ninja/FruitNinjaConstants.js +1 -148
- package/lib/module/games/fruit-ninja/FruitNinjaConstants.js.map +1 -1
- package/lib/module/games/fruit-ninja/FruitNinjaService.js +1 -311
- package/lib/module/games/fruit-ninja/FruitNinjaStore.js +1 -191
- package/lib/module/games/fruit-ninja/FruitNinjaStore.js.map +1 -1
- package/lib/module/games/fruit-ninja/components/FruitComponent.js +1 -99
- package/lib/module/games/fruit-ninja/components/GameArea.js +1 -215
- package/lib/module/games/fruit-ninja/components/GameBackground.js +1 -1267
- package/lib/module/games/fruit-ninja/components/ScoreBoard.js +1 -92
- package/lib/module/games/fruit-ninja/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/fruit-ninja/components/index.js +1 -7
- package/lib/module/games/game-2048/Game2048.js +1 -149
- package/lib/module/games/game-2048/Game2048.js.map +1 -1
- package/lib/module/games/game-2048/Game2048Constants.js +1 -263
- package/lib/module/games/game-2048/Game2048Constants.js.map +1 -1
- package/lib/module/games/game-2048/Game2048Service.js +1 -457
- package/lib/module/games/game-2048/Game2048Store.js +1 -236
- package/lib/module/games/game-2048/components/GameBackground.js +1 -247
- package/lib/module/games/game-2048/components/GameGrid.js +1 -139
- package/lib/module/games/game-2048/components/GameTile.js +1 -72
- package/lib/module/games/game-2048/components/ScoreBoard.js +1 -52
- package/lib/module/games/game-2048/components/index.js +1 -7
- package/lib/module/games/maze-runner/MazeRunner.js +1 -267
- package/lib/module/games/maze-runner/MazeRunner.js.map +1 -1
- package/lib/module/games/maze-runner/MazeRunnerConstants.js +1 -100
- package/lib/module/games/maze-runner/MazeRunnerConstants.js.map +1 -1
- package/lib/module/games/maze-runner/MazeRunnerService.js +1 -586
- package/lib/module/games/maze-runner/components/EnhancedBallComponent.js +1 -150
- package/lib/module/games/maze-runner/components/EnhancedGameArea.js +1 -370
- package/lib/module/games/maze-runner/components/GameBackground.js +1 -175
- package/lib/module/games/maze-runner/components/ScoreBoard.js +1 -61
- package/lib/module/games/maze-runner/components/SkiaPipeComponent.js +1 -209
- package/lib/module/games/maze-runner/components/StaticGameBackground.js +1 -169
- package/lib/module/games/maze-runner/components/WallComponent.js +1 -91
- package/lib/module/games/maze-runner/components/index.js +1 -8
- package/lib/module/games/popit-fidget/PopitFidget.js +1 -285
- package/lib/module/games/popit-fidget/PopitFidget.js.map +1 -1
- package/lib/module/games/popit-fidget/PopitFidgetConstants.js +1 -113
- package/lib/module/games/popit-fidget/PopitFidgetConstants.js.map +1 -1
- package/lib/module/games/popit-fidget/PopitFidgetService.js +1 -132
- package/lib/module/games/popit-fidget/PopitFidgetStore.js +1 -125
- package/lib/module/games/popit-fidget/components/BubbleComponent.js +1 -198
- package/lib/module/games/popit-fidget/components/FidgetGrid.js +1 -165
- package/lib/module/games/popit-fidget/components/GameBackground.js +1 -177
- package/lib/module/games/popit-fidget/components/ScoreBoard.js +1 -61
- package/lib/module/games/popit-fidget/components/index.js +1 -7
- package/lib/module/games/sliding-numbers/SlidingNumbers.js +1 -159
- package/lib/module/games/sliding-numbers/SlidingNumbers.js.map +1 -1
- package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js +1 -207
- package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js.map +1 -1
- package/lib/module/games/sliding-numbers/SlidingNumbersService.js +1 -248
- package/lib/module/games/sliding-numbers/SlidingNumbersStore.js +1 -274
- package/lib/module/games/sliding-numbers/components/GameBackground.js +1 -259
- package/lib/module/games/sliding-numbers/components/NumbersGrid.js +1 -174
- package/lib/module/games/sliding-numbers/components/NumbersTile.js +1 -116
- package/lib/module/games/sliding-numbers/components/ScoreBoard.js +1 -64
- package/lib/module/games/sliding-numbers/components/index.js +1 -7
- package/lib/module/games/snake/Snake.js +1 -189
- package/lib/module/games/snake/Snake.js.map +1 -1
- package/lib/module/games/snake/SnakeConstants.js +1 -138
- package/lib/module/games/snake/SnakeConstants.js.map +1 -1
- package/lib/module/games/snake/SnakeService.js +1 -148
- package/lib/module/games/snake/SnakeStore.js +1 -182
- package/lib/module/games/snake/components/GameBackground.js +1 -221
- package/lib/module/games/snake/components/GameGrid.js +1 -153
- package/lib/module/games/snake/components/ScoreBoard.js +1 -51
- package/lib/module/games/snake/components/index.js +1 -6
- package/lib/module/games/snake/index.js +1 -6
- package/lib/module/games/space-fighter/SpaceFighter.js +1 -165
- package/lib/module/games/space-fighter/SpaceFighter.js.map +1 -1
- package/lib/module/games/space-fighter/SpaceFighterConstants.js +1 -108
- package/lib/module/games/space-fighter/SpaceFighterConstants.js.map +1 -1
- package/lib/module/games/space-fighter/SpaceFighterService.js +1 -326
- package/lib/module/games/space-fighter/SpaceFighterStore.js +1 -209
- package/lib/module/games/space-fighter/components/AsteroidComponent.js +1 -113
- package/lib/module/games/space-fighter/components/GameArea.js +1 -289
- package/lib/module/games/space-fighter/components/GameBackground.js +1 -239
- package/lib/module/games/space-fighter/components/ScoreBoard.js +1 -136
- package/lib/module/games/space-fighter/components/Spacecraft3D.js +1 -202
- package/lib/module/games/space-fighter/components/SpacecraftPath.js +1 -52
- package/lib/module/games/space-fighter/components/index.js +1 -9
- package/lib/module/games/whack-a-mole/WhackAMole.js +1 -270
- package/lib/module/games/whack-a-mole/WhackAMole.js.map +1 -1
- package/lib/module/games/whack-a-mole/WhackAMoleConstants.js +1 -115
- package/lib/module/games/whack-a-mole/WhackAMoleConstants.js.map +1 -1
- package/lib/module/games/whack-a-mole/WhackAMoleService.js +1 -120
- package/lib/module/games/whack-a-mole/WhackAMoleStore.js +1 -172
- package/lib/module/games/whack-a-mole/components/GameBackground.js +1 -477
- package/lib/module/games/whack-a-mole/components/GameGrid.js +1 -97
- package/lib/module/games/whack-a-mole/components/GameHole.js +1 -196
- package/lib/module/games/whack-a-mole/components/MoleCharacter.js +1 -241
- package/lib/module/games/whack-a-mole/components/ScoreBoard.js +1 -67
- package/lib/module/games/whack-a-mole/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/whack-a-mole/components/index.js +1 -8
- package/lib/module/helpers/AnimationFrame.js +1 -120
- package/lib/module/helpers/AnimationTracker.js +1 -89
- package/lib/module/helpers/ErrorHandler.js +1 -269
- package/lib/module/helpers/GameControlButton.js +1 -219
- package/lib/module/helpers/GameOverModal.js +1 -144
- package/lib/module/helpers/GameOverModal.js.map +1 -1
- package/lib/module/helpers/GameSettingsModal.js +1 -287
- package/lib/module/helpers/ParticleBlast.js +1 -134
- package/lib/module/helpers/ScoreBoardContainer.js +1 -34
- package/lib/module/helpers/index.js +1 -12
- package/lib/module/index.js +1 -22
- package/lib/module/services/GamesConstants.js +1 -178
- package/lib/module/services/GamesService.js +1 -112
- package/lib/module/services/GamesService.js.map +1 -1
- package/lib/module/services/HapticsService.js +1 -77
- package/lib/module/services/SoundsService.js +1 -302
- package/lib/module/services/UtilsService.js +1 -32
- package/lib/typescript/src/games/balloon-blaster/BalloonBlaster.d.ts.map +1 -1
- package/lib/typescript/src/games/balloon-blaster/BalloonBlasterConstants.d.ts +1 -1
- package/lib/typescript/src/games/balloon-blaster/components/ScoreBoard.d.ts.map +1 -1
- package/lib/typescript/src/games/candy-crush/CandyCrushConstants.d.ts +7 -7
- package/lib/typescript/src/games/colors-sort/ColorsSort.d.ts.map +1 -1
- package/lib/typescript/src/games/colors-sort/ColorsSortStore.d.ts.map +1 -1
- package/lib/typescript/src/games/dino-jump/DinoJump.d.ts.map +1 -1
- package/lib/typescript/src/games/dino-jump/components/DinoSprite.d.ts.map +1 -1
- package/lib/typescript/src/games/flappy-bird/FlappyBird.d.ts.map +1 -1
- package/lib/typescript/src/games/flappy-bird/FlappyBirdConstants.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-merger/FruitMerger.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-merger/FruitMergerConstants.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-ninja/FruitNinja.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-ninja/components/ScoreBoard.d.ts.map +1 -1
- package/lib/typescript/src/games/game-2048/Game2048.d.ts.map +1 -1
- package/lib/typescript/src/games/maze-runner/MazeRunner.d.ts.map +1 -1
- package/lib/typescript/src/games/popit-fidget/PopitFidget.d.ts.map +1 -1
- package/lib/typescript/src/games/sliding-numbers/SlidingNumbers.d.ts.map +1 -1
- package/lib/typescript/src/games/space-fighter/SpaceFighter.d.ts.map +1 -1
- package/lib/typescript/src/games/whack-a-mole/WhackAMole.d.ts.map +1 -1
- package/lib/typescript/src/games/whack-a-mole/WhackAMoleConstants.d.ts +1 -1
- package/lib/typescript/src/games/whack-a-mole/components/ScoreBoard.d.ts.map +1 -1
- package/lib/typescript/src/helpers/GameOverModal.d.ts +3 -0
- package/lib/typescript/src/helpers/GameOverModal.d.ts.map +1 -1
- package/lib/typescript/src/services/GamesConstants.d.ts +7 -7
- package/package.json +2 -2
|
@@ -1,236 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { create } from 'zustand';
|
|
4
|
-
import { subscribeWithSelector } from 'zustand/middleware';
|
|
5
|
-
import { Game2048Service } from "./Game2048Service.js";
|
|
6
|
-
import { GAME_CONFIG, GAME_2048_SOUNDS, GAME_2048_SETTINGS } from "./Game2048Constants.js";
|
|
7
|
-
import { immerMiddleware } from "../../services/UtilsService.js";
|
|
8
|
-
import { playSound } from "../../services/SoundsService.js";
|
|
9
|
-
import { playHaptic, HapticType } from "../../services/HapticsService.js";
|
|
10
|
-
// Ultra-minimal store with memory-safe implementation
|
|
11
|
-
export const useGame2048Store = create()(subscribeWithSelector(immerMiddleware((set, get) => {
|
|
12
|
-
const gameService = new Game2048Service();
|
|
13
|
-
return {
|
|
14
|
-
// Initial state - minimal for memory efficiency
|
|
15
|
-
timeElapsed: 0,
|
|
16
|
-
isPlaying: false,
|
|
17
|
-
isGameOver: false,
|
|
18
|
-
isWon: false,
|
|
19
|
-
isAnimating: false,
|
|
20
|
-
grid: gameService.createGrid(),
|
|
21
|
-
nextTileId: 1,
|
|
22
|
-
difficulty: 'easy',
|
|
23
|
-
targetValue: 2048,
|
|
24
|
-
gridSize: 4,
|
|
25
|
-
enableSounds: true,
|
|
26
|
-
enableHaptics: true,
|
|
27
|
-
// Actions
|
|
28
|
-
startGame: () => {
|
|
29
|
-
set(state => {
|
|
30
|
-
state.isPlaying = true;
|
|
31
|
-
state.timeElapsed = 0; // Reset time when starting
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
stopGame: () => {
|
|
35
|
-
const state = get();
|
|
36
|
-
// Reset the game instead of showing game over modal
|
|
37
|
-
state.initializeGame(state.difficulty);
|
|
38
|
-
},
|
|
39
|
-
resetGame: () => {
|
|
40
|
-
const state = get();
|
|
41
|
-
state.initializeGame(state.difficulty);
|
|
42
|
-
},
|
|
43
|
-
initializeGame: (difficulty = 'easy') => {
|
|
44
|
-
set(state => {
|
|
45
|
-
// Get difficulty settings
|
|
46
|
-
const difficultySettings = GAME_2048_SETTINGS.DIFFICULTY_SETTINGS[difficulty];
|
|
47
|
-
|
|
48
|
-
// Clear existing grid to prevent memory leaks
|
|
49
|
-
state.grid = gameService.createGrid();
|
|
50
|
-
|
|
51
|
-
// Add initial tiles with animations
|
|
52
|
-
let tileId = 1;
|
|
53
|
-
const tile1 = gameService.addRandomTile(state.grid, tileId++);
|
|
54
|
-
const tile2 = gameService.addRandomTile(state.grid, tileId++);
|
|
55
|
-
|
|
56
|
-
// Reset state with difficulty settings
|
|
57
|
-
state.timeElapsed = 0;
|
|
58
|
-
state.isPlaying = false;
|
|
59
|
-
state.isGameOver = false;
|
|
60
|
-
state.isWon = false;
|
|
61
|
-
state.isAnimating = false;
|
|
62
|
-
state.nextTileId = tileId;
|
|
63
|
-
state.difficulty = difficulty;
|
|
64
|
-
state.targetValue = difficultySettings.targetTile;
|
|
65
|
-
state.gridSize = difficultySettings.gridSize;
|
|
66
|
-
|
|
67
|
-
// Animate initial tiles
|
|
68
|
-
[tile1, tile2].forEach(tile => {
|
|
69
|
-
if (tile?.scaleValue) {
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
tile.scaleValue?.setValue(0);
|
|
72
|
-
// Use React Native's Animated API
|
|
73
|
-
const {
|
|
74
|
-
Animated
|
|
75
|
-
} = require('react-native');
|
|
76
|
-
Animated.spring(tile.scaleValue, {
|
|
77
|
-
toValue: 1,
|
|
78
|
-
useNativeDriver: true,
|
|
79
|
-
tension: GAME_CONFIG.ANIMATION_CONFIG.TENSION,
|
|
80
|
-
friction: GAME_CONFIG.ANIMATION_CONFIG.FRICTION
|
|
81
|
-
}).start();
|
|
82
|
-
}, 100);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
updateGrid: newGrid => {
|
|
88
|
-
set(state => {
|
|
89
|
-
state.grid = newGrid;
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
incrementTime: () => {
|
|
93
|
-
set(state => {
|
|
94
|
-
state.timeElapsed += 1;
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
setIsAnimating: animating => {
|
|
98
|
-
set(state => {
|
|
99
|
-
state.isAnimating = animating;
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
setGameOver: gameOver => {
|
|
103
|
-
set(state => {
|
|
104
|
-
state.isGameOver = gameOver;
|
|
105
|
-
if (gameOver) {
|
|
106
|
-
state.isPlaying = false;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
setWon: won => {
|
|
111
|
-
set(state => {
|
|
112
|
-
state.isWon = won;
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
incrementTileId: () => {
|
|
116
|
-
const state = get();
|
|
117
|
-
const newId = state.nextTileId;
|
|
118
|
-
set(draft => {
|
|
119
|
-
draft.nextTileId = newId + 1;
|
|
120
|
-
});
|
|
121
|
-
return newId;
|
|
122
|
-
},
|
|
123
|
-
handleMove: direction => {
|
|
124
|
-
const state = get();
|
|
125
|
-
|
|
126
|
-
// Early returns for better performance
|
|
127
|
-
if (state.isGameOver || state.isWon || state.isAnimating) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Batch state updates for better performance
|
|
132
|
-
set(draft => {
|
|
133
|
-
// Auto-start the game if not playing
|
|
134
|
-
if (!draft.isPlaying) {
|
|
135
|
-
draft.isPlaying = true;
|
|
136
|
-
}
|
|
137
|
-
draft.isAnimating = true;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Create a shallow copy for better memory performance
|
|
141
|
-
const gridCopy = state.grid.map(row => row.slice());
|
|
142
|
-
const {
|
|
143
|
-
moved,
|
|
144
|
-
score: moveScore
|
|
145
|
-
} = gameService.moveTiles(gridCopy, direction);
|
|
146
|
-
if (moved) {
|
|
147
|
-
// Batch all state updates together
|
|
148
|
-
const newTileId = state.nextTileId;
|
|
149
|
-
const newTile = gameService.addRandomTile(gridCopy, newTileId);
|
|
150
|
-
|
|
151
|
-
// Check game state before updating
|
|
152
|
-
const hasWon = gameService.hasWon(gridCopy, state.targetValue);
|
|
153
|
-
const isGameOver = gameService.checkGameOver(gridCopy);
|
|
154
|
-
|
|
155
|
-
// Single state update for all changes
|
|
156
|
-
set(draft => {
|
|
157
|
-
draft.grid = gridCopy;
|
|
158
|
-
draft.nextTileId = newTileId + 1;
|
|
159
|
-
if (hasWon) draft.isWon = true;
|
|
160
|
-
if (isGameOver) draft.isGameOver = true;
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Async sound/haptic feedback (non-blocking)
|
|
164
|
-
Promise.resolve().then(() => {
|
|
165
|
-
playSound(GAME_2048_SOUNDS.TILE_MOVE, state.enableSounds);
|
|
166
|
-
playHaptic(HapticType.LIGHT, state.enableHaptics);
|
|
167
|
-
if (moveScore > 0) {
|
|
168
|
-
playSound(GAME_2048_SOUNDS.TILE_MERGE, state.enableSounds);
|
|
169
|
-
playHaptic(HapticType.MEDIUM, state.enableHaptics);
|
|
170
|
-
}
|
|
171
|
-
if (newTile) {
|
|
172
|
-
playSound(GAME_2048_SOUNDS.NEW_TILE, state.enableSounds);
|
|
173
|
-
}
|
|
174
|
-
if (hasWon) {
|
|
175
|
-
playSound(GAME_2048_SOUNDS.GAME_WIN, state.enableSounds);
|
|
176
|
-
playHaptic(HapticType.SUCCESS, state.enableHaptics);
|
|
177
|
-
} else if (isGameOver) {
|
|
178
|
-
playSound(GAME_2048_SOUNDS.GAME_OVER, state.enableSounds);
|
|
179
|
-
playHaptic(HapticType.ERROR, state.enableHaptics);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Optimized animation handling
|
|
184
|
-
if (newTile?.scaleValue) {
|
|
185
|
-
const {
|
|
186
|
-
Animated
|
|
187
|
-
} = require('react-native');
|
|
188
|
-
newTile.scaleValue.setValue(0);
|
|
189
|
-
Animated.spring(newTile.scaleValue, {
|
|
190
|
-
toValue: 1,
|
|
191
|
-
useNativeDriver: true,
|
|
192
|
-
tension: GAME_CONFIG.ANIMATION_CONFIG.TENSION,
|
|
193
|
-
friction: GAME_CONFIG.ANIMATION_CONFIG.FRICTION
|
|
194
|
-
}).start(() => {
|
|
195
|
-
set(draft => {
|
|
196
|
-
draft.isAnimating = false;
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
} else {
|
|
200
|
-
set(draft => {
|
|
201
|
-
draft.isAnimating = false;
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return true;
|
|
205
|
-
} else {
|
|
206
|
-
// Async invalid move feedback
|
|
207
|
-
Promise.resolve().then(() => {
|
|
208
|
-
playSound(GAME_2048_SOUNDS.INVALID_MOVE, state.enableSounds);
|
|
209
|
-
playHaptic(HapticType.WARNING, state.enableHaptics);
|
|
210
|
-
});
|
|
211
|
-
set(draft => {
|
|
212
|
-
draft.isAnimating = false;
|
|
213
|
-
});
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
updateSettings: (enableSounds, enableHaptics) => {
|
|
218
|
-
set(state => {
|
|
219
|
-
state.enableSounds = enableSounds;
|
|
220
|
-
state.enableHaptics = enableHaptics;
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
})));
|
|
225
|
-
|
|
226
|
-
// Selector hooks for performance optimization
|
|
227
|
-
export const useTimeElapsed = () => useGame2048Store(state => state.timeElapsed);
|
|
228
|
-
export const useGrid = () => useGame2048Store(state => state.grid);
|
|
229
|
-
export const useIsPlaying = () => useGame2048Store(state => state.isPlaying);
|
|
230
|
-
export const useIsGameOver = () => useGame2048Store(state => state.isGameOver);
|
|
231
|
-
export const useIsWon = () => useGame2048Store(state => state.isWon);
|
|
232
|
-
export const useIsAnimating = () => useGame2048Store(state => state.isAnimating);
|
|
233
|
-
export const useDifficulty = () => useGame2048Store(state => state.difficulty);
|
|
234
|
-
export const useTargetValue = () => useGame2048Store(state => state.targetValue);
|
|
235
|
-
export const useGridSize = () => useGame2048Store(state => state.gridSize);
|
|
236
|
-
//# sourceMappingURL=Game2048Store.js.map
|
|
1
|
+
"use strict";import{create}from 'zustand';import{subscribeWithSelector}from 'zustand/middleware';import{Game2048Service}from "./Game2048Service.js";import{GAME_CONFIG,GAME_2048_SOUNDS,GAME_2048_SETTINGS}from "./Game2048Constants.js";import{immerMiddleware}from "../../services/UtilsService.js";import{playSound}from "../../services/SoundsService.js";import{playHaptic,HapticType}from "../../services/HapticsService.js";export const useGame2048Store = create()(subscribeWithSelector(immerMiddleware((set,get)=>{const gameService = new Game2048Service();return{timeElapsed:0,isPlaying:false,isGameOver:false,isWon:false,isAnimating:false,grid:gameService.createGrid(),nextTileId:1,difficulty:'easy',targetValue:2048,gridSize:4,enableSounds:true,enableHaptics:true,startGame:()=>{set(state =>{state.isPlaying = true;state.timeElapsed = 0;});},stopGame:()=>{const state = get();state.initializeGame(state.difficulty);},resetGame:()=>{const state = get();state.initializeGame(state.difficulty);},initializeGame:(difficulty = 'easy')=>{set(state =>{const difficultySettings = GAME_2048_SETTINGS.DIFFICULTY_SETTINGS[difficulty];state.grid = gameService.createGrid();let tileId = 1;const tile1 = gameService.addRandomTile(state.grid,tileId++);const tile2 = gameService.addRandomTile(state.grid,tileId++);state.timeElapsed = 0;state.isPlaying = false;state.isGameOver = false;state.isWon = false;state.isAnimating = false;state.nextTileId = tileId;state.difficulty = difficulty;state.targetValue = difficultySettings.targetTile;state.gridSize = difficultySettings.gridSize;[tile1,tile2].forEach(tile =>{if(tile?.scaleValue){setTimeout(()=>{tile.scaleValue?.setValue(0);const{Animated}= require('react-native');Animated.spring(tile.scaleValue,{toValue:1,useNativeDriver:true,tension:GAME_CONFIG.ANIMATION_CONFIG.TENSION,friction:GAME_CONFIG.ANIMATION_CONFIG.FRICTION}).start();},100);}});});},updateGrid:newGrid =>{set(state =>{state.grid = newGrid;});},incrementTime:()=>{set(state =>{state.timeElapsed += 1;});},setIsAnimating:animating =>{set(state =>{state.isAnimating = animating;});},setGameOver:gameOver =>{set(state =>{state.isGameOver = gameOver;if(gameOver){state.isPlaying = false;}});},setWon:won =>{set(state =>{state.isWon = won;});},incrementTileId:()=>{const state = get();const newId = state.nextTileId;set(draft =>{draft.nextTileId = newId + 1;});return newId;},handleMove:direction =>{const state = get();if(state.isGameOver || state.isWon || state.isAnimating){return false;}set(draft =>{if(!draft.isPlaying){draft.isPlaying = true;}draft.isAnimating = true;});const gridCopy = state.grid.map(row => row.slice());const{moved,score:moveScore}= gameService.moveTiles(gridCopy,direction);if(moved){const newTileId = state.nextTileId;const newTile = gameService.addRandomTile(gridCopy,newTileId);const hasWon = gameService.hasWon(gridCopy,state.targetValue);const isGameOver = gameService.checkGameOver(gridCopy);set(draft =>{draft.grid = gridCopy;draft.nextTileId = newTileId + 1;if(hasWon)draft.isWon = true;if(isGameOver)draft.isGameOver = true;});Promise.resolve().then(()=>{playSound(GAME_2048_SOUNDS.TILE_MOVE,state.enableSounds);playHaptic(HapticType.LIGHT,state.enableHaptics);if(moveScore > 0){playSound(GAME_2048_SOUNDS.TILE_MERGE,state.enableSounds);playHaptic(HapticType.MEDIUM,state.enableHaptics);}if(newTile){playSound(GAME_2048_SOUNDS.NEW_TILE,state.enableSounds);}if(hasWon){playSound(GAME_2048_SOUNDS.GAME_WIN,state.enableSounds);playHaptic(HapticType.SUCCESS,state.enableHaptics);}else if(isGameOver){playSound(GAME_2048_SOUNDS.GAME_OVER,state.enableSounds);playHaptic(HapticType.ERROR,state.enableHaptics);}});if(newTile?.scaleValue){const{Animated}= require('react-native');newTile.scaleValue.setValue(0);Animated.spring(newTile.scaleValue,{toValue:1,useNativeDriver:true,tension:GAME_CONFIG.ANIMATION_CONFIG.TENSION,friction:GAME_CONFIG.ANIMATION_CONFIG.FRICTION}).start(()=>{set(draft =>{draft.isAnimating = false;});});}else{set(draft =>{draft.isAnimating = false;});}return true;}else{Promise.resolve().then(()=>{playSound(GAME_2048_SOUNDS.INVALID_MOVE,state.enableSounds);playHaptic(HapticType.WARNING,state.enableHaptics);});set(draft =>{draft.isAnimating = false;});return false;}},updateSettings:(enableSounds,enableHaptics)=>{set(state =>{state.enableSounds = enableSounds;state.enableHaptics = enableHaptics;});}};})));export const useTimeElapsed =()=> useGame2048Store(state => state.timeElapsed);export const useGrid =()=> useGame2048Store(state => state.grid);export const useIsPlaying =()=> useGame2048Store(state => state.isPlaying);export const useIsGameOver =()=> useGame2048Store(state => state.isGameOver);export const useIsWon =()=> useGame2048Store(state => state.isWon);export const useIsAnimating =()=> useGame2048Store(state => state.isAnimating);export const useDifficulty =()=> useGame2048Store(state => state.difficulty);export const useTargetValue =()=> useGame2048Store(state => state.targetValue);export const useGridSize =()=> useGame2048Store(state => state.gridSize);
|
|
@@ -1,247 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { View, StyleSheet, Dimensions } from 'react-native';
|
|
5
|
-
import { Canvas, LinearGradient, Rect, vec, Circle, RoundedRect } from '@shopify/react-native-skia';
|
|
6
|
-
import { BACKGROUND_TILE_COLORS } from "../Game2048Constants.js";
|
|
7
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
-
const {
|
|
9
|
-
width,
|
|
10
|
-
height
|
|
11
|
-
} = Dimensions.get('window');
|
|
12
|
-
export const GameBackground = /*#__PURE__*/React.memo(({
|
|
13
|
-
children
|
|
14
|
-
}) => {
|
|
15
|
-
// Generate beautiful floating 2048 tiles
|
|
16
|
-
const generateFloatingTiles = React.useMemo(() => {
|
|
17
|
-
const elements = [];
|
|
18
|
-
const tileCount = 30;
|
|
19
|
-
for (let i = 0; i < tileCount; i++) {
|
|
20
|
-
const baseX = width / tileCount * i;
|
|
21
|
-
const baseY = height / tileCount * i;
|
|
22
|
-
|
|
23
|
-
// Add subtle random offset for natural look
|
|
24
|
-
const x = baseX + Math.sin(i * 0.5) * 60 + Math.random() * 120;
|
|
25
|
-
const y = baseY + Math.cos(i * 0.7) * 80 + Math.random() * 140;
|
|
26
|
-
const tileSize = 15 + Math.random() * 25;
|
|
27
|
-
const colorIndex = i % BACKGROUND_TILE_COLORS.length;
|
|
28
|
-
const opacity = 0.25 + Math.sin(i) * 0.15;
|
|
29
|
-
|
|
30
|
-
// 2048 tile with varied shapes to suggest numbers
|
|
31
|
-
const tileX = Math.max(tileSize / 2, Math.min(width - tileSize, x));
|
|
32
|
-
const tileY = Math.max(tileSize / 2, Math.min(height - tileSize, y));
|
|
33
|
-
|
|
34
|
-
// Create different tile patterns inspired by 2048 numbers
|
|
35
|
-
if (i % 5 === 0) {
|
|
36
|
-
// Square tiles (like 2, 4, 8)
|
|
37
|
-
elements.push(/*#__PURE__*/_jsx(RoundedRect, {
|
|
38
|
-
x: tileX,
|
|
39
|
-
y: tileY,
|
|
40
|
-
width: tileSize,
|
|
41
|
-
height: tileSize,
|
|
42
|
-
r: tileSize * 0.25,
|
|
43
|
-
color: `${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
44
|
-
}, `square-tile-${i}`));
|
|
45
|
-
} else if (i % 5 === 1) {
|
|
46
|
-
// Rectangular tiles (like 16, 32)
|
|
47
|
-
elements.push(/*#__PURE__*/_jsx(RoundedRect, {
|
|
48
|
-
x: tileX,
|
|
49
|
-
y: tileY,
|
|
50
|
-
width: tileSize * 0.7,
|
|
51
|
-
height: tileSize,
|
|
52
|
-
r: tileSize * 0.2,
|
|
53
|
-
color: `${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
54
|
-
}, `rect-tile-${i}`));
|
|
55
|
-
} else if (i % 5 === 2) {
|
|
56
|
-
// Wide tiles (like 64, 128)
|
|
57
|
-
elements.push(/*#__PURE__*/_jsx(RoundedRect, {
|
|
58
|
-
x: tileX,
|
|
59
|
-
y: tileY,
|
|
60
|
-
width: tileSize * 1.3,
|
|
61
|
-
height: tileSize * 0.8,
|
|
62
|
-
r: tileSize * 0.15,
|
|
63
|
-
color: `${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
64
|
-
}, `wide-tile-${i}`));
|
|
65
|
-
} else if (i % 5 === 3) {
|
|
66
|
-
// Circular tiles (like 256, 512)
|
|
67
|
-
elements.push(/*#__PURE__*/_jsx(Circle, {
|
|
68
|
-
cx: tileX + tileSize / 2,
|
|
69
|
-
cy: tileY + tileSize / 2,
|
|
70
|
-
r: tileSize / 2,
|
|
71
|
-
color: `${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
72
|
-
}, `circle-tile-${i}`));
|
|
73
|
-
} else {
|
|
74
|
-
// Diamond-like tiles (like 1024, 2048)
|
|
75
|
-
elements.push(/*#__PURE__*/_jsx(RoundedRect, {
|
|
76
|
-
x: tileX,
|
|
77
|
-
y: tileY,
|
|
78
|
-
width: tileSize * 0.9,
|
|
79
|
-
height: tileSize * 0.9,
|
|
80
|
-
r: tileSize * 0.3,
|
|
81
|
-
color: `${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
82
|
-
}, `diamond-tile-${i}`));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return elements;
|
|
86
|
-
}, []);
|
|
87
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
88
|
-
style: styles.container,
|
|
89
|
-
children: [/*#__PURE__*/_jsxs(Canvas, {
|
|
90
|
-
style: styles.backgroundCanvas,
|
|
91
|
-
children: [/*#__PURE__*/_jsx(Rect, {
|
|
92
|
-
x: 0,
|
|
93
|
-
y: 0,
|
|
94
|
-
width: width,
|
|
95
|
-
height: height,
|
|
96
|
-
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
97
|
-
start: vec(0, 0),
|
|
98
|
-
end: vec(width, height),
|
|
99
|
-
colors: [`${BACKGROUND_TILE_COLORS[0]}35`,
|
|
100
|
-
// Vibrant pink
|
|
101
|
-
`${BACKGROUND_TILE_COLORS[3]}30`,
|
|
102
|
-
// Orange
|
|
103
|
-
`${BACKGROUND_TILE_COLORS[6]}35`,
|
|
104
|
-
// Green
|
|
105
|
-
`${BACKGROUND_TILE_COLORS[9]}30`,
|
|
106
|
-
// Blue
|
|
107
|
-
`${BACKGROUND_TILE_COLORS[11]}35` // Purple
|
|
108
|
-
]
|
|
109
|
-
})
|
|
110
|
-
}), /*#__PURE__*/_jsx(Rect, {
|
|
111
|
-
x: 0,
|
|
112
|
-
y: 0,
|
|
113
|
-
width: width,
|
|
114
|
-
height: height,
|
|
115
|
-
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
116
|
-
start: vec(0, 0),
|
|
117
|
-
end: vec(width / 2, height / 2),
|
|
118
|
-
colors: [`${BACKGROUND_TILE_COLORS[1]}25`,
|
|
119
|
-
// Bright red
|
|
120
|
-
'transparent', `${BACKGROUND_TILE_COLORS[4]}25`,
|
|
121
|
-
// Yellow
|
|
122
|
-
'transparent', `${BACKGROUND_TILE_COLORS[7]}25`,
|
|
123
|
-
// Teal
|
|
124
|
-
'transparent']
|
|
125
|
-
})
|
|
126
|
-
}), /*#__PURE__*/_jsx(Rect, {
|
|
127
|
-
x: 0,
|
|
128
|
-
y: 0,
|
|
129
|
-
width: width,
|
|
130
|
-
height: height,
|
|
131
|
-
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
132
|
-
start: vec(width, 0),
|
|
133
|
-
end: vec(0, height),
|
|
134
|
-
colors: [`${BACKGROUND_TILE_COLORS[2]}20`,
|
|
135
|
-
// Deep orange
|
|
136
|
-
'transparent', `${BACKGROUND_TILE_COLORS[5]}20`,
|
|
137
|
-
// Lime
|
|
138
|
-
'transparent', `${BACKGROUND_TILE_COLORS[8]}20`,
|
|
139
|
-
// Cyan
|
|
140
|
-
'transparent']
|
|
141
|
-
})
|
|
142
|
-
}), generateFloatingTiles, /*#__PURE__*/_jsx(RoundedRect, {
|
|
143
|
-
x: width * 0.08,
|
|
144
|
-
y: height * 0.12,
|
|
145
|
-
width: 55,
|
|
146
|
-
height: 55,
|
|
147
|
-
r: 12,
|
|
148
|
-
color: `${BACKGROUND_TILE_COLORS[10]}60` // Indigo
|
|
149
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
150
|
-
x: width * 0.82,
|
|
151
|
-
y: height * 0.78,
|
|
152
|
-
width: 50,
|
|
153
|
-
height: 50,
|
|
154
|
-
r: 10,
|
|
155
|
-
color: `${BACKGROUND_TILE_COLORS[9]}60` // Blue
|
|
156
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
157
|
-
x: width * 0.78,
|
|
158
|
-
y: height * 0.15,
|
|
159
|
-
width: 45,
|
|
160
|
-
height: 45,
|
|
161
|
-
r: 9,
|
|
162
|
-
color: `${BACKGROUND_TILE_COLORS[8]}60` // Cyan
|
|
163
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
164
|
-
x: width * 0.12,
|
|
165
|
-
y: height * 0.72,
|
|
166
|
-
width: 60,
|
|
167
|
-
height: 60,
|
|
168
|
-
r: 14,
|
|
169
|
-
color: `${BACKGROUND_TILE_COLORS[7]}60` // Teal
|
|
170
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
171
|
-
x: width * 0.45,
|
|
172
|
-
y: height * 0.08,
|
|
173
|
-
width: 40,
|
|
174
|
-
height: 40,
|
|
175
|
-
r: 8,
|
|
176
|
-
color: `${BACKGROUND_TILE_COLORS[6]}60` // Green
|
|
177
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
178
|
-
x: width * 0.15,
|
|
179
|
-
y: height * 0.45,
|
|
180
|
-
width: 48,
|
|
181
|
-
height: 48,
|
|
182
|
-
r: 10,
|
|
183
|
-
color: `${BACKGROUND_TILE_COLORS[5]}60` // Lime
|
|
184
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
185
|
-
x: width * 0.72,
|
|
186
|
-
y: height * 0.55,
|
|
187
|
-
width: 42,
|
|
188
|
-
height: 42,
|
|
189
|
-
r: 8,
|
|
190
|
-
color: `${BACKGROUND_TILE_COLORS[4]}60` // Yellow
|
|
191
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
192
|
-
x: width * 0.55,
|
|
193
|
-
y: height * 0.85,
|
|
194
|
-
width: 38,
|
|
195
|
-
height: 38,
|
|
196
|
-
r: 7,
|
|
197
|
-
color: `${BACKGROUND_TILE_COLORS[3]}60` // Orange
|
|
198
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
199
|
-
cx: width * 0.25,
|
|
200
|
-
cy: height * 0.28,
|
|
201
|
-
r: 22,
|
|
202
|
-
color: `${BACKGROUND_TILE_COLORS[2]}50` // Deep orange
|
|
203
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
204
|
-
cx: width * 0.62,
|
|
205
|
-
cy: height * 0.32,
|
|
206
|
-
r: 26,
|
|
207
|
-
color: `${BACKGROUND_TILE_COLORS[1]}50` // Red
|
|
208
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
209
|
-
cx: width * 0.38,
|
|
210
|
-
cy: height * 0.68,
|
|
211
|
-
r: 20,
|
|
212
|
-
color: `${BACKGROUND_TILE_COLORS[0]}50` // Pink
|
|
213
|
-
}), Array.from({
|
|
214
|
-
length: Math.floor(width / 80)
|
|
215
|
-
}, (_, i) => /*#__PURE__*/_jsx(Rect, {
|
|
216
|
-
x: i * 80,
|
|
217
|
-
y: 0,
|
|
218
|
-
width: 1,
|
|
219
|
-
height: height,
|
|
220
|
-
color: "rgba(255, 255, 255, 0.08)"
|
|
221
|
-
}, `grid-v-${i}`)), Array.from({
|
|
222
|
-
length: Math.floor(height / 80)
|
|
223
|
-
}, (_, i) => /*#__PURE__*/_jsx(Rect, {
|
|
224
|
-
x: 0,
|
|
225
|
-
y: i * 80,
|
|
226
|
-
width: width,
|
|
227
|
-
height: 1,
|
|
228
|
-
color: "rgba(255, 255, 255, 0.08)"
|
|
229
|
-
}, `grid-h-${i}`))]
|
|
230
|
-
}), children]
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
const styles = StyleSheet.create({
|
|
234
|
-
container: {
|
|
235
|
-
flex: 1
|
|
236
|
-
},
|
|
237
|
-
backgroundCanvas: {
|
|
238
|
-
position: 'absolute',
|
|
239
|
-
top: 0,
|
|
240
|
-
left: 0,
|
|
241
|
-
right: 0,
|
|
242
|
-
bottom: 0,
|
|
243
|
-
width,
|
|
244
|
-
height
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
//# sourceMappingURL=GameBackground.js.map
|
|
1
|
+
"use strict";import React from 'react';import{View,StyleSheet,Dimensions}from 'react-native';import{Canvas,LinearGradient,Rect,vec,Circle,RoundedRect}from '@shopify/react-native-skia';import{BACKGROUND_TILE_COLORS}from "../Game2048Constants.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";const{width,height}= Dimensions.get('window');export const GameBackground = React.memo(({children})=>{const generateFloatingTiles = React.useMemo(()=>{const elements = [];const tileCount = 30;for(let i = 0;i < tileCount;i++){const baseX = width / tileCount * i;const baseY = height / tileCount * i;const x = baseX + Math.sin(i * 0.5)* 60 + Math.random()* 120;const y = baseY + Math.cos(i * 0.7)* 80 + Math.random()* 140;const tileSize = 15 + Math.random()* 25;const colorIndex = i % BACKGROUND_TILE_COLORS.length;const opacity = 0.25 + Math.sin(i)* 0.15;const tileX = Math.max(tileSize / 2,Math.min(width - tileSize,x));const tileY = Math.max(tileSize / 2,Math.min(height - tileSize,y));if(i % 5 === 0){elements.push(_jsx(RoundedRect,{x:tileX,y:tileY,width:tileSize,height:tileSize,r:tileSize * 0.25,color:`${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`square-tile-${i}`));}else if(i % 5 === 1){elements.push(_jsx(RoundedRect,{x:tileX,y:tileY,width:tileSize * 0.7,height:tileSize,r:tileSize * 0.2,color:`${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`rect-tile-${i}`));}else if(i % 5 === 2){elements.push(_jsx(RoundedRect,{x:tileX,y:tileY,width:tileSize * 1.3,height:tileSize * 0.8,r:tileSize * 0.15,color:`${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`wide-tile-${i}`));}else if(i % 5 === 3){elements.push(_jsx(Circle,{cx:tileX + tileSize / 2,cy:tileY + tileSize / 2,r:tileSize / 2,color:`${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`circle-tile-${i}`));}else{elements.push(_jsx(RoundedRect,{x:tileX,y:tileY,width:tileSize * 0.9,height:tileSize * 0.9,r:tileSize * 0.3,color:`${BACKGROUND_TILE_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`diamond-tile-${i}`));}}return elements;},[]);return _jsxs(View,{style:styles.container,children:[_jsxs(Canvas,{style:styles.backgroundCanvas,children:[_jsx(Rect,{x:0,y:0,width:width,height:height,children:_jsx(LinearGradient,{start:vec(0,0),end:vec(width,height),colors:[`${BACKGROUND_TILE_COLORS[0]}35`,`${BACKGROUND_TILE_COLORS[3]}30`,`${BACKGROUND_TILE_COLORS[6]}35`,`${BACKGROUND_TILE_COLORS[9]}30`,`${BACKGROUND_TILE_COLORS[11]}35` ]})}),_jsx(Rect,{x:0,y:0,width:width,height:height,children:_jsx(LinearGradient,{start:vec(0,0),end:vec(width / 2,height / 2),colors:[`${BACKGROUND_TILE_COLORS[1]}25`,'transparent',`${BACKGROUND_TILE_COLORS[4]}25`,'transparent',`${BACKGROUND_TILE_COLORS[7]}25`,'transparent']})}),_jsx(Rect,{x:0,y:0,width:width,height:height,children:_jsx(LinearGradient,{start:vec(width,0),end:vec(0,height),colors:[`${BACKGROUND_TILE_COLORS[2]}20`,'transparent',`${BACKGROUND_TILE_COLORS[5]}20`,'transparent',`${BACKGROUND_TILE_COLORS[8]}20`,'transparent']})}),generateFloatingTiles,_jsx(RoundedRect,{x:width * 0.08,y:height * 0.12,width:55,height:55,r:12,color:`${BACKGROUND_TILE_COLORS[10]}60`}),_jsx(RoundedRect,{x:width * 0.82,y:height * 0.78,width:50,height:50,r:10,color:`${BACKGROUND_TILE_COLORS[9]}60`}),_jsx(RoundedRect,{x:width * 0.78,y:height * 0.15,width:45,height:45,r:9,color:`${BACKGROUND_TILE_COLORS[8]}60`}),_jsx(RoundedRect,{x:width * 0.12,y:height * 0.72,width:60,height:60,r:14,color:`${BACKGROUND_TILE_COLORS[7]}60`}),_jsx(RoundedRect,{x:width * 0.45,y:height * 0.08,width:40,height:40,r:8,color:`${BACKGROUND_TILE_COLORS[6]}60`}),_jsx(RoundedRect,{x:width * 0.15,y:height * 0.45,width:48,height:48,r:10,color:`${BACKGROUND_TILE_COLORS[5]}60`}),_jsx(RoundedRect,{x:width * 0.72,y:height * 0.55,width:42,height:42,r:8,color:`${BACKGROUND_TILE_COLORS[4]}60`}),_jsx(RoundedRect,{x:width * 0.55,y:height * 0.85,width:38,height:38,r:7,color:`${BACKGROUND_TILE_COLORS[3]}60`}),_jsx(Circle,{cx:width * 0.25,cy:height * 0.28,r:22,color:`${BACKGROUND_TILE_COLORS[2]}50`}),_jsx(Circle,{cx:width * 0.62,cy:height * 0.32,r:26,color:`${BACKGROUND_TILE_COLORS[1]}50`}),_jsx(Circle,{cx:width * 0.38,cy:height * 0.68,r:20,color:`${BACKGROUND_TILE_COLORS[0]}50`}),Array.from({length:Math.floor(width / 80)},(_,i)=> _jsx(Rect,{x:i * 80,y:0,width:1,height:height,color:"rgba(255,255,255,0.08)"},`grid-v-${i}`)),Array.from({length:Math.floor(height / 80)},(_,i)=> _jsx(Rect,{x:0,y:i * 80,width:width,height:1,color:"rgba(255,255,255,0.08)"},`grid-h-${i}`))]}),children]});});const styles = StyleSheet.create({container:{flex:1},backgroundCanvas:{position:'absolute',top:0,left:0,right:0,bottom:0,width,height}});
|
|
@@ -1,139 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { View, StyleSheet, Dimensions } from 'react-native';
|
|
5
|
-
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
6
|
-
import { useGrid, useGame2048Store } from "../Game2048Store.js";
|
|
7
|
-
import { GameTile } from "./GameTile.js";
|
|
8
|
-
import { GAME_CONFIG } from "../Game2048Constants.js";
|
|
9
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
-
const {
|
|
11
|
-
width: screenWidth
|
|
12
|
-
} = Dimensions.get('window');
|
|
13
|
-
export const GameGrid = /*#__PURE__*/React.memo(() => {
|
|
14
|
-
const grid = useGrid();
|
|
15
|
-
const {
|
|
16
|
-
handleMove
|
|
17
|
-
} = useGame2048Store();
|
|
18
|
-
|
|
19
|
-
// Memoize calculations for better performance
|
|
20
|
-
const gridCalculations = React.useMemo(() => {
|
|
21
|
-
const horizontalPadding = 40;
|
|
22
|
-
const availableWidth = screenWidth - horizontalPadding;
|
|
23
|
-
const margin = GAME_CONFIG.TILE_MARGIN;
|
|
24
|
-
const responsiveTileSize = Math.floor((availableWidth - margin * 5) / 4);
|
|
25
|
-
const tileSize = Math.max(responsiveTileSize, 60);
|
|
26
|
-
const gridContainerSize = tileSize * 4 + margin * 5;
|
|
27
|
-
return {
|
|
28
|
-
margin,
|
|
29
|
-
tileSize,
|
|
30
|
-
gridContainerSize
|
|
31
|
-
};
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
// Memoized tile renderer for better performance
|
|
35
|
-
const renderTile = React.useCallback(tile => {
|
|
36
|
-
const {
|
|
37
|
-
margin,
|
|
38
|
-
tileSize
|
|
39
|
-
} = gridCalculations;
|
|
40
|
-
const x = margin + tile.col * (tileSize + margin);
|
|
41
|
-
const y = margin + tile.row * (tileSize + margin);
|
|
42
|
-
return /*#__PURE__*/_jsx(GameTile, {
|
|
43
|
-
tile: tile,
|
|
44
|
-
position: {
|
|
45
|
-
x,
|
|
46
|
-
y
|
|
47
|
-
},
|
|
48
|
-
size: tileSize
|
|
49
|
-
}, tile.id);
|
|
50
|
-
}, [gridCalculations]);
|
|
51
|
-
|
|
52
|
-
// Optimized gesture handler with memoization
|
|
53
|
-
const panGesture = React.useMemo(() => Gesture.Pan().onEnd(event => {
|
|
54
|
-
const {
|
|
55
|
-
translationX,
|
|
56
|
-
translationY
|
|
57
|
-
} = event;
|
|
58
|
-
const minDistance = 50;
|
|
59
|
-
const absX = Math.abs(translationX);
|
|
60
|
-
const absY = Math.abs(translationY);
|
|
61
|
-
if (absX > absY && absX > minDistance) {
|
|
62
|
-
handleMove(translationX > 0 ? 'right' : 'left');
|
|
63
|
-
} else if (absY > minDistance) {
|
|
64
|
-
handleMove(translationY > 0 ? 'down' : 'up');
|
|
65
|
-
}
|
|
66
|
-
}).runOnJS(true), [handleMove]);
|
|
67
|
-
return /*#__PURE__*/_jsx(View, {
|
|
68
|
-
style: styles.gameContainer,
|
|
69
|
-
children: /*#__PURE__*/_jsx(GestureDetector, {
|
|
70
|
-
gesture: panGesture,
|
|
71
|
-
children: /*#__PURE__*/_jsxs(View, {
|
|
72
|
-
style: [styles.grid, {
|
|
73
|
-
width: gridCalculations.gridContainerSize,
|
|
74
|
-
height: gridCalculations.gridContainerSize
|
|
75
|
-
}],
|
|
76
|
-
children: [React.useMemo(() => Array(16).fill(0).map((_, index) => {
|
|
77
|
-
const row = Math.floor(index / 4);
|
|
78
|
-
const col = index % 4;
|
|
79
|
-
const {
|
|
80
|
-
margin,
|
|
81
|
-
tileSize
|
|
82
|
-
} = gridCalculations;
|
|
83
|
-
const x = margin + col * (tileSize + margin);
|
|
84
|
-
const y = margin + row * (tileSize + margin);
|
|
85
|
-
return /*#__PURE__*/_jsx(View, {
|
|
86
|
-
style: [styles.cell, {
|
|
87
|
-
left: x,
|
|
88
|
-
top: y,
|
|
89
|
-
width: tileSize,
|
|
90
|
-
height: tileSize
|
|
91
|
-
}]
|
|
92
|
-
}, index);
|
|
93
|
-
}), [gridCalculations]), React.useMemo(() => {
|
|
94
|
-
const tiles = [];
|
|
95
|
-
for (const row of grid) {
|
|
96
|
-
for (const tile of row) {
|
|
97
|
-
if (tile) tiles.push(renderTile(tile));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return tiles;
|
|
101
|
-
}, [grid, renderTile])]
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
const styles = StyleSheet.create({
|
|
107
|
-
gameContainer: {
|
|
108
|
-
flex: 1,
|
|
109
|
-
justifyContent: 'center',
|
|
110
|
-
alignItems: 'center',
|
|
111
|
-
paddingHorizontal: 20,
|
|
112
|
-
// Responsive horizontal padding
|
|
113
|
-
paddingVertical: 10,
|
|
114
|
-
zIndex: 10,
|
|
115
|
-
position: 'relative'
|
|
116
|
-
},
|
|
117
|
-
grid: {
|
|
118
|
-
backgroundColor: 'rgba(187, 173, 160, 0.9)',
|
|
119
|
-
borderRadius: 15,
|
|
120
|
-
position: 'relative',
|
|
121
|
-
shadowColor: '#000',
|
|
122
|
-
shadowOffset: {
|
|
123
|
-
width: 0,
|
|
124
|
-
height: 8
|
|
125
|
-
},
|
|
126
|
-
shadowOpacity: 0.25,
|
|
127
|
-
shadowRadius: 15,
|
|
128
|
-
elevation: 15,
|
|
129
|
-
// Ensure grid doesn't overflow screen
|
|
130
|
-
maxWidth: screenWidth - 40
|
|
131
|
-
},
|
|
132
|
-
cell: {
|
|
133
|
-
position: 'absolute',
|
|
134
|
-
backgroundColor: 'rgba(238, 228, 218, 0.4)',
|
|
135
|
-
borderRadius: 6 // Slightly smaller border radius for better fit
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
GameGrid.displayName = 'GameGrid';
|
|
139
|
-
//# sourceMappingURL=GameGrid.js.map
|
|
1
|
+
"use strict";import React from 'react';import{View,StyleSheet,Dimensions}from 'react-native';import{Gesture,GestureDetector}from 'react-native-gesture-handler';import{useGrid,useGame2048Store}from "../Game2048Store.js";import{GameTile}from "./GameTile.js";import{GAME_CONFIG}from "../Game2048Constants.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";const{width:screenWidth}= Dimensions.get('window');export const GameGrid = React.memo(()=>{const grid = useGrid();const{handleMove}= useGame2048Store();const gridCalculations = React.useMemo(()=>{const horizontalPadding = 40;const availableWidth = screenWidth - horizontalPadding;const margin = GAME_CONFIG.TILE_MARGIN;const responsiveTileSize = Math.floor((availableWidth - margin * 5)/ 4);const tileSize = Math.max(responsiveTileSize,60);const gridContainerSize = tileSize * 4 + margin * 5;return{margin,tileSize,gridContainerSize};},[]);const renderTile = React.useCallback(tile =>{const{margin,tileSize}= gridCalculations;const x = margin + tile.col *(tileSize + margin);const y = margin + tile.row *(tileSize + margin);return _jsx(GameTile,{tile:tile,position:{x,y},size:tileSize},tile.id);},[gridCalculations]);const panGesture = React.useMemo(()=> Gesture.Pan().onEnd(event =>{const{translationX,translationY}= event;const minDistance = 50;const absX = Math.abs(translationX);const absY = Math.abs(translationY);if(absX > absY && absX > minDistance){handleMove(translationX > 0 ? 'right':'left');}else if(absY > minDistance){handleMove(translationY > 0 ? 'down':'up');}}).runOnJS(true),[handleMove]);return _jsx(View,{style:styles.gameContainer,children:_jsx(GestureDetector,{gesture:panGesture,children:_jsxs(View,{style:[styles.grid,{width:gridCalculations.gridContainerSize,height:gridCalculations.gridContainerSize}],children:[React.useMemo(()=> Array(16).fill(0).map((_,index)=>{const row = Math.floor(index / 4);const col = index % 4;const{margin,tileSize}= gridCalculations;const x = margin + col *(tileSize + margin);const y = margin + row *(tileSize + margin);return _jsx(View,{style:[styles.cell,{left:x,top:y,width:tileSize,height:tileSize}]},index);}),[gridCalculations]),React.useMemo(()=>{const tiles = [];for(const row of grid){for(const tile of row){if(tile)tiles.push(renderTile(tile));}}return tiles;},[grid,renderTile])]})})});});const styles = StyleSheet.create({gameContainer:{flex:1,justifyContent:'center',alignItems:'center',paddingHorizontal:20,paddingVertical:10,zIndex:10,position:'relative'},grid:{backgroundColor:'rgba(187,173,160,0.9)',borderRadius:15,position:'relative',shadowColor:'#000',shadowOffset:{width:0,height:8},shadowOpacity:0.25,shadowRadius:15,elevation:15,maxWidth:screenWidth - 40},cell:{position:'absolute',backgroundColor:'rgba(238,228,218,0.4)',borderRadius:6}});GameGrid.displayName = 'GameGrid';
|