Browse Source

Add countdown timer

Thomas Dy 11 years ago
parent
commit
231472f8e1
2 changed files with 25 additions and 4 deletions
  1. 19 3
      public/javascripts/tabooServices.js
  2. 6 1
      public/partials/chatRoom.html

+ 19 - 3
public/javascripts/tabooServices.js

@@ -1,5 +1,17 @@
 angular.module('tabooServices', [])
-.factory('Taboo', function($rootScope, Chat) {
+.factory('Timer', function($interval) {
+  var service = {
+    count: 0,
+    start: function(duration) {
+      service.count = duration;
+      $interval(function() {
+        service.count -= 1;
+      }, 1000, duration);
+    }
+  }
+  return service;
+})
+.factory('Taboo', function($rootScope, Chat, Timer) {
   var game = {};
   game.startRound = function() {
     Chat.send('/start');
@@ -15,11 +27,13 @@ angular.module('tabooServices', [])
   };
   game.roundStart = function() {
     game.pendingRound = false;
-    game.startTime = new Date();
+    game.roundStarted = true;
     game.points = 0;
+    game.timer.start(60);
   };
   game.roundEnd = function() {
     game.pendingRound = false;
+    game.roundStarted = false;
     game.card = null;
     game.monitors = [];
   };
@@ -39,8 +53,10 @@ angular.module('tabooServices', [])
     game.card = null;
     game.points = 0;
     game.pendingRound = false;
+    game.roundStarted = false;
     game.player = '';
     game.monitors = [];
+    game.timer = Timer;
     game.status();
   }
 
@@ -106,4 +122,4 @@ angular.module('tabooServices', [])
   }
 
   return game;
-})
+});

+ 6 - 1
public/partials/chatRoom.html

@@ -30,9 +30,14 @@
     </div>
     <div class="span4" ng-controller="GameCtrl">
       <button class="btn" ng-show="game.pendingRound" ng-click="game.startRound()">Start</button>
-      <div ng-show="game.card">
+      <div ng-show="game.roundStarted">
+        <h1>{{game.timer.count}}</h1>
+      </div>
+      <div ng-show="game.roundStarted">
         <button class="btn" ng-show="game.isPlayer()" ng-click="game.pass()">Pass</button>
         <button class="btn" ng-show="game.isMonitor()" ng-click="game.taboo()">Uh-uh!</button>
+      </div>
+      <div ng-show="game.card">
         <h2>Card</h2>
         <h3>{{game.card.word}}</h3>
         <ul class="taboo">