add score and endgame
[2048.git] / js / html_actuator.js
blob:a/js/html_actuator.js -> blob:b/js/html_actuator.js
--- a/js/html_actuator.js
+++ b/js/html_actuator.js
@@ -1,8 +1,10 @@
 function HTMLActuator() {
-  this.tileContainer = document.getElementsByClassName("tile-container")[0];
+  this.tileContainer  = document.getElementsByClassName("tile-container")[0];
+  this.gameContainer  = document.getElementsByClassName("game-container")[0];
+  this.scoreContainer = document.getElementsByClassName("score-container")[0];
 }
 
-HTMLActuator.prototype.actuate = function (grid) {
+HTMLActuator.prototype.actuate = function (grid, metadata) {
   var self = this;
 
   window.requestAnimationFrame(function () {
@@ -15,6 +17,12 @@
         }
       });
     });
+
+    self.updateScore(metadata.score);
+
+    if (metadata.over) {
+      self.gameOver();
+    }
   });
 };
 
@@ -60,3 +68,11 @@
   return "tile-position-" + position.x + "-" + position.y;
 };
 
+HTMLActuator.prototype.updateScore = function (score) {
+  this.scoreContainer.textContent = score;
+};
+
+HTMLActuator.prototype.gameOver = function () {
+  this.gameContainer.classList.add("game-over");
+};
+

comments