From 5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Mon, 2 Apr 2018 10:12:31 +0930 Subject: added check to prevent changing direction into yourself --- snake.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/snake.c b/snake.c index 24c0900..6b94287 100644 --- a/snake.c +++ b/snake.c @@ -99,11 +99,15 @@ int main(void) /* direction key detection */ case 's': case 'j': - snake->direction = DOWN; + /* prevent changing direction into yourself */ + if (snake->direction != UP) + snake->direction = DOWN; break; case 'w': case 'k': - snake->direction = UP; + /* prevent changing direction into yourself */ + if (snake->direction != DOWN) + snake->direction = UP; break; case 'a': case 'h': -- cgit v1.2.3