From e092bb5586904e525b7c8860efb3e6b4f4dc7d34 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Mon, 6 Feb 2023 23:59:58 -0800 Subject: fixed stupid bug that someone wrote --- snake.c | 7 +++++-- 1 file 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 */ -- cgit v1.3.1