diff options
author | daniel-Jones <daniel@danieljon.es> | 2018-04-02 10:12:31 +0930 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2018-04-02 10:12:31 +0930 |
commit | 5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f (patch) | |
tree | 5bd8b78d50103605caa6a9592fd00edc65ebd1a1 /snake.c | |
parent | 085a00ac6b6abbd560716e6f5749dd0f597d464a (diff) | |
download | snake-5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f.tar.gz snake-5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f.zip |
added check to prevent changing direction into yourself
Diffstat (limited to 'snake.c')
-rw-r--r-- | snake.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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': |