Browse Source

Implement setFigure method

AIPlayer
Jonas Wagner 3 years ago
parent
commit
e06cc3a7a3
  1. 15
      src/main/java/Game.java
  2. 22
      src/test/java/GameTest.java

15
src/main/java/Game.java

@ -87,4 +87,19 @@ public class Game {
}
return false;
}
public int setFigure(int figId, int dice, Player p, Game g) {
int preCalculated = (p.figures.get(figId).getPosition() + dice) % 40;
int kicked = 0;
for(Player currentPlayer : g.players) {
for(Figure currentFigure : currentPlayer.figures) {
if(currentFigure.getPosition() == preCalculated) {
currentFigure.setPosition(-1);
kicked = 1;
}
}
}
p.figures.get(figId).setPosition(preCalculated);
return kicked;
}
}

22
src/test/java/GameTest.java

@ -13,12 +13,20 @@ public class GameTest {
private Game g;
private Player p1;
private Game g2;
private Player p2;
@BeforeEach
void setup() {
g = new Game();
p1 = g.players.get(0);
g2 = new Game();
p2 = g2.players.get(0);
p2.figures.get(0).setPosition(5);
p2.figures.get(1).setPosition(10);
g2.players.get(3).figures.get(1).setPosition(14);
}
@ParameterizedTest
@ -151,6 +159,20 @@ public class GameTest {
)
);
}
@ParameterizedTest
@MethodSource("setFigureData")
void setFigureTest(String testname, int figId, int dice, int expectedResult) {
int calculatedResult = g.setFigure(figId, dice, p2, g2);
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
}
static Stream<Arguments> setFigureData () {
return Stream.of(
Arguments.of("Figur wird auf Feld gesetzt - Niemand gekicked", 0, 4, 0),
Arguments.of("Figur wird auf Feld gesetzt - Jemand gekicked", 1, 4, 1)
);
}
}
Loading…
Cancel
Save