Ability to loose game

This commit is contained in:
2024-02-18 09:50:33 +01:00
parent e21910547a
commit 8219634b9c
8 changed files with 113 additions and 28 deletions
+29 -1
View File
@@ -13,13 +13,14 @@ import { gameStateAtom } from '../../contexts/gameState';
// ------------------------------------------------------ Utils --------------------------------------------------------
import { Difficulty } from '../../types/game';
import { discoverAroundCell, genGrid, startGame } from '../../utils/game';
import { discoverAroundCell, genGrid, revealAllGrid, startGame } from '../../utils/game';
// ---------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------- Assets --------------------------------------------------------
import Bomb from '../../assets/bomb.png';
import Flag from '../../assets/flag.png';
import './styles.scss';
import Podium from '../../assets/podium';
// ---------------------------------------------------------------------------------------------------------------------
const Grid = () => {
@@ -47,6 +48,14 @@ const Grid = () => {
}));
}
if (prev[rowIndex][colIndex].value === 'bomb') {
setGameState((prev) => ({
...prev,
endType: 'loose',
}));
return revealAllGrid(grid, true);
}
return discoverAroundCell(prev, rowIndex, colIndex);
});
forceUpdate();
@@ -138,6 +147,25 @@ const Grid = () => {
})}
</div>
))}
{gameState.endType !== '' && (
<div
className='overlay'
style={
{
'--overlayColor': gameState.endType === 'win' ? '#5f8e59' : '#ca5940',
} as React.CSSProperties
}
>
<p className='overlayTitle'>{gameState.endType === 'win' ? 'Gagné !' : 'Perdu !'}</p>
<button
className='overlayButton'
onClick={() => setGameState((prev) => ({ ...prev, status: 'board' }))}
>
<Podium />
Leaderboard
</button>
</div>
)}
</div>
);
};