replace MancalaGame to Game

This commit is contained in:
Halit Aksoy 2022-08-01 21:35:25 +03:00
parent b48aa0847e
commit 24560c0b1c
3 changed files with 13 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import { MancalaGame } from "mancala.js";
import fs from "fs"; import fs from "fs";
import { Game } from "../models/Game";
const crashFolder = "./crashes"; const crashFolder = "./crashes";
export class GameCrashManager { export class GameCrashManager {
constructor() {} constructor() {}
@ -22,7 +22,7 @@ export class GameCrashManager {
return `${year}-${month}-${date}-${hours}:${minutes}:${seconds}:${miliSeconds}`; return `${year}-${month}-${date}-${hours}:${minutes}:${seconds}:${miliSeconds}`;
} }
public static logGameCrash(error: Error, game: MancalaGame): string { public static logGameCrash(error: Error, game: Game): string {
this.createCrashFolderIfNotExist(); this.createCrashFolderIfNotExist();
const crash = { const crash = {
message: error.message, message: error.message,

View File

@ -1,15 +1,15 @@
import { MancalaGame } from "mancala.js"; import { Game } from "../../models/Game";
export interface GameStore { export interface GameStore {
get(id: string): MancalaGame | undefined; get(id: string): Game | undefined;
set(id: string, game: MancalaGame): void; set(id: string, game: Game): void;
remove(id: string): void; remove(id: string): void;
setGameIdByUser(userId: string, gameId: string): void; setGameIdByUser(userId: string, gameId: string): void;
getGameIdByUser(userId: string): string | undefined; getGameIdByUser(userId: string): string | undefined;
removeGameIdByPlayer(userId: string): void; removeGameIdByPlayer(userId: string): void;
setGameByUser(userId: string, game: MancalaGame): void; setGameByUser(userId: string, game: Game): void;
getGameByUser(userId: string): MancalaGame | undefined; getGameByUser(userId: string): Game | undefined;
removeGameByPlayer(userId: string): void; removeGameByPlayer(userId: string): void;
} }

View File

@ -1,14 +1,14 @@
import { MancalaGame } from "mancala.js"; import { Game } from "../../models/Game";
import { GameStore } from "./GameStore"; import { GameStore } from "./GameStore";
export class GameStoreImpl implements GameStore { export class GameStoreImpl implements GameStore {
gameStore: Map<string, MancalaGame> = new Map<string, MancalaGame>() gameStore: Map<string, Game> = new Map<string, Game>()
userGameMap: Map<string, string> = new Map<string, string>() userGameMap: Map<string, string> = new Map<string, string>()
get(id: string): MancalaGame | undefined { get(id: string): Game | undefined {
return this.gameStore.get(id); return this.gameStore.get(id);
} }
set(id: string, game: MancalaGame): void { set(id: string, game: Game): void {
this.gameStore.set(id, game); this.gameStore.set(id, game);
} }
remove(id: string): void { remove(id: string): void {
@ -25,10 +25,10 @@ export class GameStoreImpl implements GameStore {
this.userGameMap.delete(userId); this.userGameMap.delete(userId);
} }
setGameByUser(userId: string, game: MancalaGame): void { setGameByUser(userId: string, game: Game): void {
this.setGameIdByUser(userId, game.id); this.setGameIdByUser(userId, game.id);
} }
getGameByUser(userId: string): MancalaGame | undefined { getGameByUser(userId: string): Game | undefined {
const gameId = this.getGameIdByUser(userId); const gameId = this.getGameIdByUser(userId);
return gameId && this.gameStore.get(gameId) || undefined; return gameId && this.gameStore.get(gameId) || undefined;
} }