Browse Source

add clearBelow

Max Wenzel 3 years ago
parent
commit
424f38c8e6
  1. 9
      src/main/java/de/tims/fleetstorm/ai/Logic.java
  2. 17
      src/test/java/de/tims/fleetstorm/ai/LogicTest.java

9
src/main/java/de/tims/fleetstorm/ai/Logic.java

@ -13,6 +13,7 @@ public class Logic {
public Coordinate target;
private boolean foundShip = false;
public boolean clearedAbove = false;
public boolean clearedBelow = false;
public Coordinate chooseField() {
ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>();
@ -95,4 +96,12 @@ public class Logic {
}
public void clearBelow(Coordinate shot) {
target = matchfield.getBelow(shot);
if (target.getState() == Coordinate.EMPTY) {
clearedBelow = true;
}
}
}

17
src/test/java/de/tims/fleetstorm/ai/LogicTest.java

@ -141,4 +141,21 @@ class LogicTest {
assertEquals(logic.clearedAbove, true);
}
@Test
void testClearBelow() {
Logic logic = new Logic();
Matchfield matchfield;
Coordinate shot = new Coordinate(2, 2);
int size = 4;
matchfield = new Matchfield(size);
matchfield.createMatchfield();
logic.setMatchfield(matchfield);
logic.setLastShot(shot);
matchfield.getField(shot).setState(Coordinate.EMPTY);
logic.clearBelow(shot);
assertEquals(logic.clearedBelow, true);
}
}
Loading…
Cancel
Save