diff --git a/backend/gameStore.js b/backend/gameStore.js deleted file mode 100644 index a1d417c..0000000 --- a/backend/gameStore.js +++ /dev/null @@ -1,17 +0,0 @@ -// This module is responsible for setting and retrieving the game state. -import { GameEngine } from './uno-game-engine/engine'; -const games = map(); - -export function createGame() { - //todo: generate a unique game id and store -} - -/** - * Retrieves a game from the store using its id. - * - * @param {string} id Game id - * @returns {GameEngine|null} GameEngine instance - */ -export function retrieveGame(id) { - //todo: Retrieve the game from the store -} diff --git a/backend/gameStore.ts b/backend/gameStore.ts new file mode 100644 index 0000000..a40035e --- /dev/null +++ b/backend/gameStore.ts @@ -0,0 +1,25 @@ +// This module is responsible for setting and retrieving the game state. +import { v4 as uuid } from 'uuid'; + +import { GameEngine } from './uno-game-engine/engine'; +const games: Map = new Map(); + +/** + * Create a new game and store it in the games map + * @returns {string} gameId + */ +export function createGame() { + const gameId = uuid(); + const game = new GameEngine(); + games.set(gameId, game); + return gameId; +} + +/** + * Retrieve a game from the games map + * @param {string} id gameId + * @returns {GameEngine|null} GameEngine instance + */ +export function retrieveGame(id: string) { + return games.get(id) || null; +} diff --git a/backend/package.json b/backend/package.json index 156bcde..4aa7bdd 100644 --- a/backend/package.json +++ b/backend/package.json @@ -16,12 +16,14 @@ "description": "", "dependencies": { "@types/node": "^20.12.13", + "@types/uuid": "^9.0.8", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", "mongoose": "^8.4.0", "ts-node": "^10.9.2", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "uuid": "^9.0.1" }, "devDependencies": { "@types/cors": "^2.8.17", diff --git a/backend/uno-game-engine/deck.ts b/backend/uno-game-engine/deck.ts index dfc31f1..6d10732 100644 --- a/backend/uno-game-engine/deck.ts +++ b/backend/uno-game-engine/deck.ts @@ -47,8 +47,8 @@ export default function getShuffledCardDeck(): Array { // deck.push(makeCard('special', 'wild', 'wild')) // deck.push(makeCard('number', 'red', '0')) - shuffle(deck);; - return deck;; + shuffle(deck); + return deck; } /** @@ -68,4 +68,3 @@ function shuffle(deck: Array) { //todo: Implement a generic shuffling algorithm [deck[0], deck[1]] = [deck[1], deck[0]]; } -