diff --git a/pac-man-board-game/ClientApp/src/components/gameComponent.tsx b/pac-man-board-game/ClientApp/src/components/gameComponent.tsx index 1b84dfe..876272f 100644 --- a/pac-man-board-game/ClientApp/src/components/gameComponent.tsx +++ b/pac-man-board-game/ClientApp/src/components/gameComponent.tsx @@ -17,6 +17,7 @@ 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 guest users // TODO protected routes? checking if user is logged in diff --git a/pac-man-board-game/ClientApp/src/game/box.ts b/pac-man-board-game/ClientApp/src/game/box.ts index 218c250..0d0caf8 100644 --- a/pac-man-board-game/ClientApp/src/game/box.ts +++ b/pac-man-board-game/ClientApp/src/game/box.ts @@ -1,9 +1,8 @@ import Pellet from "./pellet"; -import {Colour} from "./colour"; -export default class Box { - public pellets: Pellet[]; - public readonly colour: Colour; +export default class Box implements BoxProps { + public pellets; + public readonly colour; public constructor({colour, pellets = []}: BoxProps) { this.colour = colour; diff --git a/pac-man-board-game/ClientApp/src/game/character.ts b/pac-man-board-game/ClientApp/src/game/character.ts index 4595692..9855618 100644 --- a/pac-man-board-game/ClientApp/src/game/character.ts +++ b/pac-man-board-game/ClientApp/src/game/character.ts @@ -7,12 +7,12 @@ export enum CharacterType { dummy, } -export class Character { - public readonly colour: Colour; - public position: Path | null; - public isEatable: boolean; - public readonly spawnPosition: DirectionalPosition | null; - public readonly type: CharacterType; +export class Character implements CharacterProps { + public readonly colour; + public position; + public isEatable; + public readonly spawnPosition; + public readonly type; public constructor( { @@ -66,7 +66,7 @@ export class Character { } } -export class PacMan extends Character { +export class PacMan extends Character implements CharacterProps { public constructor({colour, position, isEatable = true, spawnPosition, type = CharacterType.pacMan}: CharacterProps) { super({colour: colour, position: position, isEatable: isEatable, spawnPosition: spawnPosition, type: type}); @@ -74,14 +74,14 @@ export class PacMan extends Character { } -export class Ghost extends Character { +export class Ghost extends Character implements CharacterProps { public constructor({colour, position, isEatable, spawnPosition, type = CharacterType.ghost}: CharacterProps) { super({colour: colour, position: position, isEatable: isEatable, spawnPosition: spawnPosition, type: type}); } } -export class Dummy extends Character { +export class Dummy extends Character implements CharacterProps { public constructor(position: Path) { // TODO see-through super({ diff --git a/pac-man-board-game/ClientApp/src/game/player.ts b/pac-man-board-game/ClientApp/src/game/player.ts index defba62..cc7fed8 100644 --- a/pac-man-board-game/ClientApp/src/game/player.ts +++ b/pac-man-board-game/ClientApp/src/game/player.ts @@ -1,6 +1,5 @@ import {Character, CharacterType} from "./character"; import Box from "./box"; -import {Colour} from "./colour"; import {getDefaultStore} from "jotai"; import {currentPlayerNameAtom, playersAtom} from "../utils/state"; import Pellet from "./pellet"; @@ -13,12 +12,13 @@ export enum State { disconnected } -export default class Player { - public readonly username: string; - public readonly pacMan: Character; - public readonly colour: Colour; - public readonly box: Box; - public state: State; +export default class Player implements PlayerProps { + private static store = getDefaultStore(); + public readonly username; + public readonly pacMan; + public readonly colour; + public readonly box; + public state; constructor(props: PlayerProps) { this.username = props.username; @@ -32,8 +32,7 @@ export default class Player { } public isTurn(): boolean { - const store = getDefaultStore(); - return store.get(currentPlayerNameAtom) === this.username; + return Player.store.get(currentPlayerNameAtom) === this.username; } public addPellet(pellet: Pellet): void { @@ -46,8 +45,7 @@ export default class Player { if (pellet) this.box.addPellet(pellet); } - const store = getDefaultStore(); - store.set(playersAtom, store.get(playersAtom).map(player => player)); + Player.store.set(playersAtom, Player.store.get(playersAtom).map(player => player)); } }