diff --git a/clinet/src/pages/ChooseWords.js b/clinet/src/pages/ChooseWords.js
index fd02dcc..cdf1d48 100644
--- a/clinet/src/pages/ChooseWords.js
+++ b/clinet/src/pages/ChooseWords.js
@@ -24,6 +24,7 @@ function ChooseWords(props) {
function moveToDraw(word) {
let obj = {word : word.innerText , points : word.value}
let answer = Utils.setNextTurn(params.UserId , params.GameId , obj)
+ navigate('/'+params.UserId+'/'+params.GameId+'/Play')
}
diff --git a/clinet/src/pages/Guess.js b/clinet/src/pages/Guess.js
index 7a76a91..de0cb55 100644
--- a/clinet/src/pages/Guess.js
+++ b/clinet/src/pages/Guess.js
@@ -36,7 +36,7 @@ function Guess() {
},[])
useEffect(async () => {
- if(snapshot.Word.toUpperCase() == input.toUpperCase()){
+ if(snapshot.Word !== "" && snapshot.Word !== null && snapshot.Word.toUpperCase() === input.toUpperCase()){
await Utils.updateLastStep(params.UserId , params.GameId , {...snapshot , GuessState : "Done"})
}
} ,[input])
diff --git a/clinet/src/pages/Play.js b/clinet/src/pages/Play.js
index e100002..41b3cd4 100644
--- a/clinet/src/pages/Play.js
+++ b/clinet/src/pages/Play.js
@@ -21,31 +21,32 @@ function Play() {
})
useEffect(async () => {
- let answer = await Utils.getSnapshotLastStep(params.GameId)
- setSnapshot(answer)
+ // let answer = await Utils.getSnapshotLastStep(params.GameId)
+ // setSnapshot(answer)
} ,[])
useEffect(async () => {
- const interval = setInterval(async () => {
- let answer = await Utils.getSnapshotLastStep(params.GameId)
- setSnapshot(answer)
- } , 5000);
- return () => clearInterval(interval);
+
+ // const interval = setInterval(async () => {
+ // let answer = await Utils.getSnapshotLastStep(params.GameId)
+ // setSnapshot(answer)
+ // } , 5000);
+
+ // return () => clearInterval(interval);
},[])
useEffect(async () => {
await Utils.updateLastStep(params.UserId , params.GameId , snapshot)
+ if(snapshot.PaintingState == "Done" && snapshot.GuessState == "Done")
+ {
+ navigate('/'+params.UserId+'/'+params.GameId+'/WaitingRoom')
+ }
} ,[snapshot])
const finish = async () => {
await Utils.updateLastStep(params.UserId , params.GameId , {...snapshot , PaintingState : "Done"})
}
- if(snapshot.PaintingState == "Done" && snapshot.GuessState == "Done")
- {
- navigate('/'+params.UserId+'/'+params.GameId+'/WaitingRoom')
- }
-
return (
Draw
@@ -55,7 +56,9 @@ function Play() {
{setSnapshot({...snapshot , Canvas : e.getDataURL()})} } />
+ onChange={(e) => {
+ setSnapshot({...snapshot , Canvas : e.getDataURL()});
+ } } />
You need to draw :
{snapshot.Word}
diff --git a/clinet/src/pages/Utils/Utils.js b/clinet/src/pages/Utils/Utils.js
index 287230d..94b8791 100644
--- a/clinet/src/pages/Utils/Utils.js
+++ b/clinet/src/pages/Utils/Utils.js
@@ -17,17 +17,28 @@ const newGame = async (UserId) => {
return resp.data
}
-const updateLastStep = async (UserId , GameId , snapshot) => {
- let resp = await axios.put("http://localhost:8000/games/"+UserId+"/"+GameId+"/setLastStep" , snapshot)
+const updateGame = async (UserId , GameMongoId , Game) => {
+ let resp = await axios.put("http://localhost:8000/games/"+UserId+"/"+GameMongoId , Game)
return resp.data
}
-const updateGame = async (UserId , GameMongoId) => {
- let resp = await axios.put("http://localhost:8000/games/"+UserId+"/"+GameMongoId)
- return resp.data
+const updateLastStep = async (UserId , GameId , snapshot) => {
+
+ // let resp = await axios.get("http://localhost:8000/games/"+GameId);
+ // let game = resp.data[0]
+ // let index = game.Steps.length-1;
+ // game.Steps[index] = snapshot;
+
+ // let resp2 = await axios.put("http://localhost:8000/games/"+UserId+"/"+game._id , game)
+ // return resp2.data
+
+ // let resp = await axios.put("http://localhost:8000/games/"+UserId+"/"+GameId+"/updateLastStep" , game)
+ // return resp.data
}
+
const setNextTurn = async (UserId , GameId , word) => {
+
let resp = await axios.get("http://localhost:8000/games/"+GameId);
let game = {...resp.data[0]}
let newStep = {
@@ -40,7 +51,7 @@ const setNextTurn = async (UserId , GameId , word) => {
}
game.Steps.push(newStep)
- let resp2 = await axios.put("http://localhost:8000/games/"+UserId+"/"+game._id , game)
+ let resp2 = await axios.put("http://localhost:8000/games/"+UserId+"/"+game._id+"/setNextTurn" , game)
return resp2.data
}
diff --git a/clinet/src/pages/WaitingRoom.js b/clinet/src/pages/WaitingRoom.js
index c44e897..905720d 100644
--- a/clinet/src/pages/WaitingRoom.js
+++ b/clinet/src/pages/WaitingRoom.js
@@ -9,8 +9,26 @@ function WaitingRoom() {
const params = useParams();
const navigate = useNavigate();
- const goToDrawComp = () => {
- navigate('/'+params.UserId+'/'+params.GameId+'/Play')
+ const [snapshot , setSnapshot] = useState({
+ ActingUser: "" ,
+ Canvas: "" ,
+ GuessState: "" ,
+ PaintingState: "" ,
+ Points: 0 ,
+ Word: "" ,
+ _id: "" ,
+ })
+
+ useEffect(async () => {
+ const interval = setInterval(async () => {
+ let answer = await Utils.getSnapshotLastStep(params.GameId)
+ setSnapshot(answer)
+ } , 5000);
+ return () => clearInterval(interval);
+ },[])
+
+ if(snapshot.GuessState == "In_Progress"){
+ navigate('/'+params.UserId+'/'+params.GameId+'/Guess')
}
@@ -23,8 +41,6 @@ function WaitingRoom() {
Loading...
-
-
);
diff --git a/server/routes/api.js b/server/routes/api.js
index 8c2b1c4..2354a43 100644
--- a/server/routes/api.js
+++ b/server/routes/api.js
@@ -37,16 +37,28 @@ router.route('/:UserId/:GameMongoId').put(async (req, resp) => {
})
//Update lastStep
-router.route('/:UserId/:GameId'+'/setLastStep').put(async (req, resp) => {
+// router.route('/:UserId/:GameId'+'/updateLastStep').put(async (req, resp) => {
+
+// console.log(req.body)
+
+// // let answer = await gamesBL.gameByGameId(req.params.GameId);
+// // let game = answer[0]
+// // let steps = [...game.Steps];
+// // let indexLastStep = steps.length - 1;
+// // steps[indexLastStep] = updatedLastStep;
+// // game.Steps = steps;
+// // const GameMongoId = game._id;
+
+
+// // const answer2 = await gamesBL.updateGame(GameMongoId , game);
+// // return resp.json(answer2);
+// })
+
+// set Next Turn
+router.route('/:UserId/:GameId'+'/setNextTurn').put(async (req, resp) => {
const updatedLastStep = req.body;
- let answer = await gamesBL.gameByGameId(req.params.GameId);
- let game = answer[0]
- let steps = [...game.Steps];
- let indexLastStep = steps.length - 1;
- steps[indexLastStep] = updatedLastStep;
- game.Steps = steps;
- const GameMongoId = game._id;
- const answer2 = await gamesBL.updateGame(GameMongoId , game);
+ const GameMongoId = updatedLastStep._id;
+ const answer2 = await gamesBL.updateGame(GameMongoId , updatedLastStep);
return resp.json(answer2);
})