Browse Source

Merge branch 'Game' into develop

AIPlayer
Jonas Wagner 3 years ago
parent
commit
8dabc7c7a0
  1. 9
      src/main/java/Figure.java
  2. 22
      src/main/java/Game.java
  3. 25
      src/main/java/Player.java
  4. 27
      src/test/java/GameTest.java
  5. 46
      src/test/java/PlayerTest.java

9
src/main/java/Figure.java

@ -0,0 +1,9 @@
public class Figure {
int position;
public Figure() {
this.position = -1;
}
}

22
src/main/java/Game.java

@ -0,0 +1,22 @@
public class Game {
Gameboard gb;
Player p1;
Player p2;
Player p3;
Player p4;
public static void main(String[] args) {
Game g = new Game();
g.startGame();
}
public void startGame() {
this.gb = new Gameboard();
gb.initGameboard();
p1 = new Player("Rot");
p2 = new Player("Blau");
p3 = new Player("Gelb");
p4 = new Player("Grün");
}
}

25
src/main/java/Player.java

@ -0,0 +1,25 @@
import javax.sound.midi.Soundbank;
import java.util.Arrays;
public class Player {
String name;
Figure[] figures;
public Player (String name) {
this.name = name;
figures = new Figure[4];
for(int i = 0; i < 4; i++) {
this.figures[i] = new Figure();
}
}
@Override
public String toString() {
return name;
}
public int rollDice() {
return (int) (Math.random() * 6 + 1);
}
}

27
src/test/java/GameTest.java

@ -0,0 +1,27 @@
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 {
private Gameboard gb;
private Player p1;
private Player p2;
private Player p3;
private Player p4;
@BeforeEach
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");
}
}

46
src/test/java/PlayerTest.java

@ -0,0 +1,46 @@
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;
public class PlayerTest {
private Player p;
@BeforeEach
void setup() {
p = new Player("Rot");
}
@Test
void testDice() {
int calculatedResult = p.rollDice();
assertThat(calculatedResult).describedAs("Dice result").isBetween(1,6);
}
@Test
void testToString() {
String expectedResult = "Rot";
String calculatedResult = p.toString();
assertThat(calculatedResult).describedAs("Player Name").isEqualTo(expectedResult);
}
@Test
void checkStartPositionOfFigures() {
int expectedResult = -1;
int calculatedResult = p.figures[0].position;
for(int i = 0; i < 4; i++) {
calculatedResult = p.figures[i].position;
if(expectedResult != calculatedResult) {
calculatedResult = 1;
break;
}
}
assertThat(calculatedResult).describedAs("Starting postion of Figures").isEqualTo(expectedResult);
}
}
Loading…
Cancel
Save