summaryrefslogtreecommitdiff
path: root/snake.c
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2018-04-02 10:12:31 +0930
committerdaniel-Jones <daniel@danieljon.es>2018-04-02 10:12:31 +0930
commit5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f (patch)
tree5bd8b78d50103605caa6a9592fd00edc65ebd1a1 /snake.c
parent085a00ac6b6abbd560716e6f5749dd0f597d464a (diff)
downloadsnake-5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f.tar.gz
snake-5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f.zip
added check to prevent changing direction into yourself
Diffstat (limited to 'snake.c')
-rw-r--r--snake.c8
1 files 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':