commit 618426bbf5cecc165a2828ccc0f2418688ec4bd2 Author: cadoles Date: Thu Jun 9 15:53:58 2022 +0200 Ajout du gacha (ticket#12) diff --git a/functionsGacha.js b/functionsGacha.js new file mode 100644 index 0000000..03e0fc0 --- /dev/null +++ b/functionsGacha.js @@ -0,0 +1,64 @@ +//Variables/////////////////////////////////////////////////////////////////////////////// + +const recompenses = ['chapeau','bonbon','pieceOr','poney']; //récompenses possible +const seuils = ['10','25','5','1']; //seuils des récompenses + + +recompenses[0]="poney"; +seuils[0]= 1; + +recompenses[1]="pieceOr"; +seuils[1]= 5; + +recompenses[2]="chapeau"; +seuils[2]= 10; + +recompenses[3]="bonbon"; +seuils[3]= 25; + +//Functions////////////////////////////////////////////////////////////////////////////// + +//prend nombre aléatoire entre min et max +function getRandom(min, max) { + return Math.random() * (max - min) + min; +} + +//choisi une récompense aléatoire parmis celle de la constante:"récompenses" +function getRandomPrice() { + var randomNum = Math.floor(getRandom(0, 100)); + for (var i = 0; i < recompenses.length; i++) { + + console.log(randomNum, seuils[i]) + if (randomNum <= seuils[i]) { + var selectedPrices = recompenses[i]; + break + } + } + + +//écrit la phrase annonçant la récompenses, + switch (selectedPrices) { + + case 'chapeau': + document.write(""+"Vous avez gagné"+""+" un chapeau"+""+"! "+""); + break; + + case 'bonbon': + document.write(""+"Vous avez gagné"+""+" un bonbon"+""+"! "+""); + break; + + case 'pieceOr': + document.write(""+"Vous avez gagné"+""+" une pièce en or"+""+"! "+""); + break; + + case 'poney': + document.write(""+"Vous avez gagné"+""+" un poney"+""+"! "+""); + break; + + default: + document.write(""+"Vous n'avez"+""+" rien"+""+" gagné! "+""); + break; + } + return selectedPrices; +} + diff --git a/indexGacha.html b/indexGacha.html new file mode 100644 index 0000000..cd76243 --- /dev/null +++ b/indexGacha.html @@ -0,0 +1,20 @@ + + + + + + Cad'cha + + + + + +

Cad'cha

+ +

Essayer de gagner le gros lot avec la lotterie Cad'cha!

+

Qu'avez-vous gagnez ?

+ + + + + \ No newline at end of file diff --git a/scriptGacha.js b/scriptGacha.js new file mode 100644 index 0000000..c16f5ed --- /dev/null +++ b/scriptGacha.js @@ -0,0 +1,2 @@ + +getRandomPrice();