Browse Source

Merge commit '375f28c5ebc8e1c8ea93669eed2792b5f368b4d0' into HEAD

master
Jenkins 3 years ago
parent
commit
76d754f791
  1. 7
      src/main/java/Figure.java
  2. 11
      src/main/java/Game.java
  3. 1
      src/main/java/Gameboard.java
  4. 22
      src/main/java/Player.java
  5. 14
      src/test/java/GameTest.java
  6. 64
      src/test/java/PlayerTest.java

7
src/main/java/Figure.java

@ -6,4 +6,11 @@ public class Figure {
this.position = -1;
}
public void setPosition(int position) {
this.position = position;
}
public int getPosition() {
return position;
}
}

11
src/main/java/Game.java

@ -8,15 +8,14 @@ public class Game {
public static void main(String[] args) {
Game g = new Game();
g.startGame();
}
public void startGame() {
public Game() {
this.gb = new Gameboard();
gb.initGameboard();
p1 = new Player("Rot");
p2 = new Player("Blau");
p3 = new Player("Gelb");
p4 = new Player("Grün");
p1 = new Player("Rot", 40, 43);
p2 = new Player("Blau", 44, 47);
p3 = new Player("Gelb", 48, 51);
p4 = new Player("Grün", 52, 55);
}
}

1
src/main/java/Gameboard.java

@ -1,4 +1,3 @@
import java.lang.reflect.Array;
import java.util.Arrays;
public class Gameboard {

22
src/main/java/Player.java

@ -1,13 +1,17 @@
import javax.sound.midi.Soundbank;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
public class Player {
String name;
Figure[] figures;
int startHome;
int endHome;
public Player (String name) {
public Player (String name, int startHome, int endHome) {
this.name = name;
this.startHome = startHome;
this.endHome = endHome;
figures = new Figure[4];
for(int i = 0; i < 4; i++) {
this.figures[i] = new Figure();
@ -22,4 +26,16 @@ public class Player {
public int rollDice() {
return (int) (Math.random() * 6 + 1);
}
public boolean checkGameWin(Collection<Figure> figures) {
Iterator<Figure> it = figures.iterator();
Figure f;
for(;it.hasNext();) {
f = it.next();
if(!(f.getPosition() >= startHome && f.getPosition() <= endHome)) {
return false;
}
}
return true;
}
}

14
src/test/java/GameTest.java

@ -1,10 +1,4 @@
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class GameTest {
@ -18,10 +12,10 @@ public class GameTest {
void setup() {
this.gb = new Gameboard();
gb.initGameboard();
p1 = new Player("Rot");
p2 = new Player("Blau");
p3 = new Player("Gelb");
p4 = new Player("Grün");
p1 = new Player("Rot", 40, 43);
p2 = new Player("Blau", 44, 47);
p3 = new Player("Gelb", 48, 51);
p4 = new Player("Grün", 52, 55);
}
}

64
src/test/java/PlayerTest.java

@ -1,19 +1,23 @@
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Stream;
public class PlayerTest {
private Player p;
@BeforeEach
void setup() {
p = new Player("Rot");
p = new Player("Rot", 40, 43);
}
@Test
@ -43,4 +47,60 @@ public class PlayerTest {
assertThat(calculatedResult).describedAs("Starting postion of Figures").isEqualTo(expectedResult);
}
@ParameterizedTest
@MethodSource("FieldStream")
void checkGameWin(String testname, Collection<Figure> figures, Collection<Integer> positions, boolean expectedResult) {
Iterator<Figure> it = figures.iterator();
Iterator<Integer> it2 = positions.iterator();
for(;it.hasNext();) {
it.next().setPosition(it2.next());
}
boolean calculatedResult = p.checkGameWin(figures);
assertThat(calculatedResult).describedAs("Check Win").isEqualTo(expectedResult);
}
static Stream<Arguments> FieldStream() {
return Stream.of(
Arguments.of("No Figure in House",
Arrays.asList(
new Figure(),
new Figure(),
new Figure(),
new Figure()),
Arrays.asList(-1, -1, -1, -1),
false),
Arguments.of("One Figure in House",
Arrays.asList(
new Figure(),
new Figure(),
new Figure(),
new Figure()),
Arrays.asList(40, -1, -1, -1),
false),
Arguments.of("Two Figure in House",
Arrays.asList(
new Figure(),
new Figure(),
new Figure(),
new Figure()),
Arrays.asList(40, 41, -1, -1),
false),
Arguments.of("Three Figure in House",
Arrays.asList(
new Figure(),
new Figure(),
new Figure(),
new Figure()),
Arrays.asList(40, 41, 42, -1),
false),
Arguments.of("Four Figure in House",
Arrays.asList(
new Figure(),
new Figure(),
new Figure(),
new Figure()),
Arrays.asList(40, 41, 42, 43),
true)
);
}
}
Loading…
Cancel
Save