static void PlayYahtzee() { // variables int fieldValue = 0; Random rnd = new Random(); Console.Clear(); // make dice Dice dice = new Dice(); // roll dice - using a random value to facilitate a loop of rolling the dice to effectively simulate the "rolling" of the dice for (int i = 0; i < rnd.Next(5, 15); i++) { System.Threading.Thread.Sleep(100); Console.Clear(); dice.RollDice(rnd); for (int j = 0; j < dice.GameDice.Length; j++) { Console.Write("{0, 5}", dice.GameDice[j]); } Console.WriteLine(""); Console.WriteLine(""); } Console.WriteLine("--------------------------------------------------"); // calculate and show total of 1s, if applicable fieldValue = dice.CalcX(1); if (fieldValue > 0) { Console.WriteLine("Value for 1s = {0}", fieldValue); } // calculate and show total of 2s, if applicable fieldValue = dice.CalcX(2); if (fieldValue > 0) { Console.WriteLine("Value for 2s = {0}", fieldValue); } // calculate and show total of 3s, if applicable fieldValue = dice.CalcX(3); if (fieldValue > 0) { Console.WriteLine("Value for 3s = {0}", fieldValue); } // calculate and show total of 4s, if applicable fieldValue = dice.CalcX(4); if (fieldValue > 0) { Console.WriteLine("Value for 4s = {0}", fieldValue); } // calculate and show total of 5s, if applicable fieldValue = dice.CalcX(5); if (fieldValue > 0) { Console.WriteLine("Value for 5s = {0}", fieldValue); } // calculate and show total of 6s, if applicable fieldValue = dice.CalcX(6); if (fieldValue > 0) { Console.WriteLine("Value for 6s = {0}", fieldValue); } Console.WriteLine(""); // calculate and show total of 3 of a kind, if applicable fieldValue = dice.CalcXOfAKind(3); if (fieldValue > 0) { Console.WriteLine("Value for 3 of a kind = {0}", fieldValue); } // calculate and show total of 4 of a kind, if applicable fieldValue = dice.CalcXOfAKind(4); if (fieldValue > 0) { Console.WriteLine("Value for 4 of a kind = {0}", fieldValue); } // calculate and show total of full house, if applicable fieldValue = dice.CalcFullHouse(); if (fieldValue > 0) { Console.WriteLine("Value for full house = {0}", fieldValue); } // calculate and show total of small straight, if applicable fieldValue = dice.CalcStraight(false); if (fieldValue > 0) { Console.WriteLine("Value for small straight = {0}", fieldValue); } // calculate and show total of large straight, if applicable fieldValue = dice.CalcStraight(true); if (fieldValue > 0) { Console.WriteLine("Value for large straight = {0}", fieldValue); } // calculate and show total of yahtzee (5 of a kind), if applicable fieldValue = dice.CalcXOfAKind(5); if (fieldValue > 0) { Console.WriteLine("YAHTZEE!!! = {0}", fieldValue); } // calculate and show total of chance (total of all dice) fieldValue = dice.CalcChance(); if (fieldValue > 0) { Console.WriteLine("Value for chance = {0}", fieldValue); } Console.WriteLine("--------------------------------------------------"); Console.WriteLine(""); Console.WriteLine("[ press enter to continue ... ]"); Console.ReadLine(); Console.Clear(); }
public void Run() { for (int round = 1; round <= 13; round++) { int numRerolls = 0; Boolean[] roll = { true, true, true, true, true }; Boolean reload = false; Boolean invalidInput; Console.Clear(); Console.WriteLine($"--- Round {round} ---\n"); do { dice.RollDice(ref roll); CalculatePoints(); PrintRoundCard(categories); // get user input if (numRerolls < 2) { do { invalidInput = false; Console.WriteLine("Select a category, pick the dice to re-roll (Ex. 1,2,3) or \"show\" for score-card"); Console.Write("Choice (<category>/#,#,#/show):"); String input = Console.ReadLine(); if (input.Equals("show")) { ShowScoreCard(false); reload = true; } else { Boolean canParse = false; String[] inputs = input.Split(','); if (inputs.Length <= 3) { foreach (String inp in inputs) { canParse = int.TryParse(inp, out int dieToReroll); if (canParse) { reload = true; if (dieToReroll < 6 && dieToReroll > 0) { roll[dieToReroll - 1] = true; } else { canParse = false; break; } } } } if (canParse) { numRerolls++; Console.Clear(); } else { Boolean found = StoreCat(input); if (!found) { ErrorMessage(); invalidInput = true; } reload = false; } } } while (invalidInput); } else { reload = false; bool found; do { Console.Write("Select a category to take the points:"); String input = Console.ReadLine(); found = StoreCat(input); if (!found) { Console.WriteLine("Invalid category or category already taken"); } } while (!found); } } while (reload); } // game over ShowScoreCard(true); }