Commit 7e2bc5a5 authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

add functionality for newGame btn

parent a517dc4c
...@@ -20,14 +20,34 @@ activePlayer = 0; ...@@ -20,14 +20,34 @@ activePlayer = 0;
// var x = document.querySelector("#score-1").textContent; // var x = document.querySelector("#score-1").textContent;
// console.log(x); // console.log(x);
// make dice invisible
document.querySelector(".dice").style.display = "none";
// initializing user inteface //initializing everything
document.getElementById("current-0").textContent = "0"; init();
document.getElementById("current-1").textContent = "0";
document.getElementById("score-0").textContent = "0"; function init() {
document.getElementById("score-1").textContent = "0";
// initializing global variable
scores = [0, 0];
roundScore = 0;
activePlayer = 0;
// make dice invisible
document.querySelector(".dice").style.display = "none";
// initializing user inteface
document.getElementById("current-0").textContent = "0";
document.getElementById("current-1").textContent = "0";
document.getElementById("score-0").textContent = "0";
document.getElementById("score-1").textContent = "0";
document.querySelector(".player-0-panel").classList.remove('active');
document.querySelector(".player-1-panel").classList.remove('active');
document.querySelector(".player-0-panel").classList.remove('winner');
document.querySelector(".player-1-panel").classList.remove('winner');
document.querySelector(".player-0-panel").classList.add('active');
document.getElementById("name-0").textContent = "PLAYER 1";
document.getElementById("name-1").textContent = "PLAYER 2";
}
function changePlayer() { function changePlayer() {
roundScore = 0; roundScore = 0;
...@@ -76,11 +96,18 @@ document.querySelector(".btn-hold").addEventListener("click", function() { ...@@ -76,11 +96,18 @@ document.querySelector(".btn-hold").addEventListener("click", function() {
//find winner! //find winner!
if (scores[activePlayer] >= 20) { if (scores[activePlayer] >= 20) {
document.getElementById("name-" + activePlayer).textContent = "Winner! :)"; document.getElementById("name-" + activePlayer).textContent = "Winner! :)";
document.querySelector('.dice').style.display = "none"; document.querySelector(".dice").style.display = "none";
document.querySelector(".player-"+activePlayer+"-panel").classList.remove('active'); document
document.querySelector(".player-"+activePlayer+"-panel").classList.add('winner'); .querySelector(".player-" + activePlayer + "-panel")
.classList.remove("active");
document
.querySelector(".player-" + activePlayer + "-panel")
.classList.add("winner");
} else { } else {
//change player //change player
changePlayer(); changePlayer();
} }
}); });
// add functionality for newGame btn
document.querySelector('.btn-new').addEventListener("click" , init);
\ No newline at end of file
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