Gacha/scripts/functionsGacha.js

65 lines
1.7 KiB
JavaScript

//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("<BIG>"+"Vous avez gagné"+"<FONT COLOR='red'>"+" un chapeau"+"</FONT>"+"! "+"</BIG>");
break;
case 'bonbon':
document.write("<BIG>"+"Vous avez gagné"+"<FONT COLOR='red'>"+" un bonbon"+"</FONT>"+"! "+"</BIG>");
break;
case 'pieceOr':
document.write("<BIG>"+"Vous avez gagné"+"<FONT COLOR='red'>"+" une pièce en or"+"</FONT>"+"! "+"</BIG>");
break;
case 'poney':
document.write("<BIG>"+"Vous avez gagné"+"<FONT COLOR='red'>"+" un poney"+"</FONT>"+"! "+"</BIG>");
break;
default:
document.write("<BIG>"+"Vous n'avez"+"<FONT COLOR='red'>"+" rien"+"</FONT>"+" gagné! "+"</BIG>");
break;
}
return selectedPrices;
}