node-go/packages/server/services/gameServices.js

33 lines
648 B
JavaScript
Raw Permalink Normal View History

const Game = require('./Game').Game;
const gamesInProgress = { }
const storeGame = (game) => {
gamesInProgress[game.id] = new Game(game);
}
const initGame = (game) => {
gamesInProgress[game.id] = new Game(game)
return gamesInProgress[game.id].initGame();
}
2020-01-31 06:50:34 +00:00
const makeMove = (game, move) => {
if (!gamesInProgress[game.id]) initGame(game);
const newState = gamesInProgress[game.id].makeMove(move);
return {...newState}
}
const getBoard = (gameId) => {
return gamesInProgress[gameId].getBoardState();
}
const getAllGames = () => {
return gamesInProgress;
}
module.exports = {
2020-01-31 06:50:34 +00:00
makeMove,
getAllGames,
getBoard,
initGame
}