public void throwAllDice() { //create a 5 dice Random randomiser = new Random(); DieClass[] playersDice = new DieClass[5]; //roll dice 5 times for (int i = 0; i < 5; i++) { playersDice[i] = new DieClass(randomiser); playersDice[i].roll(); int numberRolled = playersDice[i].returnTopNumber(); numbersList.Add(numberRolled); numberAppearances[numberRolled]++; Console.WriteLine("Players Rolled: {0}", numberRolled); } //print what player got if (numberAppearances.Contains(2)) { Console.WriteLine("Rolled a 2 of a kind!"); } else if (numberAppearances.Contains(3)) { Console.WriteLine("Rolled a 3 of a kind!"); } else if (numberAppearances.Contains(4)) { Console.WriteLine("Rolled a 4 of a kind!"); } else if (numberAppearances.Contains(5)) { Console.WriteLine("Rolled a 5 of a kind!"); } }
public int newGame() { //create playerscore and set to 0 int playerScore = 0; int playerInput; try { Console.WriteLine("Would you like to: 1. Throw each dice once at a time 2. Throw all at once"); playerInput = Convert.ToInt32(Console.ReadLine()); switch (playerInput) { case 1: //create dice Random randomiser = new Random(); DieClass[] playersDice = new DieClass[5]; //for loop which rolls dice 5 times for (int i = 0; i < 5; i++) { playersDice[i] = new DieClass(randomiser); playersDice[i].roll(); int numberRolled = playersDice[i].returnTopNumber(); numbersList.Add(numberRolled); numberAppearances[numberRolled]++; Console.WriteLine("Players Rolled: {0}", numberRolled); Console.ReadLine(); } if (numberAppearances.Contains(2)) { Console.WriteLine("Rolled a 2 of a kind!"); } else if (numberAppearances.Contains(3)) { Console.WriteLine("Rolled a 3 of a kind!"); } else if (numberAppearances.Contains(4)) { Console.WriteLine("Rolled a 4 of a kind!"); } else if (numberAppearances.Contains(5)) { Console.WriteLine("Rolled a 5 of a kind!"); } //sets player score playerScore = pointsMethod(numberAppearances, playerScore); //prints dice roll history statsClass.diceRollHistory(numbersList); //prints out stats Console.WriteLine("\n\nAll Dice In Game Statistics:\nAverage {0}", statsClass.averageNumberRolled(numbersList)); Console.WriteLine("Sum: {0}\n", statsClass.sumOfDice(numbersList)); //clears the frequency array so it can be used again with it being empty. Array.Clear(numberAppearances, 0, numberAppearances.Length); break; case 2: //calling throwAllDice method throwAllDice(); //getting players score and multiply by two because they rolled all at once playerScore = (pointsMethod(numberAppearances, playerScore)) * 2; statsClass.diceRollHistory(numbersList); Console.WriteLine("\n\nAll Dice In Game Statistics\nAverage: {0}", statsClass.averageNumberRolled(numbersList)); Console.WriteLine("Sum: {0}\n", statsClass.sumOfDice(numbersList)); Array.Clear(numberAppearances, 0, numberAppearances.Length); break; } } //catches format errors when user inputs a key catch (FormatException) { Console.WriteLine("Please Enter A valid key"); } return(playerScore); }