You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
9.1 KiB

import java.util.Arrays;
import java.util.Iterator;
public class Gameboard {
int[] board;
static String RED = "\u001b[31;1m";
static String BLUE = "\u001b[34;1m";
static String YELLOW = "\u001b[33;1m";
static String GREEN = "\u001b[32;1m";
static String RESET = "\u001b[0m";
public Gameboard() {
board = new int[56];
}
public void initGameboard (){
for(int i = 0; i < 56; i++) {
if ( i % 10 == 0) {
board[i] = 1;
}
if( i % 10 == 9) {
board[i] = 2;
}
}
for (int i = 40; i < board.length; i++) {
board[i] = 3;
}
}
public String printBoard(Game g, Player p, int dice) {
String[] f = getFiguresOnBoard(g);
String[] d = getDice(dice);
String color = "";
switch (p.name) {
case "Rot" -> color = RED;
case "Blau" -> color = BLUE;
case "Gelb" -> color = YELLOW;
case "Grün" -> color = GREEN;
}
return "" +
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 +
" +---+ "+ YELLOW +" +---+ "+ RESET +" +---+\n" +
" | "+ f[16] +" | "+ YELLOW +" | "+ f[49] + YELLOW +" | "+ RESET +" | "+ f[22] +" |\n" +
" +---+ "+ YELLOW +" +---+ "+ RESET +" +---+\n" +
" +---+ "+ YELLOW +" +---+ "+ RESET +" +---+\n" +
" | "+ f[15] +" | "+ YELLOW +" | "+ f[50] + YELLOW +" | "+ RESET +" | "+ f[23] +" |\n" +
" +---+ "+ YELLOW +" +---+ "+ RESET +" +---+\n" +
"+---+ +---+ +---+ +---+ +---+ "+ YELLOW +" +---+ "+ RESET +" +---+ +---+ +---+ +---+ +---+ \n" +
"| "+ f[10] +" | | "+ f[11] +" | | "+ f[12] +" | | "+ f[13] +" | | "+ f[14] +" | "+ YELLOW +" | "+ f[51] +" | "+ RESET +" | "+ f[24] +" | | "+ f[25] +" | | "+ f[26] +" | | "+ f[27] +" | | "+ f[28] +" | \n" +
"+---+ +---+ +---+ +---+ +---+ "+ YELLOW +" +---+ "+ RESET +" +---+ +---+ +---+ +---+ +---+ \n" +
"+---+ "+ BLUE +" +---+ +---+ +---+ +---+ "+ GREEN +"+---+ +---+ +---+ +---+ "+ RESET +" +---+ \n" +
"| "+ f[9] +" | "+ BLUE +" | "+ f[44] + BLUE +" | | "+ f[45] + BLUE + " | | "+ f[46] + BLUE + " | | "+ f[47] + BLUE +" | "+ GREEN +" | "+ f[55] + GREEN + " | | "+ f[54] + GREEN +" | | "+ f[53] + GREEN +" | | "+ f[52] + GREEN +" | "+ RESET +" | "+ f[29] +" | \n" +
"+---+ "+ BLUE +" +---+ +---+ +---+ +---+ "+ GREEN +"+---+ +---+ +---+ +---+ "+ RESET +" +---+ \n" +
"+---+ +---+ +---+ +---+ +---+ "+ RED +" +---+ "+ RESET +" +---+ +---+ +---+ +---+ +---+ \n" +
"| "+ f[8] +" | | "+ f[7] +" | | "+ f[6] +" | | "+ f[5] +" | | "+ f[4] +" | "+ RED +" | "+ f[43] + RED +" | "+ RESET +" | "+ f[34] +" | | "+ f[33] +" | | "+ f[32] +" | | "+ f[31] +" | | "+ f[30] +" | \n" +
"+---+ +---+ +---+ +---+ +---+ "+ RED +" +---+ "+ RESET +" +---+ +---+ +---+ +---+ +---+ \n" +
" +---+ "+ RED +" +---+ "+ RESET +" +---+\n" +
" | "+ f[3] +" | "+ RED +" | "+ f[42] + RED +" | "+ RESET +" | "+ f[35] +" |\n" +
" +---+ "+ RED +" +---+ "+ RESET +" +---+\n" +
" +---+ "+ RED +" +---+ "+ RESET +" +---+\n" +
" | "+ f[2] +" | "+ RED +" | "+ f[41] + RED +" | "+ RESET +" | "+ f[36] +" |\n" +
" +---+ "+ RED +" +---+ "+ RESET +" +---+\n" +
RED +"+---+ +---+"+ RESET +" +---+ "+ RED +" +---+ "+ RESET +" +---+ "+ GREEN +"+---+ +---+\n" +
RED +"| "+ f[56] + RED +" | | "+ f[57] + RED +" |"+ RESET +" | "+ f[1] +" | "+ RED +" | "+ f[40] + RED +" | "+ RESET +" | "+ f[37] +" | "+ GREEN +"| "+ f[68] + GREEN +" | | "+ f[69] + GREEN +" |\n" +
RED +"+---+ +---+"+ RESET +" +---+ "+ RED +" +---+ "+ RESET +" +---+ "+ GREEN +"+---+ +---+\n" +
RED +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ GREEN +"+---+ +---+\n" +
RED +"| "+ f[58] + RED +" | | "+ f[59] + RED +" |"+ RESET +" | "+ f[0] +" | | "+ f[39] +" | | "+ f[38] +" | "+ GREEN +"| "+ f[70] + GREEN +" | | "+ f[71] + GREEN +" |\n" +
RED +"+---+ +---+"+ RESET +" +---+ +---+ +---+ "+ GREEN +"+---+ +---+\n" + RESET +
"===========================================================================\n" +
"Spieler " + color + p.name + RESET + " ist an der Reihe";
}
public static void main(String[] args) {
Game g = new Game();
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) {
String[] res = new String[72];
Arrays.fill(res, " ");
for (Player p : g.players) {
String color = "";
int start = 0;
switch (p.name) {
case "Rot" -> {
color = RED;
start = 56;
}
case "Blau" -> {
color = BLUE;
start = 60;
}
case "Gelb" -> {
color = YELLOW;
start = 64;
}
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) {
res[start++] = color + i + RESET;
i++;
} else {
start++;
res[f.getPosition()] = color + i + RESET;
i++;
}
}
}
return res;
}
}