From ae72cce7195cae91c44a36972b91e52139d31cfb Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Sat, 15 Jan 2022 14:48:13 +0100 Subject: [PATCH] Added test case when field was already hitted --- src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java | 2 +- .../java/de/tims/fleetstorm/matchfield/CoordinateTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java index aeebdbf..ede9574 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java @@ -45,7 +45,7 @@ public class Coordinate { } public boolean shoot() { - if (this.state == Coordinate.SHOT) + if (this.state == Coordinate.SHOT || this.state == Coordinate.HIT) return false; if (this.state == Coordinate.SHIP) { diff --git a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java index 779e432..1b9a560 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java @@ -76,6 +76,9 @@ class CoordinateTest { assertTrue(matchfield.getField(0, 0).shoot()); assertFalse(matchfield.getField(0, 0).shoot()); + + matchfield.getField(3, 4).shoot(); + assertFalse(matchfield.getField(3, 4).shoot()); } }