Download:
child 3:dc65da9d084c
parent 1:23e96cfcea1f
2:146717977795
Anton Shestakov <engored@ya.ru>, Sat, 09 Nov 2013 23:47:54 +0900
Stop iterating after the end is reached.

2 файлов изменено, 11 вставок(+), 5 удалений(-) [+]
flowsnake.js file | annotate | diff | comparison | revisions
index.html file | annotate | diff | comparison | revisions
--- a/flowsnake.js Sat Nov 09 23:47:14 2013 +0900
+++ b/flowsnake.js Sat Nov 09 23:47:54 2013 +0900
@@ -87,6 +87,10 @@
},
step: function(visible) {
+ if (this.pointer >= this.rule.length) {
+ return false;
+ }
+
var redraw = false;
switch (this.rule[this.pointer]) {
@@ -103,9 +107,7 @@
break;
}
- if (this.pointer < this.rule.length) {
- this.pointer++;
- }
+ this.pointer++;
if (visible) {
if (redraw) {
@@ -114,6 +116,8 @@
this.step(visible);
}
}
+
+ return true;
},
draw: function() {
--- a/index.html Sat Nov 09 23:47:14 2013 +0900
+++ b/index.html Sat Nov 09 23:47:54 2013 +0900
@@ -20,8 +20,10 @@
$('pre').css({'left': '50%', 'margin-left': - $('pre').width() / 2});
- window.setInterval(function() {
- flowsnake.step(true);
+ var interval = window.setInterval(function() {
+ if (!flowsnake.step(true)) {
+ window.clearInterval(interval);
+ }
}, 50);
});
</script>