summaryrefslogtreecommitdiff
path: root/snake.c
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2018-04-02 10:18:36 +0930
committerdaniel-Jones <daniel@danieljon.es>2018-04-02 10:18:36 +0930
commit9028e3082e0ed32b1fb6ac86e967e12c1f7a6f95 (patch)
tree484dcb7873e8a56cb2fcd5ff3efeab2d7216a43a /snake.c
parent5c48ff9370d95a1bd3b1ac4a063bcb0b09f7fa9f (diff)
downloadsnake-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.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/snake.c b/snake.c
index 6b94287..ca7ed6b 100644
--- a/snake.c
+++ b/snake.c
@@ -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;