From 3acc5b8fa91a363985050a1936c1023e7c7cf5a5 Mon Sep 17 00:00:00 2001 From: avanimathur Date: Wed, 10 Jan 2024 10:23:02 +0530 Subject: [PATCH] Update Scoring System Based on Response Time Interval --- Dark/game.js | 20 +++++++++++++++----- Light/game.js | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Dark/game.js b/Dark/game.js index c9149ea..1ebebee 100644 --- a/Dark/game.js +++ b/Dark/game.js @@ -9,7 +9,6 @@ const time_line = document.querySelector(".time .time_line"); const timeText = document.querySelector(".timer .time_left_txt"); const timeCount = document.querySelector(".timer .timer_sec"); - var soundCorrect = new Audio("sounds/correctAns.mp3"); var soundIncorrect = new Audio("sounds/wrongAns.mp3"); var myMusic = new Audio("sounds/gametheme.mp3"); @@ -26,7 +25,6 @@ let widthValue = 0; let questions = []; - fetch( 'https://opentdb.com/api.php?amount=10&category=17&difficulty=easy&type=multiple' ) @@ -60,7 +58,7 @@ fetch( console.error(err); }); -//CONSTANTS +// CONSTANTS const CORRECT_BONUS = 10; const MAX_QUESTIONS = 10; @@ -124,8 +122,18 @@ choices.forEach((choice) => { clearInterval(counter); clearInterval(counterLine); + const timeRemaining = parseInt(timeCount.textContent); + if (classToApply === 'correct') { - incrementScore(CORRECT_BONUS); + let scoreToAdd = 0; + if (timeRemaining > 10 && timeRemaining <= 15) { + scoreToAdd = 10; + } else if (timeRemaining > 5 && timeRemaining <= 10) { + scoreToAdd = 5; + } else if (timeRemaining > 0 && timeRemaining <= 5) { + scoreToAdd = 2; + } + incrementScore(scoreToAdd); soundCorrect.play(); } else { soundIncorrect.play(); @@ -143,7 +151,8 @@ choices.forEach((choice) => { function startTimer(time) { counter = setInterval(timer, 1000); function timer() { - timeCount.textContent = time; time--; + timeCount.textContent = time; + time--; if (time < 9) { let addZero = timeCount.textContent; timeCount.textContent = "0" + addZero; @@ -183,6 +192,7 @@ incrementScore = (num) => { score += num; scoreText.innerText = score; }; + var count=0; function muteMe(elem) { elem.muted = true; diff --git a/Light/game.js b/Light/game.js index c9149ea..1ebebee 100644 --- a/Light/game.js +++ b/Light/game.js @@ -9,7 +9,6 @@ const time_line = document.querySelector(".time .time_line"); const timeText = document.querySelector(".timer .time_left_txt"); const timeCount = document.querySelector(".timer .timer_sec"); - var soundCorrect = new Audio("sounds/correctAns.mp3"); var soundIncorrect = new Audio("sounds/wrongAns.mp3"); var myMusic = new Audio("sounds/gametheme.mp3"); @@ -26,7 +25,6 @@ let widthValue = 0; let questions = []; - fetch( 'https://opentdb.com/api.php?amount=10&category=17&difficulty=easy&type=multiple' ) @@ -60,7 +58,7 @@ fetch( console.error(err); }); -//CONSTANTS +// CONSTANTS const CORRECT_BONUS = 10; const MAX_QUESTIONS = 10; @@ -124,8 +122,18 @@ choices.forEach((choice) => { clearInterval(counter); clearInterval(counterLine); + const timeRemaining = parseInt(timeCount.textContent); + if (classToApply === 'correct') { - incrementScore(CORRECT_BONUS); + let scoreToAdd = 0; + if (timeRemaining > 10 && timeRemaining <= 15) { + scoreToAdd = 10; + } else if (timeRemaining > 5 && timeRemaining <= 10) { + scoreToAdd = 5; + } else if (timeRemaining > 0 && timeRemaining <= 5) { + scoreToAdd = 2; + } + incrementScore(scoreToAdd); soundCorrect.play(); } else { soundIncorrect.play(); @@ -143,7 +151,8 @@ choices.forEach((choice) => { function startTimer(time) { counter = setInterval(timer, 1000); function timer() { - timeCount.textContent = time; time--; + timeCount.textContent = time; + time--; if (time < 9) { let addZero = timeCount.textContent; timeCount.textContent = "0" + addZero; @@ -183,6 +192,7 @@ incrementScore = (num) => { score += num; scoreText.innerText = score; }; + var count=0; function muteMe(elem) { elem.muted = true;