Browse Source

add clearAbove

Max Wenzel 3 years ago
parent
commit
527a4b3c6b
  1. 20
      src/main/java/de/tims/fleetstorm/ai/Logic.java
  2. 17
      src/test/java/de/tims/fleetstorm/ai/LogicTest.java

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

@ -10,7 +10,9 @@ public class Logic {
private Matchfield matchfield;
private Coordinate lastShot;
public Coordinate target;
private boolean foundShip = false;
public boolean clearedAbove = false;
public Coordinate chooseField() {
ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>();
@ -75,4 +77,22 @@ public class Logic {
return this.foundShip;
}
public void checkAround(Coordinate coordinate) {
// TODO Auto-generated method stub
}
public void clearAbove(Coordinate shot) {
target = matchfield.getAbove(shot);
if (target.getState() == Coordinate.EMPTY) {
clearedAbove = true;
}
}
private void shot() {
// TODO Auto-generated method stub
}
}

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

@ -124,4 +124,21 @@ class LogicTest {
assertEquals(logic.getFoundShip(), true);
}
@Test
void testClearAbove() {
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.clearAbove(shot);
assertEquals(logic.clearedAbove, true);
}
}
Loading…
Cancel
Save