Skip to content

Commit a7aec95

Browse files
author
Angel Jumbo
committed
fix small bug
1 parent 56b9309 commit a7aec95

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ sssnake -S -s 15 -j 5
2727
press Q to quit.
2828
Use the -h options to see the option details.
2929

30-
## If the characters are not displayed properly
30+
## Known bugs
3131

32-
I'm working on fix in it, but for the moment you can use the -A flag to use ascii characters.
32+
- Sometimes the food spawns in the snake body.
3333

3434
## Contributing
3535

main.c

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ int main(int argc, char *argv[]) {
158158
update_position(snake, blocksTaken, &food, direction, maxX, maxY);
159159
}
160160

161+
if (snake->head->x == food.x && snake->head->y == food.y)
162+
rand_pos_food(&food, blocksTaken, maxX, maxY);
163+
161164
if (snake->colission || c == 'q')
162165
break;
163166
if (screensaver && c != ERR) {

snake.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void move_body(Snake *snake, XYMap *blocksTaken, Point *food, int prevx,
4545
int prevx2, prevy2;
4646

4747
xymap_mark(blocksTaken, snake->head->x, snake->head->y, SBODY);
48-
xymap_unmark(blocksTaken, snake->tail->x, snake->tail->y);
48+
// xymap_unmark(blocksTaken, snake->tail->x, snake->tail->y);
4949

5050
SnakePart *snakePart = snake->head->next;
5151
while (snakePart != NULL) {
@@ -60,7 +60,7 @@ static void move_body(Snake *snake, XYMap *blocksTaken, Point *food, int prevx,
6060
snakePart = snakePart->next;
6161
}
6262
if (food->x == snake->head->x && food->y == snake->head->y) {
63-
rand_pos_food(food, blocksTaken, maxX, maxY);
63+
// rand_pos_food(food, blocksTaken, maxX, maxY);
6464
snake->grow++;
6565
snake->colission = 0;
6666
}
@@ -71,9 +71,10 @@ static void move_body(Snake *snake, XYMap *blocksTaken, Point *food, int prevx,
7171
snake->tail->next = snake_part_create(prevx, prevy, snake->tail);
7272

7373
snake->tail = snake->tail->next;
74-
xymap_mark(blocksTaken, snake->tail->x, snake->tail->y, SBODY);
75-
// } else {
76-
// xymap_unmark(blocksTaken, prevx, prevy);
74+
// xymap_mark(blocksTaken, snake->tail->x, snake->tail->y, SBODY);
75+
// rand_pos_food(food, blocksTaken, maxX, maxY);
76+
} else {
77+
xymap_unmark(blocksTaken, prevx, prevy);
7778
}
7879
}
7980

0 commit comments

Comments
 (0)