summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;