diff --git a/src/lib/config.js b/src/lib/config.js
index 04de99a..006b120 100644
--- a/src/lib/config.js
+++ b/src/lib/config.js
@@ -62,11 +62,13 @@ export let DefaultQuestions = [
name: "What should you do when you're free?",
answers: ["Do something in real life!", "Play video games", "Code!", "Touch grass!"],
correctAnswer: 2,
+ timeLimit: 30,
},
{
name: "Is RezHackXYZ the best programmer in the world?",
answers: ["Yes :)", "No :("],
correctAnswer: 0,
+ timeLimit: 5,
},
{
name: "Best place in the world?",
@@ -81,6 +83,7 @@ export let DefaultQuestions = [
"Twitter",
],
correctAnswer: 4,
+ timeLimit: 120,
},
];
diff --git a/src/routes/kahootclone/create/components/Questions/question.svelte b/src/routes/kahootclone/create/components/Questions/question.svelte
index 6472bc5..4a976a6 100644
--- a/src/routes/kahootclone/create/components/Questions/question.svelte
+++ b/src/routes/kahootclone/create/components/Questions/question.svelte
@@ -44,6 +44,20 @@
{/each}
+
diff --git a/src/routes/kahootclone/create/logic/GameCreateData.svelte.js b/src/routes/kahootclone/create/logic/GameCreateData.svelte.js
index 978ad8f..33a6316 100644
--- a/src/routes/kahootclone/create/logic/GameCreateData.svelte.js
+++ b/src/routes/kahootclone/create/logic/GameCreateData.svelte.js
@@ -9,6 +9,7 @@ export let questions = $state({
name: "",
answers: ["", "", "", ""],
correctAnswer: undefined,
+ timeLimit: 30,
},
],
});
@@ -22,6 +23,7 @@ export function AddQuestion() {
name: "",
answers: ["", "", "", ""],
correctAnswer: undefined,
+ timeLimit: 30,
});
}
diff --git a/src/routes/kahootclone/create/logic/InsertGameInDB.js b/src/routes/kahootclone/create/logic/InsertGameInDB.js
index 7f0824f..1c1be3c 100644
--- a/src/routes/kahootclone/create/logic/InsertGameInDB.js
+++ b/src/routes/kahootclone/create/logic/InsertGameInDB.js
@@ -20,6 +20,7 @@ export async function createGame(questions, gamePin) {
gameid: gamePin,
questionstext: q.name,
correctanswer: q.correctAnswer,
+ timelimit: q.timeLimit,
media: q.media || null,
}));
diff --git a/src/routes/kahootclone/host/components/DuringGame/display.svelte b/src/routes/kahootclone/host/components/DuringGame/display.svelte
index 9952173..92a5995 100644
--- a/src/routes/kahootclone/host/components/DuringGame/display.svelte
+++ b/src/routes/kahootclone/host/components/DuringGame/display.svelte
@@ -1,8 +1,10 @@
HOSTING
+
\ No newline at end of file
diff --git a/src/routes/kahootclone/host/components/DuringGame/timeLeft.svelte b/src/routes/kahootclone/host/components/DuringGame/timeLeft.svelte
new file mode 100644
index 0000000..147daaa
--- /dev/null
+++ b/src/routes/kahootclone/host/components/DuringGame/timeLeft.svelte
@@ -0,0 +1,15 @@
+
+
+{#if TotalTimeLeft.v != null}
+
+
{timeLeft.v}sec out of {TotalTimeLeft.v}secs is left
+
+
+{/if}
diff --git a/src/routes/kahootclone/host/logic/HostsData.svelte.js b/src/routes/kahootclone/host/logic/HostsData.svelte.js
index 82e4d56..32a0c5a 100644
--- a/src/routes/kahootclone/host/logic/HostsData.svelte.js
+++ b/src/routes/kahootclone/host/logic/HostsData.svelte.js
@@ -9,4 +9,7 @@ export let Totalplayers = $state({ v: 3 });
export let CurrentQuestionDetails = $state({ v: {} });
-export let gamePin = $state({ v: "" });
\ No newline at end of file
+export let gamePin = $state({ v: "" });
+
+export let timeLeft = $state({ v: 0 });
+export let TotalTimeLeft = $state({ v: 0 });
\ No newline at end of file
diff --git a/src/routes/kahootclone/host/logic/WaitForAwnser.js b/src/routes/kahootclone/host/logic/WaitForAwnser.js
index 7fd2e9a..760f189 100644
--- a/src/routes/kahootclone/host/logic/WaitForAwnser.js
+++ b/src/routes/kahootclone/host/logic/WaitForAwnser.js
@@ -1,12 +1,23 @@
import { supabase } from "$lib/supabase.js";
import { onNewPlayerAwnsered } from "./onNewPlayerAwnsered.js";
-import { currentQuestion, questions, CurrentQuestionDetails } from "./HostsData.svelte.js";
+import {
+ currentQuestion,
+ questions,
+ CurrentQuestionDetails,
+ TotalTimeLeft,
+ timeLeft,
+ PeopleAwnseredQ,
+ totalQuetions,
+} from "./HostsData.svelte.js";
+import { GameOver } from "./GameOver.js";
let WaitingForAwnserConection;
+let TimeLimitInterval;
export async function WaitForAwnser(questionid, gamePin) {
if (questionid != 0) {
await supabase.removeChannel(WaitingForAwnserConection);
+ clearInterval(TimeLimitInterval);
}
await supabase
@@ -48,5 +59,31 @@ export async function WaitForAwnser(questionid, gamePin) {
answers: answers.map((answer) => answer.content),
questionid: questionsData[currentQuestion.v].id,
media: questionsData[currentQuestion.v].media || null,
+ timeLimit: questionsData[currentQuestion.v].timelimit,
};
+
+ TotalTimeLeft.v = CurrentQuestionDetails.v.timeLimit;
+ timeLeft.v = CurrentQuestionDetails.v.timeLimit;
+ console.log("Time left:", timeLeft.v);
+ console.log("Total time left:", TotalTimeLeft.v);
+
+ if (TotalTimeLeft.v != null) {
+ TimeLimitInterval = setInterval(() => {
+ console.log("Time left:", timeLeft.v);
+ if (timeLeft.v > 0) {
+ timeLeft.v--;
+ console.log("Time left after decrement:", timeLeft.v);
+ } else {
+ supabase.removeChannel(WaitingForAwnserConection);
+ currentQuestion.v++;
+ if (currentQuestion.v == totalQuetions.v) {
+ //GameOver(gamePin);
+ return;
+ }
+ PeopleAwnseredQ.v = 0;
+
+ WaitForAwnser(currentQuestion.v, gamePin);
+ }
+ }, 1000);
+ }
}