node-go/server/services/gameServices.js
2020-01-30 22:50:34 -08:00

33 lines
No EOL
613 B
JavaScript

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();
}
const makeMove = (game, move) => {
let meta = {};
const board = gamesInProgress[game.id].makeMove(move);
return {board, meta}
}
const getBoard = (gameId) => {
return gamesInProgress[gameId].getBoardState();
}
const getAllGames = () => {
return gamesInProgress;
}
module.exports = {
makeMove,
getAllGames,
getBoard,
initGame
}