Kniffel/fassade/KniffelSystem.java

82 lines
2.2 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 LeaderBaordData(){
return "Leaderboard - TODO \n";
}
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
}
public void createTestPlayers(int amountPlayer){
String[] names = {"Vic", "Natja", "Lilli", "Emelie", "Esra", "Oli"};
for (int i = 0; i < amountPlayer; i++){
addPlayer(i+1, names[i]);
}
}
public void rollDice(int amountRolls){
for (int i = 0; i < amountRolls; i++){
System.out.println(game.rollDice());
}
}
// TEST
public String[] getAllPlayerStrings(){
ArrayList<Player> players = game.getPlayers();
String[] returnStrings = new String[players.size()];
for (int i = 0; i < players.size(); i++){
returnStrings[i] = players.get(i).toString();
}
return returnStrings;
}
}