Bien au dessus de Léandre et JL
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.

159 lines
4.4 KiB

3 years ago
let game = {
bac: 1000,
joueur: 100,
inGame: false,
mise: 0
}
3 years ago
3 years ago
3 years ago
const bacDom = document.getElementById("banque_score")
const joueurDom = document.getElementById("joueur_score")
3 years ago
const input = document.getElementById("mise_input");
input.value = game.mise
3 years ago
bacDom.innerText = game.bac
joueurDom.innerText = game.joueur
3 years ago
3 years ago
function nbAlea(){
3 years ago
return Math.floor(Math.random()*10);
3 years ago
}
// Anime les rouleaux
function rotate(rouleau, angle){
3 years ago
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);
})
3 years ago
}
3 years ago
3 years ago
// 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 {
3 years ago
document.getElementById('tirette').style.transform = 'rotate3d(1,0,0,'+i+'deg)';
}
i += 9;
}
}, 20);
}
3 years ago
async function tirage(){
3 years ago
let numbers = [nbAlea(), nbAlea(), nbAlea()]
3 years ago
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))
])
3 years ago
return numbers
}
3 years ago
3 years ago
async function jeu(){
3 years ago
if(game.inGame) return;
3 years ago
game.inGame = true
3 years ago
3 years ago
//game.mise = parseInt(document.getElementById("mise_input").value)
if(game.mise > 100 || game.mise <= 0 || game.mise > game.joueur){
3 years ago
console.log("erreur: pas possible jouer")
3 years ago
game.inGame = false
3 years ago
return
}
3 years ago
tirette()
3 years ago
game.joueur -= game.mise
game.bac += game.mise
3 years ago
3 years ago
let tirageNumbers = await tirage() //[2,1,2]
3 years ago
//console.log(tirageNumbers)
3 years ago
document.getElementById("tirage").innerText = tirageNumbers
3 years ago
3 years ago
let gain_retour = gain(tirageNumbers)
3 years ago
console.log(gain_retour)
3 years ago
game.bac -= gain_retour
bacDom.innerText = game.bac
game.joueur += gain_retour
joueurDom.innerText = game.joueur
3 years ago
3 years ago
console.log(game.mise)
3 years ago
input
3 years ago
if(game.bac < 500) console.log("fin de partie")
3 years ago
if(game.joueur > 0) game.inGame = false
3 years ago
}
function gain(tirage){
if(tirage[0] == 9 &&
tirage[1] == 9 &&
3 years ago
tirage[2] == 9){
let periode = setInterval(clignotement, 800);
return game.bac
3 years ago
}
else if(tirage[0] == tirage[1] &&
tirage[1] == tirage[2]){
return game.mise*6
3 years ago
}
else if(tirage[0] == tirage[1] ||
tirage[0] == tirage[2] ||
tirage[1] == tirage[2]){
return game.mise*3
3 years ago
}
return 0
}
function regles(){
let overlay = document.getElementsByClassName("overlay")[0];
3 years ago
if(overlay.style.display == "none") overlay.style.display = "flex"
else overlay.style.display = "none"
3 years ago
}
3 years ago
input.addEventListener("input", (e)=>{
3 years ago
let inputMise = e.target.value;
3 years ago
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
3 years ago
})
3 years ago
for (let i = 0; i < 10; i++) {
//console.log(i);
for (var j = 0; j < 3; j++) {
//console.log(j);
3 years ago
document.getElementsByClassName('cube__face--'+i)[j].style.transform = 'rotateX('+(i*36)+'deg) translateZ(calc(1.9vw /'+Math.tan(18* Math.PI / 180)+')';
3 years ago
}
3 years ago
3 years ago
}
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);