Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7195

JavaScript Loop bug infinite loop

$
0
0

I am doing my first game snake, but I have a problem which appears sometime when I eat a rectangle and try to generate another my script crashes and I have an infinite loop.

var coincide = false;         var cmpt;         do {             mangey = Math.random();             mangey *= canvas.height;             t = mangey % 20;             mangey -= t;             mangex = Math.random();             mangex *= canvas.width;             t = mangex % 20;             mangex = mangex - t;             for (cmpt = 0; cmpt < snake.length; cmpt++) {                 if ((snake[cmpt][0] == mangex) && (snake[cmpt][1] == mangey)) {                     coincide = true;                     alert(snake);                     console.log(mangex,mangey);                 }             }         }         while ((coincide) || ((mangex > 480) || (mangex < 0)) || ((mangey > 380) || (mangey < 0)));

Viewing all articles
Browse latest Browse all 7195

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>