Browse Source

Refactoring

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

22
src/main/java/Gameboard.java

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

7
src/test/java/GameboardTest.java

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

Loading…
Cancel
Save