summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-03-05 00:52:05 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-03-05 00:52:05 -0800
commit303099bbcaa223ff3f5946295e2d814d40fec324 (patch)
tree087497190dc2bb04e29f4cf102adda28d90a2a13
parentcfcdffe92b7248b3982f53b2c14b67d94a42b210 (diff)
fixed the implementation of q to abort
-rw-r--r--src/snake.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/snake.c b/src/snake.c
index 7f9a32a..f40e341 100644
--- a/src/snake.c
+++ b/src/snake.c
@@ -175,11 +175,10 @@ int main(int argc, char **argv) {
time.tv_nsec = round((float)updateInterval / ((float)speed / 3));
nanosleep(&time, NULL);
/* read the most recent value emitted by the listener */
+ if(*(char*)lastInput == 'q') {
+ goto EXIT;
+ }
vector_t dir = parse_dir(*(char*)lastInput);
-
- if (dir.mx == -2) {
- goto EXIT;
- }
/* if the player inputted a valid direction, use it. otherwise, use his last valid input */
if((dir.mx != 0 || dir.my != 0) && !(dir.mx == 1 && lastMoveDir.mx == -1) && !(dir.mx == -1 && lastMoveDir.mx == 1) && !(dir.my == 1 && lastMoveDir.my == -1) && !(dir.my == -1 && lastMoveDir.my == 1)) {
lastMoveDir = dir;
@@ -260,9 +259,7 @@ vector_t parse_dir(char cDir) {
}
else if(cDir == 'a' || cDir == 'h') {
return init_vector(-1, 0);
- } else if (cDir == 'q') {
- return init_vector(-2, -2);
- }
+ }
else {
return init_vector(0, 0);
}