Browse Source

Refactor Player toString

AIPlayer
Jonas Wagner 3 years ago
parent
commit
d1ee446cc4
  1. 4
      src/main/java/Game.java
  2. 5
      src/main/java/Player.java
  3. 7
      src/test/java/PlayerTest.java

4
src/main/java/Game.java

@ -15,7 +15,7 @@ public class Game {
for (Player p : g.players) {
int c = 0;
int dice;
System.out.println("Spieler " + p.toString() + " an der Reihe.");
System.out.println("Spieler " + p.name + " an der Reihe.");
do {
int figId;
dice = p.rollDice();
@ -32,7 +32,7 @@ public class Game {
} while (g.checkDice(dice, p, c));
if(p.checkGameWin(p.figures)) {
winner = p;
System.out.println("Spieler " + winner.toString() + " gewinnt!");
System.out.println("Spieler " + winner.name + " gewinnt!");
exit(42);
}
}

5
src/main/java/Player.java

@ -20,11 +20,6 @@ public class Player {
}
}
@Override
public String toString() {
return name;
}
public int rollDice() {
return (int) (Math.random() * 6 + 1);
}

7
src/test/java/PlayerTest.java

@ -25,13 +25,6 @@ public class PlayerTest {
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;

Loading…
Cancel
Save