diff options
author | Simon Rettberg | 2019-06-12 15:27:13 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-06-12 15:27:13 +0200 |
commit | 8a2c60bddb7d854aaef04ff3f0b69fde33c0443f (patch) | |
tree | 9360c056c6dd070ca3d11a793b42d09a536811bc /src | |
parent | remove newline (diff) | |
download | slxgreeter-8a2c60bddb7d854aaef04ff3f0b69fde33c0443f.tar.gz slxgreeter-8a2c60bddb7d854aaef04ff3f0b69fde33c0443f.tar.xz slxgreeter-8a2c60bddb7d854aaef04ff3f0b69fde33c0443f.zip |
Prevent infinite loop
Diffstat (limited to 'src')
-rw-r--r-- | src/snake.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/snake.cpp b/src/snake.cpp index 9c3c4d0..5246a3c 100644 --- a/src/snake.cpp +++ b/src/snake.cpp @@ -187,10 +187,10 @@ GameCore::GameCore(QWidget *widget) // Remove tail from field if snake reached desired length if (snake->parts.size() >= snake->len) { const QPoint &p = snake->parts.front(); + snake->parts.pop_front(); if (FIELD(p.x(), p.y()) == snake->cell) { setField(p.x(), p.y(), &empty); } - snake->parts.pop_front(); } // Eat if (FIELD(snake->x, snake->y)->isFood()) { @@ -200,10 +200,10 @@ GameCore::GameCore(QWidget *widget) snake->len = 10; while (snake->parts.size() > snake->len) { const QPoint &p = snake->parts.front(); - if (FIELD(p.x(), p.y())->isFood()) - continue; - setField(p.x(), p.y(), &snakebrick); snake->parts.pop_front(); + if (!FIELD(p.x(), p.y())->isFood()) { + setField(p.x(), p.y(), &snakebrick); + } } addFood(); } else { |