This commit is contained in:
2025-12-08 12:24:45 +00:00
parent 2db041f919
commit e987f3de3b
6 changed files with 107 additions and 0 deletions
+10
View File
@@ -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';
@@ -26,6 +27,7 @@ interface Brick {
const Breakout = () => {
const { playSound } = useSettings();
const { checkGameScoreAchievements, unlockMaxScore } = useAchievements();
const [isFullscreen, setIsFullscreen] = useState(false);
const [score, setScore] = useState(0);
const [highScore, setHighScore] = useState(0);
@@ -96,6 +98,14 @@ const Breakout = () => {
if (saved) setHighScore(Math.min(parseInt(saved, 10), MAX_SCORE));
}, []);
// Check score achievements
useEffect(() => {
if (score > 0) {
checkGameScoreAchievements('breakout', score);
if (score >= MAX_SCORE) unlockMaxScore();
}
}, [score, checkGameScoreAchievements, unlockMaxScore]);
const initBricks = useCallback(() => {
const bricks: Brick[] = [];
const brickWidth = (canvasSize.width - (BRICK_COLS + 1) * BRICK_GAP) / BRICK_COLS;
+10
View File
@@ -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';
@@ -43,6 +44,7 @@ const MAZE_TEMPLATE = [
const Pacman = () => {
const { playSound } = useSettings();
const { checkGameScoreAchievements, unlockMaxScore } = useAchievements();
const [pacman, setPacman] = useState<Position>({ x: 10, y: 15 });
const [direction, setDirection] = useState<Direction>('right');
const [nextDirection, setNextDirection] = useState<Direction>('right');
@@ -112,6 +114,14 @@ const Pacman = () => {
if (saved) setHighScore(Math.min(parseInt(saved, 10), MAX_SCORE));
}, []);
// Check score achievements
useEffect(() => {
if (score > 0) {
checkGameScoreAchievements('pacman', score);
if (score >= MAX_SCORE) unlockMaxScore();
}
}, [score, checkGameScoreAchievements, unlockMaxScore]);
const initDots = useCallback(() => {
const newDots = new Set<string>();
const newPowerPellets = new Set<string>();
+10
View File
@@ -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';
@@ -17,6 +18,7 @@ type Position = { x: number; y: number };
const Snake = () => {
const { playSound } = useSettings();
const { checkGameScoreAchievements, unlockMaxScore } = useAchievements();
const [snake, setSnake] = useState<Position[]>([{ x: 10, y: 10 }]);
const [direction, setDirection] = useState<Direction>('right');
const [food, setFood] = useState<Position>({ x: 15, y: 10 });
@@ -94,6 +96,14 @@ const Snake = () => {
if (saved) setHighScore(Math.min(parseInt(saved, 10), MAX_SCORE));
}, []);
// Check score achievements
useEffect(() => {
if (score > 0) {
checkGameScoreAchievements('snake', score);
if (score >= MAX_SCORE) unlockMaxScore();
}
}, [score, checkGameScoreAchievements, unlockMaxScore]);
const spawnFood = useCallback((currentSnake: Position[]): Position | null => {
const occupied = new Set(currentSnake.map(s => `${s.x},${s.y}`));
const available: Position[] = [];
+10
View File
@@ -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++) {