Commits

Anonymous committed caf4b5c

Restart

Comments (0)

Files changed (2)

                         But Different
                     </div>
                     <h2>Score: <span id="score">0</span></h2>
+                    <button id="restart">Restart</button>
+                    <hr />
                     By <a href="mailto:miki.tebeka@gmail.com">Miki</a>
                 </td>
                 <td>
 var COLORS = ['blue', 'green', 'orange', 'red', 'yellow'];
 var NUM_ROWS = 10;
 var NUM_COLS = 15;
+var SCORE = 0;
 
 function random_color() {
     return COLORS[parseInt(Math.random() * COLORS.length)];
 }
 
 function on_click(coords) {
-    var same_color = same_color_pack(coords);
-    $.each(same_color, function () {
+    var pack = same_color_pack(coords);
+    $.each(pack, function () {
             img_at(this).attr('src', 'blank.png');
         }
     );
+
+    update_score(pack.length);
 }
 
 function make_handler(row, col) {
     }
 }
 
+function update_score(count) {
+    SCORE = SCORE + count;
+    $('#score').html(SCORE);
+}
+
 function create_board() {
     var table = $('#board');
     for (var row = 0; row < NUM_ROWS; ++row) {
 function on_ready()
 {
     create_board();
+    $('#restart').click(
+        function() {
+            update_score(-SCORE);
+            $.each($('#board img'), function() {
+                $(this).attr('src', random_color() + '.png');
+            });
+        }
+    );
 }
 
 $(document).ready(on_ready);