2048.html
changeset 130 28694f058ea4
parent 129 e0958e521716
child 131 02d7eb74bfe5
--- a/2048.html	Wed Sep 24 19:17:52 2014 +0300
+++ b/2048.html	Wed Sep 24 19:23:05 2014 +0300
@@ -283,6 +283,7 @@
       <div class="option">up to <input type="text" id="stat-count-limit" value="100"> times</div>
       <div class="option">up to <input type="text" id="stat-time-limit" value="10"> sec</div>
       <button id="statistic-start">Start</button>
+      <button id="statistic-stop">Stop</button>
       <button id="statistic-clean">Clean</button>
       <div class="option"><input type="checkbox" id="report-score"/> score</div>
       <div class="option"><input type="checkbox" id="report-turn"/> turn</div>
@@ -889,6 +890,7 @@
       reportsDom.insertBefore(reportDom, reportsDom.firstChild);
     }
     ui.report.start = function() {
+      ui.report.executed = true;
       var histo = {};
       var gameCntLimit = parseInt(document.getElementById('stat-count-limit').value);
       if (isNaN(gameCntLimit) || !isFinite(gameCntLimit) || gameCntLimit < 1)
@@ -926,7 +928,7 @@
       var tsFrom = new Date().getTime(), tsFrame = tsFrom;
       function batch() {
         /* console.profile(); */
-        while (gameCnt++ < gameCntLimit) {
+        while (gameCnt++ < gameCntLimit && ui.report.executed) {
           play();
           var tsTo = new Date().getTime();
           if (tsTo - tsFrame > 7000) {
@@ -937,7 +939,7 @@
             break;
         }
         /* console.profileEnd(); */
-        if (tsTo - tsFrom >= tsLimit || gameCnt >= gameCntLimit) {
+        if (tsTo - tsFrom >= tsLimit || gameCnt >= gameCntLimit || ! ui.report.executed) {
           ui.report.fix(histo);
           ui.report.show(histo, gameCnt);
         } else {
@@ -949,6 +951,12 @@
     var statisticStartBtn = document.getElementById("statistic-start");
     statisticStartBtn.addEventListener("click", ui.report.start, false);
 
+    ui.report.stop = function() {
+      ui.report.executed = false;
+    }
+    var statisticStopBtn = document.getElementById("statistic-stop");
+    statisticStopBtn.addEventListener("click", ui.report.stop, false);
+
     ui.report.clean = function() {
       while (reportsDom.hasChildNodes()) {
         reportsDom.removeChild(reportsDom.lastChild);