diff --git a/pac-man-board-game/ClientApp/src/components/debugMenu.tsx b/pac-man-board-game/ClientApp/src/components/debugMenu.tsx index 3a25ea8..35d932e 100644 --- a/pac-man-board-game/ClientApp/src/components/debugMenu.tsx +++ b/pac-man-board-game/ClientApp/src/components/debugMenu.tsx @@ -33,15 +33,15 @@ const DebugOptions: FC = () => { sessionStorage.clear(); } - function resetMap() { + function restartGame(): void { // TODO } return (
-
- + {/*
*/} + {/**/}
) } diff --git a/pac-man-board-game/ClientApp/src/components/gameComponent.tsx b/pac-man-board-game/ClientApp/src/components/gameComponent.tsx index bf970d7..f87333a 100644 --- a/pac-man-board-game/ClientApp/src/components/gameComponent.tsx +++ b/pac-man-board-game/ClientApp/src/components/gameComponent.tsx @@ -10,29 +10,10 @@ import {diceAtom, ghostsAtom, playersAtom, rollDiceButtonAtom, selectedDiceAtom} import GameButton from "./gameButton"; import {Button} from "./button"; import {useNavigate, useParams} from "react-router-dom"; +import {getData} from "../utils/api"; const wsService = new WebSocketService(import.meta.env.VITE_API_WS); -// TODO bug, when taking player on last dice, the currentPlayer changes and the wrong character gets to steal -// TODO bug, first player can sometimes roll dice twice -// TODO bug, when refreshing page, some data is missing until other clients make a move -// TODO bug, stolen pellets are only updated on the client that stole them -// TODO bug, when navigating to lobby from the navbar while not logged in, the page is blank instead of redirecting to login -// TODO bug, when refreshing page, the player's button show ready, instead of roll dice or waiting - -// TODO spawns should be the same color as the player -// TODO better front page -// TODO smaller map to fit button and dice on screen -// TODO guest users -// TODO store map in backend and save it in state on each client -// TODO add debug menu on dev, for testing and cheating -// TODO sign up player page -// TODO show box with collected pellets -// TODO layout -// TODO end game when all pellets are eaten -// TODO store stats in backend -// TODO check if game exists on load, if not redirect to lobby - export const GameComponent: FC<{ player: Player, map: GameMap }> = ({player, map}) => { const players = useAtomValue(playersAtom); @@ -84,7 +65,7 @@ export const GameComponent: FC<{ player: Player, map: GameMap }> = ({player, map * Joins a game by sending a WebSocket request to the server. */ function joinGame(): void { - wsService.send({ // TODO if returns exception, navigate to lobby + wsService.send({ action: GameAction.joinGame, data: { username: player.username, @@ -117,10 +98,17 @@ export const GameComponent: FC<{ player: Player, map: GameMap }> = ({player, map } useEffect(() => { - wsService.onReceive = doAction; - wsService.open(); - wsService.waitForOpen().then(() => joinGame()); + getData(`/game/exists/${id}`) + .then(res => { + if (!res.ok) { + return navigate("/lobby"); + } + wsService.onReceive = doAction; + wsService.open(); + + wsService.waitForOpen().then(() => joinGame()); + }) return () => wsService.close(); }, []); diff --git a/pac-man-board-game/Controllers/GameController.cs b/pac-man-board-game/Controllers/GameController.cs index 4ca2ff2..c905ce4 100644 --- a/pac-man-board-game/Controllers/GameController.cs +++ b/pac-man-board-game/Controllers/GameController.cs @@ -51,6 +51,13 @@ public class GameController : GenericController } } + [HttpGet("exists/{gameId:guid}")] + public IActionResult GameExists(Guid gameId) + { + Logger.Log(LogLevel.Debug, "Checking if game {} exists", gameId); + return _gameService.Games.Any(game => game.Id == gameId) ? Ok() : NotFound(); + } + [HttpPost("create")] public IActionResult CreateGame([FromBody] CreateGameData data) {