Browse Source

aaaah

master
Kalyax 3 years ago
parent
commit
9bf404b117
  1. 72
      app.js

72
app.js

@ -2,12 +2,12 @@ let game = {
bac: 1000,
joueur: 100,
inGame: false,
mise: 0
mise: parseInt(document.getElementById("mise_input").value)
}
const bacDom = document.getElementById("banque_score")
const joueurDom = document.getElementById("joueur_score")
const tirageDom = document.getElementById("tirage")
bacDom.innerText = game.bac
joueurDom.innerText = game.joueur
@ -17,17 +17,20 @@ function nbAlea(){
// Anime les rouleaux
function rotate(rouleau, angle){
let i = 0;
let interval = setInterval(() => {
if (i >= angle){
rouleau.style.transform = 'rotate3d(1,0,0,'+angle+'deg)';
clearInterval(interval);
}
else {
i += 9;
rouleau.style.transform = 'rotate3d(1,0,0,'+i+'deg)';
}
}, 5);
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);
})
}
@ -48,29 +51,33 @@ function tirette(){
}, 20);
}
function tirage(){
async function tirage(){
let numbers = [nbAlea(), nbAlea(), nbAlea()]
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));
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
}
function jeu(){
async function jeu(){
if(game.inGame) return;
tirette()
game.inGame = true
game.mise = parseInt(document.getElementById("mise_input").value)
//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 = tirage() //[2,1,2]
let tirageNumbers = await tirage() //[2,1,2]
//console.log(tirageNumbers)
tirageDom.innerText = tirageNumbers
document.getElementById("tirage").innerText = tirageNumbers
let gain_retour = gain(tirageNumbers)
console.log(gain_retour)
@ -79,25 +86,27 @@ function jeu(){
game.joueur += gain_retour
joueurDom.innerText = game.joueur
if(game.bac < 500){
console.log("fin de partie")
}
console.log(game.mise)
if(game.bac < 500) console.log("fin de partie")
if(!game.jouer <= 0) game.inGame = false
}
function gain(tirage){
if(tirage[0] == 9 &&
tirage[1] == 9 &&
tirage[2] == 9){
return bac
return game.bac
}
else if(tirage[0] == tirage[1] &&
tirage[1] == tirage[2]){
return mise*6
return game.mise*6
}
else if(tirage[0] == tirage[1] ||
tirage[0] == tirage[2] ||
tirage[1] == tirage[2]){
return mise*3
return game.mise*3
}
return 0
}
@ -105,6 +114,13 @@ function regles(){
//afficher règles
}
document.getElementById("mise_input").addEventListener("input", (e)=>{
let inputMise = e.target.value;
if(isNaN(inputMise)) e.target.value = game.mise
else game.mise = parseInt(e.target.value)
})
for (let i = 0; i < 10; i++) {
//console.log(i);
for (var j = 0; j < 3; j++) {

Loading…
Cancel
Save