Merge pull request #8 from sorrelbri/patch_game_end_bug

patch game end bug
This commit is contained in:
Sorrel 2020-06-26 16:33:33 -07:00 committed by GitHub
commit ccbeddfa40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View file

@ -42,8 +42,8 @@ const Board = (props) => {
const posY = (i % boardSize) + 1; const posY = (i % boardSize) + 1;
const pointData = board[`${posX}-${posY}`]; const pointData = board[`${posX}-${posY}`];
const dotData = const dotData =
meta && meta.turn === 0 && !meta.winner meta && meta.turn === 0 && !meta.winner && meta.territory
? meta?.territory[`${posX}-${posY}`] ? meta.territory[`${posX}-${posY}`]
: game.turn || meta?.turn; : game.turn || meta?.turn;
boardPoints.push( boardPoints.push(
<Point <Point

View file

@ -80,14 +80,9 @@ function joinRequest(state, action) {
} }
function updateBoard(state, action) { function updateBoard(state, action) {
const { console.log(action.body);
gameRecord, const { gameRecord, pass, turn, winner, playerState } = action.body.meta;
pass, const territory = action.body.territory;
turn,
winner,
playerState,
territory,
} = action.body.meta;
return { return {
...state, ...state,
board: action.body.board, board: action.body.board,

View file

@ -103,12 +103,18 @@ io.on("connection", async (socket) => {
const { id, room } = game; const { id, room } = game;
const gameNsp = `game${id}`; const gameNsp = `game${id}`;
try { try {
const { board, ...meta } = await gameServices.toggleTerritory({ const {
board,
territory,
...meta
} = await gameServices.toggleTerritory({
id, id,
point, point,
}); });
socket.join(gameNsp, () => { socket.join(gameNsp, () => {
io.of(room).to(gameNsp).emit("update_board", { board, meta }); io.of(room)
.to(gameNsp)
.emit("update_board", { board, territory, meta });
}); });
} catch (e) { } catch (e) {
console.log(e); console.log(e);