Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gameStore: Added functions to add and retrieve games #12

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions backend/gameStore.js

This file was deleted.

25 changes: 25 additions & 0 deletions backend/gameStore.ts
Original file line number Diff line number Diff line change
@@ -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<string, GameEngine> = 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;
}
4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions backend/uno-game-engine/deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default function getShuffledCardDeck(): Array<UNOCard> {
// deck.push(makeCard('special', 'wild', 'wild'))
// deck.push(makeCard('number', 'red', '0'))

shuffle(deck);;
return deck;;
shuffle(deck);
return deck;
}

/**
Expand All @@ -68,4 +68,3 @@ function shuffle(deck: Array<any>) {
//todo: Implement a generic shuffling algorithm
[deck[0], deck[1]] = [deck[1], deck[0]];
}

Loading