6 Commits

  1. 17
      src/main/java/Game.java
  2. 76
      src/main/java/Gameboard.java

17
src/main/java/Game.java

@ -11,17 +11,18 @@ public class Game {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
Game g = new Game(); Game g = new Game();
Player winner; Player winner;
clearScreen();
while(true){ while(true){
for (Player p : g.players) { for (Player p : g.players) {
int c = 0; int c = 0;
int dice; int dice;
System.out.println(g.printGameboard(g, p));
do { do {
clearScreen();
int figId; int figId;
dice = p.rollDice(); dice = p.rollDice();
TimeUnit.SECONDS.sleep(1L);
System.out.println("Würfel: " + dice);
System.out.println(g.printGameboard(g,p,dice));
TimeUnit.MILLISECONDS.sleep(600L);
System.out.println("Würfel: "+ dice);
TimeUnit.MILLISECONDS.sleep(600L);
c++; c++;
ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g); ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g);
if(usableFigures.size() > 0) { if(usableFigures.size() > 0) {
@ -30,7 +31,7 @@ public class Game {
} while(figId == -1); } while(figId == -1);
g.setFigure(figId, dice, p, g); g.setFigure(figId, dice, p, g);
clearScreen(); clearScreen();
System.out.println(g.printGameboard(g, p));
System.out.println(g.printGameboard(g,p,dice));
} }
} while (g.checkDice(dice, p, c, g)); } while (g.checkDice(dice, p, c, g));
if(p.checkGameWin(p.figures)) { if(p.checkGameWin(p.figures)) {
@ -38,8 +39,6 @@ public class Game {
System.out.println("Spieler " + winner.name + " gewinnt!"); System.out.println("Spieler " + winner.name + " gewinnt!");
exit(42); exit(42);
} }
TimeUnit.SECONDS.sleep(1L);
clearScreen();
} }
} }
} }
@ -54,8 +53,8 @@ public class Game {
players.add(new Player("Grün",30, 52, 29)); players.add(new Player("Grün",30, 52, 29));
} }
public String printGameboard(Game g, Player p) {
return gb.printBoard(g, p);
public String printGameboard(Game g, Player p, int dice) {
return gb.printBoard(g, p, dice);
} }
public static void clearScreen() { public static void clearScreen() {

76
src/main/java/Gameboard.java

@ -28,8 +28,9 @@ public class Gameboard {
} }
public String printBoard(Game g, Player p) {
public String printBoard(Game g, Player p, int dice) {
String[] f = getFiguresOnBoard(g); String[] f = getFiguresOnBoard(g);
String[] d = getDice(dice);
String color = ""; String color = "";
switch (p.name) { switch (p.name) {
case "Rot" -> color = RED; case "Rot" -> color = RED;
@ -38,11 +39,11 @@ public class Gameboard {
case "Grün" -> color = GREEN; case "Grün" -> color = GREEN;
} }
return "" + return "" +
BLUE +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ YELLOW +"+---+ +---+\n" +
BLUE +"| "+ f[60] + BLUE +" | | "+ f[61] + BLUE +" |"+ RESET +" | "+ f[18] +" | | "+ f[19] +" | | "+ f[20] +" | "+ YELLOW +"| "+ f[64] + YELLOW + " | | "+ f[65] + YELLOW +" |\n" +
BLUE +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ YELLOW +"+---+ +---+\n" +
BLUE +"+---+ +---+"+ RESET +" +---+ "+ YELLOW +"+---+"+ RESET +" +---+ "+ YELLOW +"+---+ +---+\n" +
BLUE +"| "+ f[62] + BLUE + " | | "+ f[63] + BLUE +" |"+ RESET +" | "+ f[17] +" | "+ YELLOW +" | "+ f[48] + YELLOW +" | "+ RESET +" | "+ f[21] +" | "+ YELLOW +"| "+ f[66] + YELLOW +" | | "+ f[67] + YELLOW +" |\n" +
BLUE +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ YELLOW +"+---+ +---+"+ RESET +" ---------\n" +
BLUE +"| "+ f[60] + BLUE +" | | "+ f[61] + BLUE +" |"+ RESET +" | "+ f[18] +" | | "+ f[19] +" | | "+ f[20] +" | "+ YELLOW +"| "+ f[64] + YELLOW + " | | "+ f[65] + YELLOW +" | "+ RESET + " | "+ d[0] +" "+ d[1] +" "+ d[2] +" |\n" +
BLUE +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ YELLOW +"+---+ +---+"+ RESET +" | "+ d[3] +" |\n" +
BLUE +"+---+ +---+"+ RESET +" +---+ "+ YELLOW +"+---+"+ RESET +" +---+ "+ YELLOW +"+---+ +---+"+ RESET +" | "+d[4]+" "+d[5]+" "+d[6]+" |\n" +
BLUE +"| "+ f[62] + BLUE + " | | "+ f[63] + BLUE +" |"+ RESET +" | "+ f[17] +" | "+ YELLOW +" | "+ f[48] + YELLOW +" | "+ RESET +" | "+ f[21] +" | "+ YELLOW +"| "+ f[66] + YELLOW +" | | "+ f[67] + YELLOW +" | "+ RESET +" ---------\n" +
BLUE +"+---+ +---+"+ RESET +" +---+ "+ YELLOW +"+---+"+ RESET +" +---+ "+ YELLOW +"+---+ +---+\n" + RESET + BLUE +"+---+ +---+"+ RESET +" +---+ "+ YELLOW +"+---+"+ RESET +" +---+ "+ YELLOW +"+---+ +---+\n" + RESET +
" +---+ "+ YELLOW +" +---+ "+ RESET +" +---+\n" + " +---+ "+ YELLOW +" +---+ "+ RESET +" +---+\n" +
" | "+ f[16] +" | "+ YELLOW +" | "+ f[49] + YELLOW +" | "+ RESET +" | "+ f[22] +" |\n" + " | "+ f[16] +" | "+ YELLOW +" | "+ f[49] + YELLOW +" | "+ RESET +" | "+ f[22] +" |\n" +
@ -77,7 +78,68 @@ public class Gameboard {
public static void main(String[] args) { public static void main(String[] args) {
Game g = new Game(); Game g = new Game();
System.out.println(g.gb.printBoard(g, g.players.get(0)));
System.out.println(g.gb.printBoard(g, g.players.get(0), 6));
}
public String[] getDice (int dice) {
String[] res = new String[7];
switch (dice) {
case 1 -> {
res[0] = " ";
res[1] = " ";
res[2] = " ";
res[3] = "o";
res[4] = " ";
res[5] = " ";
res[6] = " ";
}
case 2 -> {
res[0] = "o";
res[1] = " ";
res[2] = " ";
res[3] = " ";
res[4] = " ";
res[5] = " ";
res[6] = "o";
}
case 3 -> {
res[0] = "o";
res[1] = " ";
res[2] = " ";
res[3] = "o";
res[4] = " ";
res[5] = " ";
res[6] = "o";
}
case 4 -> {
res[0] = "o";
res[1] = " ";
res[2] = "o";
res[3] = " ";
res[4] = "o";
res[5] = " ";
res[6] = "o";
}
case 5 -> {
res[0] = "o";
res[1] = " ";
res[2] = "o";
res[3] = "o";
res[4] = "o";
res[5] = " ";
res[6] = "o";
}
case 6 -> {
res[0] = "o";
res[1] = "o";
res[2] = "o";
res[3] = " ";
res[4] = "o";
res[5] = "o";
res[6] = "o";
}
}
return res;
} }
public String[] getFiguresOnBoard(Game g) { public String[] getFiguresOnBoard(Game g) {

Loading…
Cancel
Save