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); + } }