import java.util.*; public class Player { String name; ArrayList
figures; int startPos; int startHome; int jumpToHome; Scanner scanner; public Player(String name, int startPos, int startHome, int jumpToHome) { this.name = name; this.startPos = startPos; this.startHome = startHome; this.jumpToHome = jumpToHome; figures = new ArrayList<>(); for(int i = 0; i < 4; i++) { figures.add(new Figure()); } } /** * Rolls the dice - Generates a random Number in the range of 1 - 6 * @return value of the dice */ public int rollDice() { return (int) (Math.random() * 6 + 1); } /** * Checks if a Player has won the game with the current play * @param figures figures of the current Player * @return true if Player has won */ public boolean checkGameWin(ArrayList
figures) { Iterator
it = figures.iterator(); Figure f; while(it.hasNext()) { f = it.next(); if(!(f.getPosition() >= startHome && f.getPosition() <= startHome+3)) { return false; } } return true; } /** * Checks if the Player has figures in the base (off gameboard) * @param figures figures of the current Player * @return true if there is at least one figure in the base (off gameboard) */ public int checkFigureInBase(ArrayList
figures) { Iterator
it = figures.iterator(); Figure f; int count = 0; while(it.hasNext()) { f = it.next(); if(f.getPosition() == -1) { count++; } } return count; } /** * Get the user input on witch figure the user wants to move * @param usableFigures list of usable Figures to choose from * @return int figid of the figure chosen */ public int choose(ArrayList usableFigures) { StringBuilder out = new StringBuilder("["); Iterator it = usableFigures.iterator(); for(int i = 0; i Collections.max(usableFigures) + 1 || input < Collections.min(usableFigures) + 1) { System.out.println("Die eingegebene Zahl war zu groß oder zu klein.\n" + "Bitte nur Zahlen von " + (Collections.min(usableFigures) + 1) + " bis " + (Collections.max(usableFigures) + 1) + " eingeben."); return -1; } return input - 1; } catch (Exception e) { System.out.println("Die Eingabe hat keine Zahl bekommen.\n" + "Bitte nur Zahlen von " + (Collections.min(usableFigures) + 1) + " bis " + (Collections.max(usableFigures) + 1)+ " eingeben."); return -1; } } }