aboutsummaryrefslogtreecommitdiff
path: root/src/components/MultiplayerGrid.js
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-31 20:06:30 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-31 20:06:30 +0530
commitd43fa3768c5e9eee06c0af3b093c84aa38aedbf8 (patch)
treec598b63440e7be8e56008947e6a225507063e483 /src/components/MultiplayerGrid.js
parentb353dda4df7fc7be973e52a2f529360e7bfc8fed (diff)
Added basic rooms support
Diffstat (limited to 'src/components/MultiplayerGrid.js')
-rw-r--r--src/components/MultiplayerGrid.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/components/MultiplayerGrid.js b/src/components/MultiplayerGrid.js
index 88a8259..3db9dc6 100644
--- a/src/components/MultiplayerGrid.js
+++ b/src/components/MultiplayerGrid.js
@@ -28,9 +28,19 @@ const MultiplayerGrid = (props) => {
const [board, setBoard] = useState([2,2,2,2,2,2,2,2,2]);
const turn = props.turn;
+ const isHost = props.isHost;
+ useEffect(() => {
+ if (isHost) {
+ socket.emit("host");
+ socket.on("set-host-id", (id) => alert(id));
+ } else {
+ socket.emit("join", prompt("Enter ID"));
+ }
+ }, [isHost]);
+
const getBoard = (index) => {
// if it's not your turn you can't play
- if ((turn === 0) === props.isHost) return;
+ if ((turn === 0) === isHost) return;
const newBoard = board.slice(0, index).concat(turn).concat(board.slice(index+1, 9));
socket.emit("update-remote-data", {