Browse Source

overload getState() in Matchfield

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
ac9183ea27
  1. 1
      src/main/java/de/tims/fleetstorm/ai/Logic.java
  2. 4
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  3. 1
      src/test/java/de/tims/fleetstorm/ai/LogicTest.java
  4. 14
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

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

@ -173,6 +173,5 @@ public class Logic {
public void setClearedLeft(boolean b) { public void setClearedLeft(boolean b) {
this.clearedLeft = b; this.clearedLeft = b;
} }
} }

4
src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java

@ -32,6 +32,10 @@ public class Matchfield {
this.matchfield[x][y].setState(state); this.matchfield[x][y].setState(state);
} }
public void setState(Coordinate coordinate, int state) {
this.matchfield[coordinate.getX()][coordinate.getY()].setState(state);
}
public Coordinate getField(Coordinate coordinate) { public Coordinate getField(Coordinate coordinate) {
return matchfield[coordinate.getX()][coordinate.getY()]; return matchfield[coordinate.getX()][coordinate.getY()];
} }

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

@ -255,4 +255,5 @@ class LogicTest {
assertEquals(logic.getClearedRight(), false); assertEquals(logic.getClearedRight(), false);
} }
} }

14
src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

@ -1,6 +1,7 @@
package de.tims.fleetstorm.matchfield; package de.tims.fleetstorm.matchfield;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -127,4 +128,17 @@ class MatchfieldCreationTest {
matchfield.getField(5, 4)), matchfield.getField(5, 4)),
Arguments.of("below from (5/0) - should be null", matchfield, new Coordinate(5, 0), null)); Arguments.of("below from (5/0) - should be null", matchfield, new Coordinate(5, 0), null));
} }
@Test
void testsetStateOverloaded() {
Matchfield matchfield = new Matchfield(10);
matchfield.createMatchfield();
int x = 3;
int y = 3;
matchfield.setState(new Coordinate(x, y), Coordinate.SHIP);
int result = matchfield.getState(x, y);
assertEquals(result, Coordinate.SHIP);
}
} }
Loading…
Cancel
Save