public static void main(String[] args) { Scanner in = new Scanner(System.in); // Capture user input Player[] players = getBlankPlayers(in); // create colleciton of players boolean seeDice = seeDice(in); // Do we want to see dice? boolean seeScore = seeScore(in); // Do we want to see the score? int diceSize = getDiceSides(in); // how many sides (6-26)? // Instantiate the environment Bunco b = new Bunco(diceSize, players, seeDice, seeScore); // Fill in all the player-names (previously left blank) getNames(players, b, in); b.play(); // Play the entire game System.out.println(b); // print stats }
/* * Fills the players with name references * duplicate names are not allowed, case sensitive */ static void getNames(Player[] players, Bunco b, Scanner in) { int count = 0; boolean dup = false; while (count < players.length) { dup = false; System.out.print("Please enter player " + (count + 1) + "'s name: "); String lineInput = in.nextLine(); Player p = b.player(lineInput); /* * in the event of duplicate users, * warn the user and loop until the name * provided is useable */ for (int i = 0; i < count; i++) { if (players[i].equals(p)) { dup = true; break; } } if (!dup) { players[count] = p; count++; } else { System.out.println("The name is already taken"); } } }