Commit c5c021b2 authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

create function for change player

parent b519acd5
......@@ -29,6 +29,23 @@ document.getElementById("current-1").textContent = "0";
document.getElementById("score-0").textContent = "0";
document.getElementById("score-1").textContent = "0";
function changePlayer() {
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");
}
// add functionality for roll btn
document.querySelector(".btn-roll").addEventListener("click", function() {
//create random number
......@@ -41,22 +58,7 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
if (dice !== 1) {
roundScore += dice;
} else {
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");
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