diff options
author | daniel-Jones <daniel@danieljon.es> | 2018-04-02 10:18:36 +0930 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2018-04-02 10:18:36 +0930 |
commit | 9028e3082e0ed32b1fb6ac86e967e12c1f7a6f95 (patch) | |
tree | 484dcb7873e8a56cb2fcd5ff3efeab2d7216a43a /snake.c | |
parent | 5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f (diff) | |
download | snake-9028e3082e0ed32b1fb6ac86e967e12c1f7a6f95.tar.gz snake-9028e3082e0ed32b1fb6ac86e967e12c1f7a6f95.zip |
Added checking to x directions as well to prevent colliding with self
Diffstat (limited to 'snake.c')
-rw-r--r-- | snake.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -110,12 +110,16 @@ int main(void) snake->direction = UP; break; case 'a': - case 'h': - snake->direction = LEFT; + case 'h': + /* prevent changing direction into yourself */ + if (snake->direction != RIGHT) + snake->direction = LEFT; break; case 'd': case 'l': - snake->direction = RIGHT; + /* prevent changing direction into yourself */ + if (snake->direction != LEFT) + snake->direction = RIGHT; break; case 'q': /* q quits the game */ snake->state = 0; |