summaryrefslogtreecommitdiff
path: root/snake.c
diff options
context:
space:
mode:
Diffstat (limited to 'snake.c')
-rw-r--r--snake.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/snake.c b/snake.c
index a1df46f..26623cf 100644
--- a/snake.c
+++ b/snake.c
@@ -191,19 +191,22 @@ int main(int argc, char **argv) {
}
/* move the food */
while(1) {
+ uint8 overlap = 0;
foodPos = init_vector(1 + (rand() % (boardSize - 2)), 1 + (rand() % (boardSize - 2)));
/* if food overlaps snake or obstacles, try again */
for(int i = 0; i < snakePositions.length; i++) {
if((snakePositions.vectors[i].mx == foodPos.mx) && (snakePositions.vectors[i].my == foodPos.my)) {
- continue;
+ overlap = 1;
}
}
for(int i = 0; i < obstaclePositions.length; i++) {
if((obstaclePositions.vectors[i].mx == foodPos.mx) && (obstaclePositions.vectors[i].my == foodPos.my)) {
- continue;
+ overlap = 1;
}
}
+ if(!overlap) {
break;
+ }
}
}
/* move the snake */