From e8b420c1516224cd6f2ef59dff90a9acdc354ad5 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 15:52:31 +0100 Subject: [PATCH] update --- src/main/java/Snake/Snake.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/Snake/Snake.java b/src/main/java/Snake/Snake.java index a1574df..a07b1ca 100644 --- a/src/main/java/Snake/Snake.java +++ b/src/main/java/Snake/Snake.java @@ -91,6 +91,11 @@ public class Snake { this.direction = direction; } - + public boolean isSelfColliding() + { + var headPosition = bodySegments.get(0); + return bodySegments.stream().anyMatch((point) -> + point.equals(headPosition) && point != headPosition); + } }