diff --git a/src/pages/Tetris.tsx b/src/pages/Tetris.tsx index f2287cc..b22f2ab 100644 --- a/src/pages/Tetris.tsx +++ b/src/pages/Tetris.tsx @@ -59,6 +59,7 @@ const Tetris = () => { const { playSound } = useSettings(); const [board, setBoard] = useState(createBoard); const [piece, setPiece] = useState(randomTetromino); + const [nextPiece, setNextPiece] = useState(randomTetromino); const [score, setScore] = useState(0); const [highScore, setHighScore] = useState(0); const [lines, setLines] = useState(0); @@ -69,7 +70,6 @@ const Tetris = () => { const [showGlitchCrash, setShowGlitchCrash] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false); const gameRef = useRef(null); - const { enterFullscreen, exitFullscreen } = useBrowserFullscreen(); const getCellSize = useCallback(() => { @@ -176,11 +176,12 @@ const Tetris = () => { }); } else { playSound('click'); } setBoard(clearedBoard); - const newTetromino = randomTetromino(); + const newTetromino = nextPiece; + setNextPiece(randomTetromino()); if (!isValidMove(newTetromino, clearedBoard)) { setGameOver(true); playSound('error'); } else { setPiece(newTetromino); } } - }, [piece, board, gameOver, gameComplete, isPaused, gameStarted, isValidMove, mergePiece, clearLines, playSound, highScore]); + }, [piece, board, gameOver, gameComplete, isPaused, gameStarted, isValidMove, mergePiece, clearLines, playSound, highScore, nextPiece]); const moveLeft = useCallback(() => { if (gameOver || gameComplete || isPaused || !gameStarted) return; @@ -212,6 +213,7 @@ const Tetris = () => { const startGame = () => { setBoard(createBoard()); setPiece(randomTetromino()); + setNextPiece(randomTetromino()); setScore(0); setLines(0); setGameOver(false); @@ -286,12 +288,22 @@ const Tetris = () => { {isFullscreen ? : } -
{renderBoard()}
- {!isMobile && (
+
+

NEXT

+
+ {nextPiece.shape.map((row, y) => ( +
+ {row.map((val, x) => ( +
+ ))} +
+ ))} +
+

SCORE

{score.toLocaleString()}

HIGH SCORE

{highScore.toLocaleString()}

max: 4,294,967,296

LINES

{lines}

@@ -303,7 +315,6 @@ const Tetris = () => { )}
)} - {isMobile && (
@@ -330,7 +341,6 @@ const Tetris = () => {
)}
- {!isMobile && (gameOver || isPaused || gameComplete) && gameStarted && (