Browse Source

Refactoring

AIPlayer
FelixKrull 3 years ago
parent
commit
bf9d29158b
  1. 24
      src/main/java/Gameboard.java
  2. 7
      src/test/java/GameboardTest.java

24
src/main/java/Gameboard.java

@ -29,8 +29,7 @@ public class Gameboard {
public String printBoard(Game g) {
String[] f;
f = getFiguresOnBoard(g);
String[] f = getFiguresOnBoard(g);
return "" +
BLUE +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ YELLOW +"+---+ +---+\n" +
BLUE +"| "+ f[60] + BLUE +" | | "+ f[61] + BLUE +" |"+ RESET +" | "+ f[18] +" | | "+ f[19] +" | | "+ f[20] +" | "+ YELLOW +"| "+ f[64] +" | | "+ f[65] +" |\n" +
@ -75,29 +74,32 @@ public class Gameboard {
public String[] getFiguresOnBoard(Game g) {
String[] res = new String[72];
Arrays.fill(res, " ");
Iterator<Player> pIt = g.players.iterator();
while(pIt.hasNext()) {
Player p = pIt.next();
String color = new String();
for (Player p : g.players) {
String color = "";
int start = 0;
if(p.name.equals("Rot")) {
switch (p.name) {
case "Rot" -> {
color = RED;
start = 56;
} else if (p.name.equals("Blau")) {
}
case "Blau" -> {
color = BLUE;
start = 60;
} else if (p.name.equals("Gelb")) {
}
case "Gelb" -> {
color = YELLOW;
start = 64;
} else if (p.name.equals("Grün")) {
}
case "Grün" -> {
color = GREEN;
start = 68;
}
}
Iterator<Figure> figureIt = p.figures.iterator();
int i = 1;
while (figureIt.hasNext()) {
Figure f = figureIt.next();
if(f.getPosition() == -1) {
if (f.getPosition() == -1) {
res[start++] = color + i + RESET;
i++;
} else {

7
src/test/java/GameboardTest.java

@ -34,9 +34,6 @@ public class GameboardTest {
@Test
void checkGameboardFilled() {
int[] expectedGameboard = new int[56];
for(int i = 0; i < expectedGameboard.length; i++) {
expectedGameboard[i] = 0;
}
int [] givenGameboard = gb.board;
assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard);
@ -73,9 +70,7 @@ public class GameboardTest {
Iterator<Integer> posIt = positions.iterator();
while(pIt.hasNext()) {
Player p = pIt.next();
Iterator<Figure> figureIt = p.figures.iterator();
while (figureIt.hasNext()) {
Figure f = figureIt.next();
for (Figure f : p.figures) {
f.setPosition(posIt.next());
}
}

Loading…
Cancel
Save