From 2a377b25c9b41c16254aaca2861020a07e2a1eec Mon Sep 17 00:00:00 2001 From: jibidar Date: Sat, 28 Dec 2024 18:11:10 +0100 Subject: [PATCH] j'ai mis le cadeau --- css/gift.css | 32 ++++++++++++++++++++++++++++++++ js/main.js | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 css/gift.css diff --git a/css/gift.css b/css/gift.css new file mode 100644 index 0000000..7a165ab --- /dev/null +++ b/css/gift.css @@ -0,0 +1,32 @@ +.gift { + width: 50px; + height: 50px; + background-color: red; + border-radius: 10px; + position: absolute; + animation: moveGift 5s infinite linear; + cursor: pointer; +} + +@keyframes moveGift { + 0% { + top: 0; + left: 0; + } + 25% { + top: 0; + left: calc(100% - 50px); + } + 50% { + top: calc(100% - 50px); + left: calc(100% - 50px); + } + 75% { + top: calc(100% - 50px); + left: 0; + } + 100% { + top: 0; + left: 0; + } +} \ No newline at end of file diff --git a/js/main.js b/js/main.js index e6c6015..d142f82 100644 --- a/js/main.js +++ b/js/main.js @@ -138,7 +138,7 @@ async function remplirMagasinCollegues(){ let collegues = data["collegues"] for(const key in collegues){ - // ne va pas s'embeter à proecess si déjà présent dans le magasin + // ne va pas s'embeter à process si déjà présent dans le magasin // ou si le score d'évolution n'est pas assez élevé const el = collegues[key] if(!magasin_coll[key] && evolution_coll === parseInt(el.evolution)){ @@ -320,9 +320,10 @@ function rickRoll(){ }) - + } + // fonction qui va creer plein d'elements confetti function genererConfetti() { @@ -416,4 +417,39 @@ function rendreNombreLisible(n){ return ret -} \ No newline at end of file +} + +function showGift() { + const x = Math.random() * (window.innerWidth - 50); + const y = Math.random() * (window.innerHeight - 50); + + gift.style.left = `${x}px`; + gift.style.top = `${y}px`; + gift.style.display = "block"; + + setTimeout(() => { + gift.style.display = "none"; + setTimeout(showGift, Math.random() * 3000 + 2000); // Temps aléatoire entre 2 et 5 secondes + }, Math.random() * 2000 + 1000); // Durée d'affichage entre 1 et 2 secondes +} + +function cadeau(){ + const gift = document.getElementById("gift"); + const correctNumber = Math.floor(Math.random() * 10) + 1; // Nombre aléatoire entre 1 et 10 + gift.addEventListener("click", () => { + const userNumber = parseInt(prompt("Entrez un chiffre entre 1 et 10 :"), 10); + if (isNaN(userNumber) || userNumber < 1 || userNumber > 10) { + alert("Le chiffre rentré n'est pas valide") + } + else{ + if (userNumber === correctNumber) { + alert("Bravo ! Vous avez doublé votre score !"); + score *= 2; + } else { + alert("Dommage !"); + } + } + } +) +} +setTimeout(showGift, Math.random() * 10000 + 20000); // Premier affichage aléatoire entre 10 et 30 secondes