55 lines
1.5 KiB
Java
55 lines
1.5 KiB
Java
package fassade;
|
|
|
|
import domain.Game;
|
|
import domain.Player;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Random;
|
|
|
|
public class KniffelSystem {
|
|
ArrayList<String> playerColors;
|
|
Game game;
|
|
public KniffelSystem(){
|
|
game = new Game();
|
|
playerColors = new ArrayList<>(Arrays.asList(
|
|
"\u001B[31m", // Quelle 2 Anfang
|
|
"\u001B[32m", //
|
|
"\u001B[34m", //
|
|
"\u001B[33m", //
|
|
"\u001B[36m")); // Quelle 2 Ende
|
|
}
|
|
|
|
|
|
public String scorebaordData(){
|
|
return "Scoreboard - TODO";
|
|
}
|
|
|
|
|
|
public String addPlayer(int playerNumber, String name) {
|
|
String playerColor = colorPicker(playerNumber);
|
|
Player playerToAdd = new Player(playerNumber, name, playerColor, 0);
|
|
game.addPlayer(playerToAdd);
|
|
|
|
return changePlayerNameColor(name, playerColor);
|
|
}
|
|
|
|
|
|
private String changePlayerNameColor(String name, String color){
|
|
String ANSI_RESET = "\u001B[0m";
|
|
|
|
return String.format(color + name + ANSI_RESET);
|
|
}
|
|
|
|
|
|
private String colorPicker(int playerNumber){
|
|
if (playerNumber == 1){
|
|
return "\u001B[35m"; // Quelle 2
|
|
}
|
|
|
|
Random rand = new Random(); // Quelle 1 Anfang
|
|
int randomIndex = rand.nextInt(playerColors.size()); //
|
|
return playerColors.remove(randomIndex); // Quelle 1 Ende
|
|
}
|
|
}
|