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 28, 2024
1 parent 40be68f commit eb9d912
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
21 changes: 15 additions & 6 deletions backend/gameStore.js
Original file line number Diff line number Diff line change
@@ -1,16 +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;
}

/**
*
* @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;
}
55 changes: 28 additions & 27 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
{
"name": "backend",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"lint": "eslint .",
"format": "prettier --check .",
"fix-format": "prettier --write .",
"test": "jest",
"start": "node src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mongoose": "^8.4.0"
},
"devDependencies": {
"eslint": "^8.57.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"supertest": "^7.0.0"
}
"name": "backend",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"lint": "eslint .",
"format": "prettier --check .",
"fix-format": "prettier --write .",
"test": "jest",
"start": "node src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mongoose": "^8.4.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"eslint": "^8.57.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"supertest": "^7.0.0"
}
}

0 comments on commit eb9d912

Please sign in to comment.