Commit c5c021b2 authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

create function for change player

parent b519acd5
......@@ -29,18 +29,7 @@ document.getElementById("current-1").textContent = "0";
document.getElementById("score-0").textContent = "0";
document.getElementById("score-1").textContent = "0";
// add functionality for roll btn
document.querySelector(".btn-roll").addEventListener("click", function() {
//create random number
var dice = Math.floor(Math.random() * 6) + 1;
// disply the result
var diceDOM = document.querySelector(".dice");
diceDOM.style.display = "block";
diceDOM.src = "./dice-" + dice + ".png";
// update current scores, if the rolled number was not one
if (dice !== 1) {
roundScore += dice;
} else {
function changePlayer() {
roundScore = 0;
if (activePlayer === 0) {
activePlayer = 1;
......@@ -55,8 +44,21 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
//change active theme
document.querySelector(".player-0-panel").classList.toggle("active");
document.querySelector(".player-1-panel").classList.toggle("active");
}
// add functionality for roll btn
document.querySelector(".btn-roll").addEventListener("click", function() {
//create random number
var dice = Math.floor(Math.random() * 6) + 1;
// disply the result
var diceDOM = document.querySelector(".dice");
diceDOM.style.display = "block";
diceDOM.src = "./dice-" + dice + ".png";
// update current scores, if the rolled number was not one
if (dice !== 1) {
roundScore += dice;
} else {
changePlayer();
}
// change current score in user inteface
document.querySelector("#current-" + activePlayer).textContent = roundScore;
......@@ -64,22 +66,14 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
// add functionality for hold btn
document.querySelector(".btn-hold").addEventListener("click", function() {
//update score
scores[activePlayer] += roundScore;
//change score in user interface
document.getElementById("score-" + activePlayer).textContent =
scores[activePlayer];
roundScore = 0;
if (activePlayer === 0) {
activePlayer = 1;
document.querySelector("#current-0").textContent = 0;
} else {
activePlayer = 0;
document.querySelector("#current-1").textContent = 0;
}
// make dice invisible
document.querySelector(".dice").style.display = "none";
//change active theme
document.querySelector(".player-0-panel").classList.toggle("active");
document.querySelector(".player-1-panel").classList.toggle("active");
//change player
changePlayer();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment