Skip to content

Commit

Permalink
gameStore: Added functions to add and retrieve games
Browse files Browse the repository at this point in the history
Implemented the createGame function which creates a new game, generates
it's id and adds it the the games map.

Also added the retrieveGame function which retrieves a game, given it's
id.

Also added the uuid package to generate unique ids for games.

Fixes #5

Signed-off-by: Sagnik Mandal <[email protected]>
  • Loading branch information
criticic committed May 30, 2024
1 parent df8d243 commit c5bfd63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 15 additions & 7 deletions backend/gameStore.js
Original file line number Diff line number Diff line change
@@ -1,17 +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();
const games = new Map();

/**
* Create a new game and store it in the games map
* @returns {string} gameId
*/
export function createGame() {
//todo: generate a unique game id and store
const gameId = uuid();
const game = new GameEngine();
games.set(gameId, game);
return gameId;
}

/**
* Retrieves a game from the store using its id.
*
* @param {string} id Game id
* Retrieve a game from the games map
* @param {string} id gameId
* @returns {GameEngine|null} GameEngine instance
*/
export function retrieveGame(id) {
//todo: Retrieve the game from the store
}
return games.get(id) || null;
}
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"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",
Expand Down

0 comments on commit c5bfd63

Please sign in to comment.