Browse Source

add clearAbove

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
794f4bbb51
  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 Matchfield matchfield;
private Coordinate lastShot; private Coordinate lastShot;
public Coordinate target;
private boolean foundShip = false; private boolean foundShip = false;
public boolean clearedAbove = false;
public Coordinate chooseField() { public Coordinate chooseField() {
ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>(); ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>();
@ -75,4 +77,22 @@ public class Logic {
return this.foundShip; 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); 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