From 308aa92b3e19a2aab5fe5b0bb1c59a7524b08e9e Mon Sep 17 00:00:00 2001 From: Lurkars Date: Fri, 14 Apr 2017 20:07:06 +0200 Subject: [PATCH] disable button while 'cpu' playing --- index.html | 1 + js/interface.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 726bbd5..2d09295 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ openzilch.js + diff --git a/js/interface.js b/js/interface.js index a074ab2..61f04ed 100644 --- a/js/interface.js +++ b/js/interface.js @@ -28,20 +28,26 @@ function Interface() { }); self.pointsButton.addEventListener("click", function() { - self.fireEvent("takePoints"); + if (self.playing) { + self.fireEvent("takePoints"); + } }); self.dicesButton.addEventListener("click", function() { - self.fireEvent("addPoints"); - self.fireEvent("roleDices"); + if (self.playing) { + self.fireEvent("addPoints"); + self.fireEvent("roleDices"); + } }); for (var diceIndex = 0; diceIndex < 6; diceIndex++) { var diceContainer = self.dices[diceIndex]; diceContainer.diceIndex = diceIndex; diceContainer.addEventListener("click", function() { - self.fireEvent("toggleDice", this.diceIndex); + if (self.playing) { + self.fireEvent("toggleDice", this.diceIndex); + } }); } @@ -138,9 +144,11 @@ Interface.prototype.setPoints = function(points) { Interface.prototype.setPlaying = function(playing) { if (playing) { + this.playing = true; this.playerScoreContainer.classList.add('active'); this.cpuScoreContainer.classList.remove('active'); } else { + this.playing = false; this.playerScoreContainer.classList.remove('active'); this.cpuScoreContainer.classList.add('active'); }