aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-01 02:34:59 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-01 02:34:59 +0530
commitb8babd592b60b1a2cfedac3956184207a3d4bb8d (patch)
tree3aa3f708e3f3c6b7d804ecdc53c4fce755853c91 /src
parent1a40b90e29dc61ed28ad251b49e9175a2215c3d0 (diff)
created menu entry to enter join code
Diffstat (limited to 'src')
-rw-r--r--src/components/App.js3
-rw-r--r--src/components/GamemodeChooser.js1
-rw-r--r--src/components/MultiplayerGrid.js5
-rw-r--r--src/components/MultiplayerMenu.js45
-rw-r--r--src/server/index.js8
5 files changed, 46 insertions, 16 deletions
diff --git a/src/components/App.js b/src/components/App.js
index db5af1b..5b13230 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -33,6 +33,7 @@ const App = () => {
const [showMessageBox, setShowMessageBox] = useState(false);
const [message, setMessage] = useState("");
const [isHost, setIsHost] = useState(false);
+ const [joinCode, setJoinCode] = useState();
return gameStarted ? (
<>
@@ -61,6 +62,7 @@ const App = () => {
setScoreO={setScoreO}
setMessage={setMessage}
setShowMessage={setShowMessageBox}
+ joinCode={joinCode}
/> : <Grid
turn={turn}
setTurn={setTurn}
@@ -81,6 +83,7 @@ const App = () => {
setMultiplayer={setMultiplayer}
setGameStarted={setGameStarted}
setIsHost={setIsHost}
+ setJoinCode={setJoinCode}
/>
<Footer/>
</>
diff --git a/src/components/GamemodeChooser.js b/src/components/GamemodeChooser.js
index 91010e4..6b2e985 100644
--- a/src/components/GamemodeChooser.js
+++ b/src/components/GamemodeChooser.js
@@ -47,6 +47,7 @@ const GamemodeChooser = (props) => {
<MultiplayerMenu
setIsHost={props.setIsHost}
setGameStarted={props.setGameStarted}
+ setJoinCode={props.setJoinCode}
/>
<div className={"GamemodeButton"} onClick={() => {
diff --git a/src/components/MultiplayerGrid.js b/src/components/MultiplayerGrid.js
index 7c00f17..d7eae36 100644
--- a/src/components/MultiplayerGrid.js
+++ b/src/components/MultiplayerGrid.js
@@ -29,6 +29,7 @@ const MultiplayerGrid = (props) => {
const turn = props.turn;
const isHost = props.isHost;
+ const joinCode = props.joinCode;
const setMessage = props.setMessage;
const setShowMessage = props.setShowMessage;
@@ -48,7 +49,7 @@ const MultiplayerGrid = (props) => {
setTimeout(() => setShowMessage(false), 3000)
})
} else {
- socket.emit("join", prompt("Enter ID"));
+ socket.emit("join", joinCode);
// error if room doesn't exist
socket.on("join failed", () => {
@@ -57,7 +58,7 @@ const MultiplayerGrid = (props) => {
setTimeout(() => window.location.reload(), 3000)
});
}
- }, [isHost, setMessage, setShowMessage]);
+ }, [isHost, setMessage, setShowMessage, joinCode]);
const getBoard = (index) => {
// if it's not your turn you can't play
diff --git a/src/components/MultiplayerMenu.js b/src/components/MultiplayerMenu.js
index 1dfe9dd..aa77507 100644
--- a/src/components/MultiplayerMenu.js
+++ b/src/components/MultiplayerMenu.js
@@ -15,24 +15,45 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import React from 'react';
+import React, { useState } from 'react';
import './style.css';
const MultiplayerMenu = (props) => {
+ const [showCodeInput, setShowCodeInput] = useState(false)
+ const [joinCode, setJoinCode] = useState("");
+
return (
<div className={"MultiplayerMenu"}>
- <div className={"GamemodeButton"} onClick={() => {
- props.setIsHost(true);
- props.setGameStarted(true);
- }}>
- HOST GAME
- </div>
+ {showCodeInput
+ ? <>
+ <input type="text" placeholder={"ENTER CODE"}
+ className={"GamemodeButton"} onChange={
+ (event) => setJoinCode(event.target.value)
+ }
+ />
+
+ <div className={"GamemodeButton"} onClick={() => {
+ props.setGameStarted(true);
+ props.setJoinCode(joinCode);
+ }}>
+ START
+ </div>
+ </>
+ : <>
+ <div className={"GamemodeButton"} onClick={() => {
+ props.setIsHost(true);
+ props.setGameStarted(true);
+ }}>
+ HOST GAME
+ </div>
- <div className={"GamemodeButton"} onClick={() => {
- props.setGameStarted(true);
- }}>
- JOIN GAME
- </div>
+ <div className={"GamemodeButton"} onClick={() => {
+ setShowCodeInput(true);
+ }}>
+ JOIN GAME
+ </div>
+ </>
+ }
</div>
);
}
diff --git a/src/server/index.js b/src/server/index.js
index 5eeff99..a5aa97f 100644
--- a/src/server/index.js
+++ b/src/server/index.js
@@ -3,10 +3,14 @@ const app = express();
const http = require('http').Server(app);
const path = require('path');
-// const io = require('socket.io')(http);
const io = require("socket.io")(http, {
cors: {
- origin: ["http://localhost:5000", "http://localhost:3000"],
+ origin: [
+ "http://localhost:5000",
+ "http://localhost:3000",
+ "https://mikunonaka-tic-tac-toe.herokuapp.com",
+ "http://mikunonaka-tic-tac-toe.herokuapp.com"
+ ],
"Access-Control-Allow-Origin": "*",
methods: ["GET", "POST"]
}