273 lines
11 KiB
Plaintext
273 lines
11 KiB
Plaintext
---
|
|
import Layout from "../../layouts/Layout.astro";
|
|
---
|
|
<Layout title="">
|
|
<!-- bg-[url('/assets/customBG.jpg')] bg-cover bg-center -->
|
|
<main>
|
|
<div class="">
|
|
<section class="bg-white bg-center bg-no-repeat bg-cover h-screen">
|
|
<div class="shadow-md">
|
|
<div class="container mx-auto px-4 flex flex-row place-content-between pt-6">
|
|
<div>
|
|
<img src="/assets/top_logo.png" alt="" draggable="false" class="select-none">
|
|
</div>
|
|
<div class="flex flex-row space-x-1 pb-2">
|
|
<button><img src="/assets/svg/mute.svg" alt=""></button>
|
|
<button><img src="/assets/svg/reset.svg" alt=""></button>
|
|
<button onclick="saveUserData();"><img src="/assets/svg/tick2.svg" alt=""></button>
|
|
<button><img src="/assets/svg/cancel.svg" alt=""></button>
|
|
</div>
|
|
</div>
|
|
<!-- <input onclick="saveUserData();" class="bg-blue-700 px-8 py-2 rounded-lg shadow-lg font-bold text-white cursor-pointer" type="submit" value="Submit"> -->
|
|
</div>
|
|
<div class="container mx-auto px-4">
|
|
<div class="flex flex-col">
|
|
<p class="sm:text-2xl md:text-3xl lg:text-4xl text-center font-[600] text-[#60C6CB] my-4 select-none" id="gameDescription"></p>
|
|
<!-- <p id="LearningSubArea"></p> -->
|
|
</div>
|
|
<div class="flex flex-col justify-center place-items-center ">
|
|
<img class="md:w-[80%] lg:w-[35%]" draggable="false" id="descImage" src="" alt="" />
|
|
<p class="text-2xl lg:text-4xl text-center font-[600] text-[#7c4c23] mb-0 select-none " id="gameLabel"></p>
|
|
</div>
|
|
<form id="contactForm" class="">
|
|
<div id="itemForm" class="">
|
|
<div class="flex flex-row gap-4 place-content-between">
|
|
<div class="flex flex-col place-items-center">
|
|
<label for="a1" class="round-checkbox-label">
|
|
<img id="image1" src="" alt="" draggable="false" class="select-none" />
|
|
<p id="label1"></p>
|
|
</label>
|
|
<input onclick="checkResult2('image1');" type="checkbox" id="a1" class="round-checkbox-input myCheckbox largerCheckbox" value="a1"/>
|
|
</div>
|
|
<div class="flex flex-col place-items-center">
|
|
<label for="a2" class="round-checkbox-label">
|
|
<img id="image2" src="" alt="" draggable="false" class="select-none" />
|
|
<p id="label2"></p>
|
|
</label>
|
|
<input onclick="checkResult2('image2');" type="checkbox" id="a2" class="round-checkbox-input myCheckbox largerCheckbox" value="a2"/>
|
|
</div>
|
|
<div class="flex flex-col place-items-center">
|
|
<label for="a3" class="round-checkbox-label">
|
|
<img id="image3" src="" alt="" draggable="false" class="select-none" />
|
|
<p id="label3"></p>
|
|
</label>
|
|
<input onclick="checkResult2('image3');" type="checkbox" id="a3" class="round-checkbox-input myCheckbox largerCheckbox" value="a3"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex flex-col place-items-center justify-center pt-4">
|
|
<p id="savedMessage"></p>
|
|
<!-- <input onclick="saveUserData();" class="bg-blue-700 px-8 py-2 rounded-lg shadow-lg font-bold text-white cursor-pointer" type="submit" value="Submit"> -->
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
</Layout>
|
|
<script is:inline>
|
|
const params = new URLSearchParams(window.location.search);
|
|
const gameId = params.get('id');
|
|
const userId = params.get('userid');
|
|
let startTime = Date.now();
|
|
let gameData = null;
|
|
|
|
fetch(`https://game-du.teachertrainingkolkata.in/items/game_cross_varient3/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
gameData = data.data;
|
|
// console.log(gameData)
|
|
document.getElementById("gameLabel").innerHTML = gameData.label;
|
|
document.getElementById("gameDescription").innerHTML = gameData.description;
|
|
if(gameData.label1, gameData.label2, gameData.label3){
|
|
document.getElementById("label1").innerHTML = gameData.label1;
|
|
document.getElementById("label2").innerHTML = gameData.label2;
|
|
document.getElementById("label3").innerHTML = gameData.label3;
|
|
}
|
|
// if(gameData.label1){
|
|
// document.getElementById("label1").innerHTML = gameData.label1;
|
|
// }
|
|
// if(gameData.label2){
|
|
// document.getElementById("label2").innerHTML = gameData.label2;
|
|
// }
|
|
// if(gameData.label3){
|
|
// document.getElementById("label3").innerHTML = gameData.label3;
|
|
// }
|
|
// document.getElementById('LearningArea').innerHTML = gameData.LearningArea;
|
|
// document.getElementById('LearningSubArea').innerHTML = gameData.LearningSubArea;
|
|
|
|
const assetsURL = 'https://game-du.teachertrainingkolkata.in/assets/';
|
|
document.getElementById('descImage').src = assetsURL + gameData.descript_img;
|
|
for (let i = 1; i <= 3; i++) {
|
|
const imageId = `image${i}`;
|
|
if(gameData[imageId]){
|
|
document.getElementById(imageId).src = assetsURL + gameData[imageId];
|
|
}
|
|
}
|
|
});
|
|
|
|
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('redBorder');
|
|
} else {
|
|
element.classList.add('greenBorder');
|
|
}
|
|
} else {
|
|
element.classList.remove('redBorder', 'greenBorder');
|
|
}
|
|
}
|
|
let url = window.location.href;
|
|
let urlSplit = url.split('/');
|
|
let gameName = urlSplit[3] + '-' + urlSplit[4];
|
|
|
|
function saveUserData() {
|
|
const endTime = Date.now();
|
|
const timeDifference = endTime - startTime;
|
|
const timeDifferenceInSeconds = timeDifference / 1000;
|
|
// Get checkbox values and corresponding elements
|
|
const checkboxes = ['a1', 'a2', 'a3'];
|
|
const checkboxValues = checkboxes.map(id => {
|
|
const checkbox = document.getElementById(id);
|
|
const element = document.getElementById('image' + id.slice(-1));
|
|
return {
|
|
id: id,
|
|
checked: checkbox.checked,
|
|
element: element
|
|
};
|
|
});
|
|
|
|
// Count points based on checkbox values and "greenBorder" class
|
|
let totalPoints = 0;
|
|
checkboxValues.forEach(checkbox => {
|
|
if (checkbox.checked && checkbox.element.classList.contains('redBorder')) {
|
|
totalPoints += 1;
|
|
}
|
|
});
|
|
|
|
let userData = {
|
|
'gameName': gameName,
|
|
'gameID': gameId,
|
|
'userId': userId,
|
|
'gameTime': timeDifferenceInSeconds,
|
|
'score': totalPoints,
|
|
};
|
|
// console.log(userData);
|
|
fetch(`https://phaser-game-api.s38.siliconpin.com/save-data`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(userData)
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
document.getElementById('savedMessage').innerHTML = 'Saved Successfully';
|
|
} else {
|
|
// console.log('Something Wrong', response);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('An error occurred', error);
|
|
});
|
|
}
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const contactForm = document.getElementById('contactForm');
|
|
contactForm.addEventListener('submit', async function (event) {
|
|
event.preventDefault();
|
|
});
|
|
});
|
|
</script>
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css2?family=Lobster&family=Quicksand:wght@500;700&display=swap');
|
|
input[type="checkbox"]{
|
|
-webkit-appearance: initial;
|
|
appearance: initial;
|
|
border: 1px solid gray;
|
|
border-radius: 5px;
|
|
/* background: gray; */
|
|
width: 40px;
|
|
height: 40px;
|
|
|
|
position: relative;
|
|
}
|
|
input[type="checkbox"]:checked {
|
|
background: #FF0000;
|
|
}
|
|
input[type="checkbox"]:checked:after {
|
|
border: none;
|
|
content: "X";
|
|
color: #fff;
|
|
position: absolute;
|
|
left: 50%;
|
|
top: 50%;
|
|
-webkit-transform: translate(-50%,-50%);
|
|
-moz-transform: translate(-50%,-50%);
|
|
-ms-transform: translate(-50%,-50%);
|
|
transform: translate(-50%,-50%);
|
|
/*
|
|
* If you want to fully change the check appearance, use the following:
|
|
* content: " ";
|
|
* width: 100%;
|
|
* height: 100%;
|
|
* background: blue;
|
|
* top: 0;
|
|
* left: 0;
|
|
*/
|
|
}
|
|
body{
|
|
font-family: Quicksand;
|
|
}
|
|
input.largerCheckbox {
|
|
/* width: 40px; */
|
|
height: 40px;
|
|
cursor: pointer;
|
|
}
|
|
.greenBorder{
|
|
border: 4px solid #008000;
|
|
border-radius: 10%;
|
|
transition: border 0.5s, border-color 0.3s, transform 6s;
|
|
}
|
|
.redBorder{
|
|
border: 4px solid red;
|
|
border-radius: 10%;
|
|
transition: border 0.5s, border-color 0.3s, transform 6s;
|
|
}
|
|
#image1, #image2, #image3, #image4, #image5, #image6{
|
|
width: 250px;
|
|
}
|
|
#label1, #label2, #label3, #label4, #label5, #label6{
|
|
text-align: center;
|
|
font-weight: bold;
|
|
color: #7C4C23;
|
|
padding-top: 10px;
|
|
}
|
|
#LearningArea, #LearningSubArea{
|
|
font-size: 20px;
|
|
color: #7C4C23;
|
|
font-weight: bold;
|
|
}
|
|
.round-checkbox-label {
|
|
display: inline-block;
|
|
cursor: pointer;
|
|
position: relative;
|
|
transition: background-color 0.3s, border-color 0.3s, transform 0.3s;
|
|
}
|
|
.round-checkbox-input:checked + .round-checkbox-label {
|
|
border-radius: 30%;
|
|
}
|
|
.round-checkbox-input:checked + .round-checkbox-label::after {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
font-size: 40px;
|
|
display: block;
|
|
}
|
|
</style>
|