Commits

Colin Copeland  committed 47f6205

add has_winner stub

  • Participants
  • Parent commits 2af5ddd

Comments (0)

Files changed (1)

File tic-tac-toe/media/game.js

         var y = row * box_size + line_size;
         this.ctx.fillRect(x, y, box_size - line_size, box_size - line_size);
     }
+    this.has_winner = function() {
+        function sum(spaces) {
+            var total = 0;
+            $(spaces).each(function(idx) {
+                total += this;
+            });
+            return total;
+        }
+        var vals = [];
+        // rows
+        $(this.board).each(function(row, cols) {
+            vals.append(sum(cols));
+        });
+        
+        $(vals).each(function(idx, total) {
+            if (total == -3 || total == 3) {
+                alert('winner!');
+            }
+        });
+    }
+    // this.has_winner();
 }
 
 function handle_click(ctx, x, y) {