hasty bugfix and moved board functions to own directory

This commit is contained in:
2024-12-15 12:07:25 +02:00
parent 66238756d6
commit be6dfe712c
6 changed files with 81 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include "snake.h"
#include "../board/board.h"
extern char SNAKE_VIS;
extern boardInfo brdInfo;
@@ -107,6 +108,23 @@ void addSnakePart(char board[][brdInfo.x], snakePart* head) {
exit(1);
}
/*
Untested fix to a bug where the new part
would replace a part of the board border.
*/
if (newTail->x > plBrdInfo.xe) {
newTail->x = plBrdInfo.xs;
} else if (newTail->x < plBrdInfo.xs) {
newTail->x = plBrdInfo.xe;
}
if (newTail->y > plBrdInfo.ye) {
newTail->y = plBrdInfo.ys;
} else if (newTail->y < plBrdInfo.ys) {
newTail->y = plBrdInfo.ye;
}
// bugfix end
newTail->next = NULL;
tail->next = newTail;