Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #235 from Arquisoft/BugFixed
Browse files Browse the repository at this point in the history
Fixed some bugs
  • Loading branch information
RubenFern authored Apr 8, 2024
2 parents be193ed + c1df4ee commit d46d92d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
13 changes: 13 additions & 0 deletions game_service/game/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,26 @@ const next = async (req,res) => {
return;
}

let settings = await SettingsGameMode.findOne({
where: {
user_id: userId
}
});

if (settings == null) {
settings = await SettingsGameMode.create({
user_id: userId,
})
}

const questionRaw = await loadQuestion(game.tags.split(",").filter(s=>s.length > 0));

Question.create({
title: questionRaw.title,
imageUrl: questionRaw.imageUrl ? questionRaw.imageUrl : "",
answer: questionRaw.answer,
fake: questionRaw.fakes,
duration: settings.durationQuestion,
gameId: game.id
})

Expand Down
64 changes: 33 additions & 31 deletions webapp/src/components/game/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,38 @@ export const Game = () => {
if(botonIncorrecto !== null)
botonIncorrecto.className = "bg-red-700 w-full containedButton text-black dark:text-white font-mono";
}

if(!gameDone)
setTimeout(loadNextQuestion, 1000);
else
setTimeout(() =>
Swal.fire({
customClass: {
container: "bg-white dark:bg-dark-mode text-black dark:text-white ",
confirmButton: "text-black dark:text-white ",
cancelButton: "text-black dark:text-white " ,
},
title: "El juego ha finalizado!",
text: "Gracias por jugar",
imageUrl: bannerDark,
showCancelButton: true,
confirmButtonColor: "#f384f6",
cancelButtonColor: "#e8b260",
confirmButtonText: "Volver al menu principal",
cancelButtonText: "Continuar jugando"
}).then((result) => {
if (result.isConfirmed) {
navigate("/home")
}else {
window.location.reload(false);

setGameDone(gameDone => {
if(!gameDone)
setTimeout(loadNextQuestion, 1000);
else {
setTime(undefined);
setTimeout(() =>
Swal.fire({
customClass: {
container: "bg-white dark:bg-dark-mode text-black dark:text-white ",
confirmButton: "text-black dark:text-white ",
cancelButton: "text-black dark:text-white " ,
},
title: "El juego ha finalizado!",
text: "Gracias por jugar",
imageUrl: bannerDark,
showCancelButton: true,
confirmButtonColor: "#f384f6",
cancelButtonColor: "#e8b260",
confirmButtonText: "Volver al menu principal",
cancelButtonText: "Continuar jugando"
}).then((result) => {
if (result.isConfirmed) {
navigate("/home")
}else {
window.location.reload(false);
}
}
}
), 1000);
), 1000);
}
return gameDone;
});
})
};

Expand Down Expand Up @@ -100,8 +105,7 @@ export const Game = () => {
useEffect(() => {
let interval = setInterval(() => {
setTime(time => {
setGameDone(gameDone => {
if(time !== undefined && !gameDone){
if(time !== undefined){
let total = basicGameSetting.durationQuestion * 1000;
let trans = (new Date().getTime()) - time.start;

Expand All @@ -115,8 +119,6 @@ export const Game = () => {
time = undefined;
}
}
return gameDone
});
return time;
});
}, 20);
Expand Down Expand Up @@ -180,7 +182,7 @@ export const Game = () => {
className="text-black dark:text-white bg-cyan-200 dark:bg-purple-700"
>
<Typography data-testid="counter" variant="h2" component="h2" className="text-black dark:text-white " >
{ Number(remTime/10).toFixed(0) }
{ Math.min(Math.max(Number(remTime/10).toFixed(0),0),10) }
</Typography>
</Box>
<Typography fontFamily="monospace" component="h1" variant="h5" className="text-black dark:text-white "
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/components/home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const Home = () =>
component="main"
maxWidth="md"
sx={{ display: "flex", flexDirection: "row", alignItems: "center", justifyContent: "center", minHeight: "85vh", backgroundColor:"rgb(23 23 23 / var(--tw-bg-opacity))"}}
className="min-h-screen flex justify-center place-content-between"
className="bg-teal-50 dark:bg-zinc-800 min-h-screen flex justify-center place-content-between rounded-lg flex"
>
<Container
className="bg-teal-50 dark:bg-zinc-800 rounded-lg flex "
Expand Down Expand Up @@ -178,12 +178,12 @@ export const Home = () =>
<div id="tagBox">
{tags.map((tag) =>
<Chip
className="tagChip"
className="tagChip text-black dark:text-white"
key={tag.name}
onClick={(e) => toggleTag(e, tag)}
variant="outlined"
label={tag.name}
data-active="true"
data-active={tag.active}

>
</Chip>
Expand Down

0 comments on commit d46d92d

Please sign in to comment.