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 pointData = board[`${posX}-${posY}`];
const dotData =
meta && meta.turn === 0 && !meta.winner
? meta?.territory[`${posX}-${posY}`]
meta && meta.turn === 0 && !meta.winner && meta.territory
? meta.territory[`${posX}-${posY}`]
: game.turn || meta?.turn;
boardPoints.push(
<Point

View file

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

View file

@ -103,12 +103,18 @@ io.on("connection", async (socket) => {
const { id, room } = game;
const gameNsp = `game${id}`;
try {
const { board, ...meta } = await gameServices.toggleTerritory({
const {
board,
territory,
...meta
} = await gameServices.toggleTerritory({
id,
point,
});
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) {
console.log(e);