fix(leaderboard)!: Replay button now generate new bombs & numbers on first grid click
This commit is contained in:
@@ -93,7 +93,7 @@ const LeaderBoard = () => {
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
className='controlButton replay'
|
className='controlButton replay'
|
||||||
onClick={() => setGameState((prev) => ({ ...prev, status: 'idle' }))}
|
onClick={() => setGameState((prev) => ({ ...prev, status: 'idle', endType: '', placedFlags: 0, bombs: 0, gameTime: 0 }))}
|
||||||
>
|
>
|
||||||
<Replay />
|
<Replay />
|
||||||
Rejouer
|
Rejouer
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { atom } from 'recoil';
|
|||||||
/**
|
/**
|
||||||
* Values:
|
* Values:
|
||||||
* - Status: 'settings' | 'idle' | 'playing' | 'board'
|
* - Status: 'settings' | 'idle' | 'playing' | 'board'
|
||||||
* - Difficulty: 'begginer' | 'intermediate' | 'expert'
|
* - Difficulty: 'beginner' | 'intermediate' | 'expert'
|
||||||
* - Grid Size: 12, 16, 20
|
* - Grid Size: 12, 16, 20
|
||||||
* - Bombs: ]0;{GridSize}]
|
* - Bombs: ]0;{GridSize}]
|
||||||
* - Placed Flags: [0;{GridSize}]
|
* - Placed Flags: [0;{GridSize}]
|
||||||
@@ -15,7 +15,7 @@ export const gameStateAtom = atom({
|
|||||||
key: 'gameState',
|
key: 'gameState',
|
||||||
default: {
|
default: {
|
||||||
status: 'board',
|
status: 'board',
|
||||||
difficulty: 'begginer',
|
difficulty: 'beginner',
|
||||||
gridSize: 12,
|
gridSize: 12,
|
||||||
bombs: 0,
|
bombs: 0,
|
||||||
placedFlags: 0,
|
placedFlags: 0,
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ export const genBombs = (grid: GridType, difficulty: Difficulty) => {
|
|||||||
bombs = surface * 0.15;
|
bombs = surface * 0.15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(difficulty);
|
||||||
|
// console.log(surface, surface * 0.05, bombs);
|
||||||
|
|
||||||
bombs = Math.floor(bombs);
|
bombs = Math.floor(bombs);
|
||||||
for (let i = 1; i <= bombs; i++) {
|
for (let i = 1; i <= bombs; i++) {
|
||||||
let needRegenerate = false;
|
let needRegenerate = false;
|
||||||
@@ -164,6 +167,7 @@ export const startGame = (grid: GridType, difficulty: Difficulty, needEmpty: boo
|
|||||||
} while (grid[rowIndex][colIndex].value !== 'empty');
|
} while (grid[rowIndex][colIndex].value !== 'empty');
|
||||||
|
|
||||||
grid = genNumbers(grid);
|
grid = genNumbers(grid);
|
||||||
|
// console.log(grid, bombsCount);
|
||||||
return { grid, bombsCount };
|
return { grid, bombsCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user