aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/Grid.js4
-rw-r--r--src/components/MultiplayerGrid.js5
-rw-r--r--src/server/index.js2
3 files changed, 4 insertions, 7 deletions
diff --git a/src/components/Grid.js b/src/components/Grid.js
index 289f142..c10b0aa 100644
--- a/src/components/Grid.js
+++ b/src/components/Grid.js
@@ -49,13 +49,13 @@ const Grid = (props) => {
const endGame = (winner) => {
const gameWinner = winner < 2 ? (winner === 1 ? "X" : "O") : "Draw";
- props.setMessage(`WINNER: ${gameWinner}`);
+ props.setMessage(`${gameWinner === "Draw" ? "" : "WINNER: "}${gameWinner}`);
props.setShowMessage(true);
gameWinner === "Draw" || (gameWinner === "X"
? props.setScoreX(props.scoreX + 1)
: props.setScoreO(props.scoreO + 1));
setBoard([2,2,2,2,2,2,2,2,2]);
- winner < 2 && props.setTurn(winner); // set turn to prev. winner
+ // winner < 2 && props.setTurn(winner); // set turn to prev. winner
}
useEffect(() => {
diff --git a/src/components/MultiplayerGrid.js b/src/components/MultiplayerGrid.js
index d7eae36..7cd3835 100644
--- a/src/components/MultiplayerGrid.js
+++ b/src/components/MultiplayerGrid.js
@@ -75,16 +75,13 @@ const MultiplayerGrid = (props) => {
const endGame = (data) => {
setMessage(
- `${data.winner === "Data" ? "" : "WINNER: "}${data.winner}`
+ `${data.winner === "Draw" ? "" : "WINNER: "}${data.winner}`
);
setShowMessage(true);
props.setScoreX(data.scoreX);
props.setScoreO(data.scoreO);
- // socket.emit messes everything up
- // and this does the job very well
setBoard([2,2,2,2,2,2,2,2,2]);
- props.setTurn(data.winner === "Draw" ? turn : (data.winner === "X" ? 1 : 0));
}
useEffect(() => {
diff --git a/src/server/index.js b/src/server/index.js
index a5aa97f..004c989 100644
--- a/src/server/index.js
+++ b/src/server/index.js
@@ -89,7 +89,7 @@ io.on('connection', (socket) => {
const score = getScore(winner, data.scoreX, data.scoreO, data.board)
io.to(room).emit('update-client-data', {
board: data.board,
- turn: score.winner ? data.turn : (data.turn === 0 ? 1 : 0),
+ turn: (data.turn === 0 ? 1 : 0),
score: score
});