Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
Signed-off-by: mateusz <mateusz@stake.fish>
  • Loading branch information
mateuszsokola authored and mateush committed Sep 1, 2024
1 parent 6463d2e commit 413d05a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function Board() {
return (
<MobileSwiper onSwipe={handleSwipe}>
<div className={styles.board}>
{status === "won" && <Splash heading="You won!" type="won"/>}
{status === "won" && <Splash heading="You won!" type="won" />}
{status === "lost" && <Splash heading="You lost!" />}
<div className={styles.tiles}>{renderTiles()}</div>
<div className={styles.grid}>{renderGrid()}</div>
Expand Down
25 changes: 17 additions & 8 deletions context/game-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,34 @@ export default function GameProvider({ children }: PropsWithChildren) {

if (isWon) {
dispatch({ type: "update_status", status: "won" });
return
return;
}

const { tiles, board } = gameState;

const maxIndex = tileCountPerDimension - 1;
for (let x = 0; x < maxIndex; x += 1) {
for (let y = 0; y < maxIndex; y += 1) {
if (isNil(gameState.board[x][y]) || isNil(gameState.board[x + 1][y]) || isNil(gameState.board[x][y + 1])) {
return
if (
isNil(gameState.board[x][y]) ||
isNil(gameState.board[x + 1][y]) ||
isNil(gameState.board[x][y + 1])
) {
return;
}

if (x < maxIndex && tiles[board[x][y]].value === tiles[board[x + 1][y]].value) {
return
if (
x < maxIndex &&
tiles[board[x][y]].value === tiles[board[x + 1][y]].value
) {
return;
}

if (y < maxIndex && tiles[board[x][y]].value === tiles[board[x][y + 1]].value) {
return
if (
y < maxIndex &&
tiles[board[x][y]].value === tiles[board[x][y + 1]].value
) {
return;
}
}
}
Expand All @@ -112,7 +122,6 @@ export default function GameProvider({ children }: PropsWithChildren) {
}
}, [gameState.hasChanged]);


useEffect(() => {
if (!gameState.hasChanged) {
checkGameState();
Expand Down
4 changes: 2 additions & 2 deletions styles/splash.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

.win {
background: rgba(237, 194, 46, 0.6);
color: white
color: white;
}

.splash > div {
Expand All @@ -36,7 +36,7 @@
border-radius: calc(var(--pixel-size) * 0.5);
font-size: calc(var(--pixel-size) * 2);
line-height: calc(var(--pixel-size) * 4);
padding: calc(var(--pixel-size) * .5) calc(var(--pixel-size) * 2);
padding: calc(var(--pixel-size) * 0.5) calc(var(--pixel-size) * 2);
font-weight: bold;
color: white;
cursor: pointer;
Expand Down

0 comments on commit 413d05a

Please sign in to comment.