cadeau qui fonctionne vraiment cette fois
This commit is contained in:
parent
4b4d8c3d03
commit
54f824b52a
6 changed files with 80 additions and 86 deletions
|
|
@ -1,57 +0,0 @@
|
||||||
/*
|
|
||||||
* @file css/alerte.css
|
|
||||||
* @description
|
|
||||||
* @author mougnibas <mougnibas@insa-toulouse.fr>
|
|
||||||
* @createTime 2024-11-29 10:35:07
|
|
||||||
* @lastModified 2024-12-15 18:53:32
|
|
||||||
* Copyright ©Théo Mougnibas All rights reserved
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Le conteneur de l'alerte, va couvrir tout l'écran*/
|
|
||||||
.modal {
|
|
||||||
display: none; /* on la cache par défaut */
|
|
||||||
position: fixed;
|
|
||||||
z-index: 1; /* BAM ! AU DESSUS DE TOUT */
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-color: rgba(0, 0, 0, 0.4); /* On floute le derrière */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Contenu de l'alerte */
|
|
||||||
.modal-content {
|
|
||||||
color: black;
|
|
||||||
background-color: #fefefe;
|
|
||||||
margin: 15% auto; /* on le centre */
|
|
||||||
padding: 20px;
|
|
||||||
border: 1px solid #888;
|
|
||||||
width: 80%;
|
|
||||||
max-width: 400px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bouton pour fermer l'alerte */
|
|
||||||
.close-btn {
|
|
||||||
color: #aaa;
|
|
||||||
float: right;
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.close-btn:hover,
|
|
||||||
.close-btn:focus {
|
|
||||||
color: black;
|
|
||||||
text-decoration: none;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bouton OK */
|
|
||||||
.modal.button {
|
|
||||||
padding: 10px 20px;
|
|
||||||
background-color: #4CAF50;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -50,4 +50,11 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
pointer-events: none; /* pour ne pas interagir avec les confettis */
|
pointer-events: none; /* pour ne pas interagir avec les confettis */
|
||||||
|
}
|
||||||
|
|
||||||
|
#div_cadeau{
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
z-index: -2;
|
||||||
|
width: 5vw;
|
||||||
}
|
}
|
||||||
BIN
img/cadeau.png
Normal file
BIN
img/cadeau.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 333 KiB |
|
|
@ -4,7 +4,6 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Prog Web Legend</title>
|
<title>Prog Web Legend</title>
|
||||||
<script> alert("click")</script>
|
|
||||||
<link rel="stylesheet" href="" id="link-css">
|
<link rel="stylesheet" href="" id="link-css">
|
||||||
<link rel="stylesheet" href="./css/index.css">
|
<link rel="stylesheet" href="./css/index.css">
|
||||||
<link rel="stylesheet" href="./css/alerte/a1.css" id="alerte-css">
|
<link rel="stylesheet" href="./css/alerte/a1.css" id="alerte-css">
|
||||||
|
|
@ -78,7 +77,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="div_cadeau">
|
||||||
|
<img src="img/cadeau.png">
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<footer>
|
<footer>
|
||||||
<p>L'evolution est non contractuelle, adaptée pour le gameplay</p>
|
<p>L'evolution est non contractuelle, adaptée pour le gameplay</p>
|
||||||
|
|
|
||||||
20
js/intro.js
20
js/intro.js
|
|
@ -24,4 +24,24 @@ function firstClick(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pageChargee(){
|
||||||
|
// fonction appelée au chargement de la page, initialise divers mécanismes du jeu
|
||||||
|
|
||||||
|
ouvrirAlerte("Bienvenue dans progWeb-legend ! Un jeu des plus innovants basé sur le concept du click de souris :)")
|
||||||
|
firstClick()
|
||||||
|
|
||||||
|
|
||||||
|
// on setup le cadeau qui se téléporte
|
||||||
|
const div_cadeau = document.getElementById("div_cadeau");
|
||||||
|
div_cadeau.addEventListener("click",cadeauClickCallback)
|
||||||
|
|
||||||
|
|
||||||
|
setTimeout(genererCadeau, Math.random() * 10000 + 20000); // Premier affichage aléatoire entre 20 et 30 secondes
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("DOMContentLoaded",pageChargee)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
77
js/main.js
77
js/main.js
|
|
@ -419,37 +419,60 @@ function rendreNombreLisible(n){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function afficherCadeau() {
|
|
||||||
|
function genererCadeau(){
|
||||||
|
|
||||||
|
|
||||||
|
const div_cadeau = document.getElementById("div_cadeau");
|
||||||
|
div_cadeau.style.display = "block";
|
||||||
|
|
||||||
|
teleportationCadeau(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cadeauClickCallback(){
|
||||||
|
const div_cadeau = document.getElementById("div_cadeau");
|
||||||
|
|
||||||
|
const nb_gen = Math.floor(Math.random() * 10) + 1; // Nombre aléatoire entre 1 et 10
|
||||||
|
const nb_devine = parseInt(prompt("Entrez un chiffre entre 1 et 10 :"), 10);
|
||||||
|
if (isNaN(nb_devine) || nb_devine < 1 || nb_devine > 10) {
|
||||||
|
ouvrirAlerte("Le chiffre rentré n'est pas valide")
|
||||||
|
}else{
|
||||||
|
if (nb_gen === nb_devine) {
|
||||||
|
ouvrirAlerte("Bravo ! Vous avez doublé votre score !");
|
||||||
|
score *= 2;
|
||||||
|
} else {
|
||||||
|
ouvrirAlerte("Dommage !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// enlève le cadeau
|
||||||
|
div_cadeau.style.display = "none";
|
||||||
|
|
||||||
|
// génère un nouveau timer pour le prochain cadeau à afficher !
|
||||||
|
setTimeout(genererCadeau, Math.random() * 10000 + 20000); // Premier affichage aléatoire entre 20 et 30 secondes
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function teleportationCadeau(n) {
|
||||||
|
const div_cadeau = document.getElementById("div_cadeau");
|
||||||
|
|
||||||
const x = Math.random() * (window.innerWidth - 50);
|
const x = Math.random() * (window.innerWidth - 50);
|
||||||
const y = Math.random() * (window.innerHeight - 50);
|
const y = Math.random() * (window.innerHeight - 50);
|
||||||
|
|
||||||
gift.style.left = `${x}px`;
|
div_cadeau.style.left = `${x}px`;
|
||||||
gift.style.top = `${y}px`;
|
div_cadeau.style.top = `${y}px`;
|
||||||
gift.style.display = "block";
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
gift.style.display = "none";
|
|
||||||
setTimeout(afficherCadeau, 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(){
|
// limite le nombre de téléportations du cadeau à 15 fois
|
||||||
const gift = document.getElementById("gift");
|
// permet de ne pas boucler le timeout à l'infini
|
||||||
const correctNumber = Math.floor(Math.random() * 10) + 1; // Nombre aléatoire entre 1 et 10
|
if(n < 15){
|
||||||
gift.addEventListener("click", () => {
|
n += 1
|
||||||
const userNumber = parseInt(prompt("Entrez un chiffre entre 1 et 10 :"), 10);
|
setTimeout(() => {
|
||||||
if (isNaN(userNumber) || userNumber < 1 || userNumber > 10) {
|
// affiche le cadeau à un autre endroit pour faire un effet de téléportation
|
||||||
alert("Le chiffre rentré n'est pas valide")
|
teleportationCadeau(n)
|
||||||
}
|
}, Math.random() * 1000 + 500); // Durée d'affichage entre 500ms et 1.5 seconde
|
||||||
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
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue