diff options
Diffstat (limited to 'snake.c')
| -rw-r--r-- | snake.c | 14 |
1 files changed, 3 insertions, 11 deletions
@@ -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); |
