diff --git a/app/games/[gameId]/visualizer.tsx b/app/games/[gameId]/visualizer.tsx deleted file mode 100644 index f0abbff..0000000 --- a/app/games/[gameId]/visualizer.tsx +++ /dev/null @@ -1,90 +0,0 @@ -import { Button } from "@/components/ui/button"; -import { ZombieSurvival } from "@/simulators/zombie-survival"; -import { useEffect, useRef, useState } from "react"; - -const REPLAY_SPEED = 600; - -export function Visualizer({ - map, - autoStart = false, - onSimulationEnd, -}: { - map: string[][]; - autoStart?: boolean; - onSimulationEnd?: (isWin: boolean) => void; -}) { - const simulator = useRef(null); - const interval = useRef(null); - const [isRunning, setIsRunning] = useState(false); - const [mapState, setMapState] = useState(map); - const [needsReset, setNeedsReset] = useState(false); - - const startSimulation = () => { - setNeedsReset(true); - const clonedMap = JSON.parse(JSON.stringify(map)); - simulator.current = new ZombieSurvival(clonedMap); - setMapState(simulator.current!.getState()); - setIsRunning(true); - interval.current = setInterval(() => { - if (simulator.current!.finished()) { - clearInterval(interval.current!); - interval.current = null; - setIsRunning(false); - if (onSimulationEnd) { - console.log("here"); - onSimulationEnd(!simulator.current!.getPlayer().dead()); - } - return; - } - simulator.current!.step(); - setMapState(simulator.current!.getState()); - }, REPLAY_SPEED); - }; - - useEffect(() => { - if (autoStart) { - startSimulation(); - } - }, [autoStart]); - - useEffect(() => { - return () => { - if (interval.current) { - clearInterval(interval.current); - } - }; - }, []); - - return ( -
- {mapState.map((row, y) => ( -
- {row.map((cell, x) => ( -
- {cell} -
- ))} -
- ))} -
- - -
-
- ); -} diff --git a/app/header.tsx b/app/header.tsx index a10f60d..409798f 100644 --- a/app/header.tsx +++ b/app/header.tsx @@ -46,7 +46,7 @@ export default function Header() { {isAuthenticated && ( - + )} {flags?.showTestPage && ( diff --git a/app/maps/page.tsx b/app/maps/page.tsx index 82c329e..89d01df 100644 --- a/app/maps/page.tsx +++ b/app/maps/page.tsx @@ -43,8 +43,8 @@ export default function AddMapPage() { console.log("All set"); console.log(map); alert("No place left to place the player!"); - }else{ - createMap({grid: map}); + } else { + createMap({ grid: map }); alert("Map saved"); } }; @@ -60,7 +60,7 @@ export default function AddMapPage() { if (map[y][x] == "B") { cell = " "; } else { - cell = "B"; + cell = "R"; } } const newMap = map.map((row) => [...row]); @@ -68,7 +68,9 @@ export default function AddMapPage() { setMap(newMap); }; return ( -
+
+

Submit Map

+ {isSubmitted ? (
@@ -84,7 +86,7 @@ export default function AddMapPage() { variant={isZombie ? "outline" : "default"} onClick={() => setIsZombie(false)} > - Place Block + Place Rock