You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.4 KiB
158 lines
4.4 KiB
let game = {
|
|
bac: 1000,
|
|
joueur: 100,
|
|
inGame: false,
|
|
mise: 0
|
|
}
|
|
|
|
|
|
const bacDom = document.getElementById("banque_score")
|
|
const joueurDom = document.getElementById("joueur_score")
|
|
const input = document.getElementById("mise_input");
|
|
input.value = game.mise
|
|
bacDom.innerText = game.bac
|
|
joueurDom.innerText = game.joueur
|
|
|
|
function nbAlea(){
|
|
return Math.floor(Math.random()*10);
|
|
}
|
|
|
|
// Anime les rouleaux
|
|
function rotate(rouleau, angle){
|
|
return new Promise((resolve, reject) => {
|
|
let i = 0;
|
|
let interval = setInterval(() => {
|
|
if (i >= angle){
|
|
rouleau.style.transform = 'rotate3d(1,0,0,'+angle+'deg)';
|
|
clearInterval(interval);
|
|
resolve()
|
|
}
|
|
else {
|
|
i += 9;
|
|
rouleau.style.transform = 'rotate3d(1,0,0,'+i+'deg)';
|
|
}
|
|
}, 5);
|
|
})
|
|
}
|
|
|
|
|
|
// Anime la tirette
|
|
function tirette(){
|
|
let i = 0;
|
|
let id = setInterval(() => {
|
|
if (i > 360) clearInterval(id);
|
|
else {
|
|
if (i > 180){
|
|
document.getElementById('tirette').style.transform = 'rotate3d(1,0,0,'+(360-i)+'deg)';
|
|
}
|
|
else {
|
|
|
|
document.getElementById('tirette').style.transform = 'rotate3d(1,0,0,'+i+'deg)';
|
|
}
|
|
i += 9;
|
|
}
|
|
}, 20);
|
|
}
|
|
|
|
async function tirage(){
|
|
let numbers = [nbAlea(), nbAlea(), nbAlea()]
|
|
await Promise.all([
|
|
rotate(document.getElementsByClassName("cube")[0], (Math.floor(Math.random()*15)*360) - (numbers[0]*36)),
|
|
rotate(document.getElementsByClassName("cube")[1], (Math.floor(Math.random()*15)*360) - (numbers[1]*36)),
|
|
rotate(document.getElementsByClassName("cube")[2], (Math.floor(Math.random()*15)*360) - (numbers[2]*36))
|
|
])
|
|
return numbers
|
|
}
|
|
|
|
async function jeu(){
|
|
if(game.inGame) return;
|
|
game.inGame = true
|
|
|
|
//game.mise = parseInt(document.getElementById("mise_input").value)
|
|
if(game.mise > 100 || game.mise <= 0 || game.mise > game.joueur){
|
|
console.log("erreur: pas possible jouer")
|
|
game.inGame = false
|
|
return
|
|
}
|
|
tirette()
|
|
game.joueur -= game.mise
|
|
game.bac += game.mise
|
|
|
|
let tirageNumbers = await tirage() //[2,1,2]
|
|
//console.log(tirageNumbers)
|
|
document.getElementById("tirage").innerText = tirageNumbers
|
|
|
|
let gain_retour = gain(tirageNumbers)
|
|
console.log(gain_retour)
|
|
game.bac -= gain_retour
|
|
bacDom.innerText = game.bac
|
|
game.joueur += gain_retour
|
|
joueurDom.innerText = game.joueur
|
|
|
|
console.log(game.mise)
|
|
input
|
|
if(game.bac < 500) console.log("fin de partie")
|
|
if(game.joueur > 0) game.inGame = false
|
|
}
|
|
|
|
function gain(tirage){
|
|
if(tirage[0] == 9 &&
|
|
tirage[1] == 9 &&
|
|
tirage[2] == 9){
|
|
let periode = setInterval(clignotement, 800);
|
|
return game.bac
|
|
}
|
|
else if(tirage[0] == tirage[1] &&
|
|
tirage[1] == tirage[2]){
|
|
return game.mise*6
|
|
}
|
|
else if(tirage[0] == tirage[1] ||
|
|
tirage[0] == tirage[2] ||
|
|
tirage[1] == tirage[2]){
|
|
return game.mise*3
|
|
}
|
|
return 0
|
|
}
|
|
function regles(){
|
|
let overlay = document.getElementsByClassName("overlay")[0];
|
|
if(overlay.style.display == "none") overlay.style.display = "flex"
|
|
else overlay.style.display = "none"
|
|
}
|
|
|
|
input.addEventListener("input", (e)=>{
|
|
let inputMise = e.target.value;
|
|
if(isNaN(inputMise)) e.target.value = game.mise; //autre que 0-9 entré
|
|
else if(parseInt(e.target.value) > 100) {e.target.value = 100; game.mise = 100;} //sup à 100
|
|
else if(inputMise == "") game.mise = 0
|
|
else game.mise = parseInt(e.target.value); //nbr entre 0-9
|
|
})
|
|
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
//console.log(i);
|
|
for (var j = 0; j < 3; j++) {
|
|
//console.log(j);
|
|
document.getElementsByClassName('cube__face--'+i)[j].style.transform = 'rotateX('+(i*36)+'deg) translateZ(calc(1.9vw /'+Math.tan(18* Math.PI / 180)+')';
|
|
}
|
|
|
|
}
|
|
|
|
let jackpot_loop = 0;
|
|
|
|
function clignotement(){
|
|
if (jackpot_loop<10){
|
|
if (document.getElementById('jackpot').style.visibility=='visible'){
|
|
document.getElementById('jackpot').style.visibility='hidden';
|
|
}
|
|
else{
|
|
document.getElementById('jackpot').style.visibility='visible';
|
|
}
|
|
}
|
|
else {
|
|
clearInterval(periode);
|
|
jackpot_loop = 0;
|
|
}
|
|
jackpot_loop++;
|
|
};
|
|
// mise en place de l appel de la fonction toutes les 0.8 secondes
|
|
// Pour arrêter le clignotement : clearInterval(periode);
|
|
|