Browse Source

add findShip()

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
61cd9ad08a
  1. 9
      src/main/java/de/tims/fleetstorm/ai/Logic.java
  2. 15
      src/test/java/de/tims/fleetstorm/ai/LogicTest.java

9
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<Coordinate> possibleFields = new ArrayList<Coordinate>();
@ -57,4 +58,12 @@ public class Logic {
return matchfield;
}
public void findShip() {
if (lastShot.getState() == Coordinate.HIT) {
foundShip = true;
}
System.out.println("Do this");
}
}

15
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);
}
}
Loading…
Cancel
Save