diff --git a/src/main/java/Snake/Snake.java b/src/main/java/Snake/Snake.java index b4fc174..a1574df 100644 --- a/src/main/java/Snake/Snake.java +++ b/src/main/java/Snake/Snake.java @@ -82,6 +82,14 @@ public class Snake { return bodySegments; } + public void setDirection(SnakeDirection direction) + { + if((this.direction == SnakeDirection.LEFT && direction != SnakeDirection.RIGHT) || + (this.direction == SnakeDirection.RIGHT && direction != SnakeDirection.LEFT) || + (this.direction == SnakeDirection.UP && direction != SnakeDirection.DOWN) || + (this.direction == SnakeDirection.DOWN && direction != SnakeDirection.UP)) + this.direction = direction; + }