This commit is contained in:
Suvodip
2025-01-26 13:45:25 +05:30
parent f15a4b3b27
commit 54f2c9f06e
11 changed files with 247 additions and 177 deletions

View File

@@ -152,15 +152,15 @@ import Layout from "../../layouts/Layout.astro";
let urlSplit = url.split('/');
// let gameName = urlSplit[3] + '-' + urlSplit[4].split('?')[0];
let wrongCount = 0;
let starValue;
let maxScore = 6;
let progress = 0;
const progressBar = document.createElement('div');
let totalCorrectFromApi = 0;
fetch(`https://game-du.teachertrainingkolkata.in/items/game_tick_variant1/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
.then(res => res.json())
.then(data => {
gameData = data.data;
gameData = data.data;
// console.log('totalCorrectFromApi', totalCorrectFromApi) gameData
let audioLink = `https://game-du.teachertrainingkolkata.in/assets/${gameData.instruction}.mp3`;
document.getElementById('instrucAudio1').src = audioLink;
document.getElementById('instrucAudio2').src = audioLink;
@@ -236,7 +236,6 @@ import Layout from "../../layouts/Layout.astro";
function checkResult2(id) {
const checkbox = document.getElementById('a' + id.slice(-1));
const element = document.getElementById(id);
if (checkbox.checked) {
if (gameData[id.replace('image', 'a')] === true) {
element.classList.add('greenBorder');
@@ -285,16 +284,27 @@ import Layout from "../../layouts/Layout.astro";
totalPoints += 1;
}
});
let starValue = Math.round((totalPoints / maxScore) * 10);
starValue = starValue === 0 ? 3 : starValue;
// console.log('totalCorrectFromApi', gameData);
const answersList = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6'];
answersList.forEach((answer) => {
if (gameData[answer] === true) {
totalCorrectFromApi++;
}
});
let afterNegative = totalPoints - wrongCount;
let percentage = Math.round((afterNegative / totalCorrectFromApi ) * 10);
if(percentage <= 3){
percentage = 3
}
let feedbackMessage = '';
if (starValue >= 1 && starValue <= 3) {
if (percentage >= 1 && percentage <= 3) {
feedbackMessage = "You're making progress! Let's keep going!";
} else if (starValue >= 4 && starValue <= 6) {
} else if (percentage >= 4 && percentage <= 6) {
feedbackMessage = "Nice work! You're improving every day!";
} else if (starValue >= 7 && starValue <= 8) {
} else if (percentage >= 7 && percentage <= 8) {
feedbackMessage = "Amazing work! Keep it up!";
} else if (starValue >= 9 && starValue <= 10) {
} else if (percentage >= 9 && percentage <= 10) {
feedbackMessage = "Outstanding! You're a true superstar!";
} else {
feedbackMessage = "Invalid star value.";
@@ -412,7 +422,7 @@ import Layout from "../../layouts/Layout.astro";
'userId': userId,
'gameTime': timeDifferenceInSeconds,
'score': totalPoints,
'gameStar': starValue
'gameStar': percentage
};
fetch(`https://api.teachertrainingkolkata.in/api/saveGameScore2`, {
method: 'POST',
@@ -432,7 +442,7 @@ import Layout from "../../layouts/Layout.astro";
starContainer.style.display = 'flex';
starContainer.style.flexDirection = 'row';
document.getElementById('starFeedbackMessage').innerHTML = feedbackMessage;
document.getElementById('get-star-value').innerHTML = starValue;
document.getElementById('get-star-value').innerHTML = percentage;
scoreBoard.style.display = 'flex';
}
} else {