-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gameStore: Added functions to add and retrieve games
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
Showing
2 changed files
with
43 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |