Integrated Home comp with the game comp

This commit is contained in:
2024-02-13 09:41:01 +01:00
parent 232aae14a8
commit 79962f45dc
7 changed files with 170 additions and 86 deletions
+6 -6
View File
@@ -22,10 +22,10 @@ import Flag from '../../assets/flag.png';
import './styles.scss';
// ---------------------------------------------------------------------------------------------------------------------
const Grid = ({ size = 12, difficulty = 'beginner' }) => {
const Grid = () => {
const [gameState, setGameState] = useRecoilState(gameStateAtom);
const [grid, setGrid] = useState(genGrid(size));
const [grid, setGrid] = useState(genGrid(gameState.gridSize));
const [, updateGrid] = useState({});
const forceUpdate = useCallback(() => updateGrid({}), []);
@@ -37,7 +37,7 @@ const Grid = ({ size = 12, difficulty = 'beginner' }) => {
if (grid[rowIndex][colIndex].hidden && !grid[rowIndex][colIndex].flag) {
setGrid((prev) => {
if (gameState.status === 'idle') {
const { grid: newGrid, bombsCount } = startGame(prev, difficulty as Difficulty, true, rowIndex, colIndex);
const { grid: newGrid, bombsCount } = startGame(prev, gameState.difficulty as Difficulty, true, rowIndex, colIndex);
prev = newGrid;
setGameState((prevGameState) => ({
@@ -59,7 +59,7 @@ const Grid = ({ size = 12, difficulty = 'beginner' }) => {
if (grid[rowIndex][colIndex].hidden) {
setGrid((prev) => {
if (gameState.status === 'idle') {
const { grid: newGrid, bombsCount } = startGame(prev, difficulty as Difficulty, false);
const { grid: newGrid, bombsCount } = startGame(prev, gameState.difficulty as Difficulty, false);
prev = newGrid;
setGameState((prevGameState) => ({
@@ -97,7 +97,7 @@ const Grid = ({ size = 12, difficulty = 'beginner' }) => {
<div
className='grid'
style={{
gridTemplateRows: `repeat(${size}, var(--size))`,
gridTemplateRows: `repeat(${gameState.gridSize}, var(--size))`,
}}
>
{grid.map((row, rowIndex) => (
@@ -105,7 +105,7 @@ const Grid = ({ size = 12, difficulty = 'beginner' }) => {
key={`row${rowIndex}`}
className='row'
style={{
gridTemplateColumns: `repeat(${size}, var(--size))`,
gridTemplateColumns: `repeat(${gameState.gridSize}, var(--size))`,
}}
>
{row.map((cell, cellIndex) => {