From 15b8c1e803d988d20d92a15398432e8220157c90 Mon Sep 17 00:00:00 2001 From: dev sp Date: Thu, 18 Jan 2024 13:37:13 +0000 Subject: [PATCH] add score calculation in drag all games all varient --- src/pages/drag/index.astro | 101 +++++++----------------- src/pages/drag/v2.astro | 156 +++++++------------------------------ src/pages/drag/v3.astro | 63 +++++++-------- src/pages/drag/v4.astro | 47 ++++++----- 4 files changed, 102 insertions(+), 265 deletions(-) diff --git a/src/pages/drag/index.astro b/src/pages/drag/index.astro index eb59e3a..aefc90a 100644 --- a/src/pages/drag/index.astro +++ b/src/pages/drag/index.astro @@ -75,6 +75,8 @@ import Layout from '../../layouts/Layout.astro'; let submitButton; let formattedDateTime; let shortUniqueID; + let scoreTotal = 0; + let resultView; gameResult = []; window.onload = function() { // Get the current date and time @@ -505,6 +507,30 @@ import Layout from '../../layouts/Layout.astro'; retryButton.setInteractive().on('pointerdown', () => { window.location.reload(); }) + let score = 0; + let counter = 0; + const isMatch = (blockName, targetName) => { + if(isMatch){ + counter++; + // console.log(counter) + } + const match = blockMatches.find((m) => m.blockName === blockName && m.targetName === targetName); + console.log(match) + if(match !== undefined){ + scoreTotal++; + console.log("Score Total", scoreTotal) + resultView = this.add.text(window.innerWidth / 2 - 100, window.innerHeight / 2 - 100, `Your Score: ${scoreTotal}`, {font: `24px`, fill: `#7c4c23`}); + resultView.setVisible(false); + } + if(counter === 4){ + const overlap = document.getElementById("overlap"); + overlap.style.display = "block"; + // console.log(counter) + submitButton.setVisible(true); + resultView.setVisible(true); + } + }; + } } // let hideButton = this.add.text(helpButtonWidth, helpButtonHeight, "Let`s Do", { @@ -529,82 +555,7 @@ import Layout from '../../layouts/Layout.astro'; const targetZone = targetZones.find((zone) => zone.name === block.texture.key); }); }; - let score = 0; - let counter = 0; - const isMatch = (blockName, targetName) => { - if(isMatch){ - counter++; - // console.log(counter) - - if(counter === 4){ - const overlap = document.getElementById("overlap"); - overlap.style.display = "block"; - // console.log(counter) - submitButton.setVisible(true); - } - } - let scoreTotal = 0; - const match = blockMatches.find((m) => m.blockName === blockName && m.targetName === targetName); - console.log(match) - if(match !== undefined){ - scoreTotal++; - console.log(scoreTotal) - } - // console.log(scoreTotal) - // // console.log(match) - // if(match){ - // score++; - // console.log(score) - // let day; - // switch (score) { - // case 0: - // day = "Points - 1"; - // break; - // case 2: - // day = "Points - 2"; - // break; - // case 4: - // day = "Points - 4"; - - // } - // console.log(day) - // finalDom = document.getElementById("good"); - // finalDom.classList.add("good"); - // document.getElementById("good").innerHTML = day; - // document.getElementById("good").style.color = '#7c4c23' - // // console.log(totalScore) - // // if(score === 2){ - // // finalDom = document.getElementById("good"); - // // finalDom.classList.add("good"); - // // document.getElementById("good").innerHTML = " Good"; - // // document.getElementById("good").style.color = '#7c4c23' - - - // // // let img = document.createElement("img"); - // // // img.src = "/assets/party-feestje.gif"; - // // // img.width = 100; - // // // document.getElementById('win').appendChild(img); - // // } - // // else if(score === 4) { - // // finalDom = document.getElementById("verryGood"); - // // finalDom.classList.add("verryGood"); - // // document.getElementById("verryGood").innerHTML = "Verry Good"; - // // document.getElementById("verryGood").style.color = '#7c4c23' - // // } - // // else { - // // // finalDom = document.getElementById("lost"); - // // // finalDom.classList.add("lost"); - // // // document.getElementById("lost").innerHTML = " Lost"; - // // // document.getElementById("lost").style.color = '#7c4c23' - // // // console.log("Losttttt") - // // } - - // } else{ - // score = score - // } - // return match !== undefined; - };