From 86fc6a2578c24feb38df37bb6d4ae9883060fa4d Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 15:51:28 +0100 Subject: [PATCH] update --- src/main/java/Snake/Snake.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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; + }