Changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useSettings } from '@/contexts/SettingsContext';
|
||||
import { useAchievements } from '@/contexts/AchievementsContext';
|
||||
import { Link } from 'react-router-dom';
|
||||
import GlitchCrash from '@/components/GlitchCrash';
|
||||
import { Maximize2, Minimize2 } from 'lucide-react';
|
||||
@@ -57,6 +58,7 @@ const rotate = (matrix: number[][]): number[][] => {
|
||||
|
||||
const Tetris = () => {
|
||||
const { playSound } = useSettings();
|
||||
const { checkGameScoreAchievements, unlockMaxScore } = useAchievements();
|
||||
const [board, setBoard] = useState<Board>(createBoard);
|
||||
const [piece, setPiece] = useState<Piece>(randomTetromino);
|
||||
const [nextPiece, setNextPiece] = useState<Piece>(randomTetromino);
|
||||
@@ -122,6 +124,14 @@ const Tetris = () => {
|
||||
if (saved) setHighScore(Math.min(parseInt(saved, 10), MAX_SCORE));
|
||||
}, []);
|
||||
|
||||
// Check score achievements
|
||||
useEffect(() => {
|
||||
if (score > 0) {
|
||||
checkGameScoreAchievements('tetris', score);
|
||||
if (score >= MAX_SCORE) unlockMaxScore();
|
||||
}
|
||||
}, [score, checkGameScoreAchievements, unlockMaxScore]);
|
||||
|
||||
const isValidMove = useCallback((newPiece: Piece, currentBoard: Board): boolean => {
|
||||
for (let y = 0; y < newPiece.shape.length; y++) {
|
||||
for (let x = 0; x < newPiece.shape[y].length; x++) {
|
||||
|
||||
Reference in New Issue
Block a user