From 61cd9ad08abce996b34c338ef25c3a4c3cad426f Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Thu, 13 Jan 2022 15:14:37 +0100 Subject: [PATCH] add findShip() --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 9 +++++++++ .../java/de/tims/fleetstorm/ai/LogicTest.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index 8acdc8d..76e29f8 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -10,6 +10,7 @@ public class Logic { private Matchfield matchfield; private Coordinate lastShot; + public boolean foundShip = false; public Coordinate chooseField() { ArrayList possibleFields = new ArrayList(); @@ -57,4 +58,12 @@ public class Logic { return matchfield; } + public void findShip() { + if (lastShot.getState() == Coordinate.HIT) { + + foundShip = true; + } + System.out.println("Do this"); + } + } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 7257ccf..f266a76 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -102,4 +102,19 @@ class LogicTest { assertNotNull(result); } + @Test + void testFindShip() { + Logic logic = new Logic(); + Matchfield matchfield; + int size = 4; + matchfield = new Matchfield(size); + matchfield.createMatchfield(); + logic.setMatchfield(matchfield); + + logic.setLastShot(new Coordinate(2, 2)); + logic.getLastShot().setState(Coordinate.HIT); + logic.findShip(); + assertEquals(logic.foundShip, true); + } + }