summaryrefslogtreecommitdiff
path: root/snake.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-02-06 15:36:36 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-02-06 15:36:36 -0800
commit7bff197db2e87175bd5c181f1e46716351701769 (patch)
tree7577a397eb687fcb1d2b9da8cfdf6bf5bb02db15 /snake.c
parente02ba6dc7511c46f017e22f348ac75974f93e15a (diff)
fixed obstacle collisions
Diffstat (limited to 'snake.c')
-rw-r--r--snake.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/snake.c b/snake.c
index bfd1bf7..c63a2d4 100644
--- a/snake.c
+++ b/snake.c
@@ -164,16 +164,7 @@ int main(int argc, char **argv) {
while(1) {
/* handle ctrl-c interrupt */
if(intCtrlC) {
-EXIT:
- /* unhide cursor */
- printf("\033[?25h");
- /* kill the listener thread */
- *cancellationToken = 1;
- printf("Your score was %d. Press any key to exit\n", score);
- pthread_join(listenerID, NULL);
- free(cancellationToken);
- free((int*)lastInput);
- return 0;
+ goto EXIT;
}
/* first, draw the current state of the board */
@@ -192,7 +183,7 @@ EXIT:
}
/* check if snake lands on obstacle */
for (int i = 0; i < obstaclePositions.length; i ++) {
- if ((snakePositions.vectors[0].mx + lastMoveDir.mx == obstaclePositions.vectors[i].mx) && (snakePositions.vectors[0].my + lastMoveDir.my == obstaclePositions.vectors[i].mx)) {
+ if ((snakePositions.vectors[0].mx + lastMoveDir.mx == obstaclePositions.vectors[i].mx) && (snakePositions.vectors[0].my + lastMoveDir.my == obstaclePositions.vectors[i].my)) {
goto EXIT;
}
}
@@ -240,6 +231,7 @@ EXIT:
break;
}
}
+EXIT:
/* clear the last getch call from the listener */
*cancellationToken = 1;
printf("\n%sYou died. Score: %d. Press any key to exit%s\n", RED, score, COLOR_RESET);