mancala/src/game/gamestore/GameStoreImpl.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-07-15 21:42:38 +03:00
import { MancalaGame } from "mancala.js";
import { GameStore } from "./GameStore";
export class GameStoreImpl implements GameStore {
gameStore: Map<string, MancalaGame> = new Map<string, MancalaGame>()
userGameMap: Map<string, string> = new Map<string, string>()
2022-07-15 21:42:38 +03:00
get(id: string): MancalaGame | undefined {
return this.gameStore.get(id);
}
set(id: string, game: MancalaGame): void {
this.gameStore.set(id, game);
}
remove(id: string): void {
this.gameStore.delete(id);
}
setGameIdByUser(userId: string, gameId: string): void {
this.userGameMap.set(userId, gameId)
}
getGameIdByUser(userId: string): string | undefined {
return this.userGameMap.get(userId);
}
removeGameIdByPlayer(userId: string): void {
this.userGameMap.delete(userId);
}
setGameByUser(userId: string, game: MancalaGame): void {
this.setGameIdByUser(userId, game.id);
}
getGameByUser(userId: string): MancalaGame | undefined {
const gameId = this.getGameIdByUser(userId);
return gameId && this.gameStore.get(gameId) || undefined;
}
removeGameByPlayer(userId: string): void {
this.removeGameIdByPlayer(userId);
}
2022-07-15 21:42:38 +03:00
}