// Display scores that the player can drop and drop them based on user input. private void DropScore(Player player) { UtilityClass.YellowText("What score do you want to drop? \nType the number you want to drop.\n"); var droppableScores = new Dictionary <int, string>(); for (int index = player.Scoreboard.Count - 1; index >= 0; index--) { (string scoreName, int?score) = player.Scoreboard.ElementAt(index); if (player.Scoreboard[scoreName] != null) { continue; } UtilityClass.GreenText($"{index + 1}. {scoreName}\n"); droppableScores.Add(index, scoreName); } try { int input = Convert.ToInt32(Console.ReadLine()); if (!droppableScores.ContainsKey(input - 1)) { return; } string nameOfScore = droppableScores[input - 1]; player.Scoreboard[nameOfScore] = 0; player.PlayerTurn = false; } catch (Exception e) { UtilityClass.RedText(e.Message + "\n"); } UtilityClass.GreenText("Success!\n"); }
// Check if upper section scores are possible, and assign by userInput. private void UpperSectionScores(Player player) { // Check if Assignment of score is possible for (int index = 0; index < player.Scoreboard.Count; index++) { var(scorename, score) = player.Scoreboard.ElementAt(index); if (player.Scoreboard[scorename] == null && (player.DiceList.Any(x => x.DiceValue.Equals(index + 1)))) { UtilityClass.GreenText($"{index + 1}. {scorename}{score}\n"); } } try { // Assign score if player input matches assignable score. int playerInput = Convert.ToInt32(Console.ReadLine()); for (int index = 0; index < player.Scoreboard.Count; index++) { (string scorename, int?score) = player.Scoreboard.ElementAt(index); if (playerInput != (index + 1) || (!player.DiceList.Any(x => x.DiceValue.Equals(index + 1)))) { continue; } { player.Scoreboard[scorename] = player.DiceList.Count(x => x.DiceValue.Equals(index + 1)) * (index + 1); player.PlayerTurn = false; Console.Clear(); } } } catch (Exception e) { UtilityClass.RedText(e.Message + "\n"); } }
//Roll players dice. internal void Roll() { if (PlayerRolls != 0) { foreach (Dice dice in DiceList) { dice.Roll(); switch (dice.HoldState) { case true: UtilityClass.RedText($"{dice.DiceValue} "); break; default: Console.Write($"{dice.DiceValue} "); break; } } PlayerRolls--; } else if (PlayerRolls == 0) { foreach (Dice dice in DiceList) { Console.Write($"{dice.DiceValue} "); } } Console.WriteLine("\n---------------------------"); Console.Write($"{PlayerRolls} rolls left\n"); Console.WriteLine("---------------------------"); }
// Instantiate player objects, based on input. internal void SetupGame() { UtilityClass.YellowText( "Hey, let's play some yahtzy! \nType 'help' to see all available commands.\n\nHow many players?\n"); try { int amountOfPlayers = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < amountOfPlayers; i++) { UtilityClass.GreenText($"\nWhat is player {i + 1}'s name?\n"); Players.Add(new Player(Console.ReadLine())); } StartGame(); } catch (Exception e) { UtilityClass.RedText(e.Message + "\n"); } }
// Collection of player commands. private void ReadLine(Player player = null) { switch (Console.ReadLine()) { case "roll": Console.Clear(); Score(player); player.Roll(); player.OccurrencesOfDice(); break; case "help": Help(); break; case "score": Score(player); break; case "hold": Hold(player); break; case "exit": Exit(); break; case "save": UtilityClass.YellowText( "These are the scores you can save to, write the number of where you want to save your points eg. '1'\n"); if (player.UpperSection) { UpperSectionScores(player); } else { LowerSectionScores(player); } break; case "release": Release(player); break; case "drop": DropScore(player); break; case "bias": Bias(player); break; case "more": ChangeAmountOfRolls(player); break; default: UtilityClass.RedText("Unavailable command type 'help' to get a list of the available commands\n"); break; } }
// Check if scores are possible in lower section, and assign based on players input. private void LowerSectionScores(Player player) { // See if score is more than 1 in each score scenario, if it is write to the console. if (player.Scoreboard.ContainsKey("One Pair") && player.Scoreboard["One Pair"] == null && player.OnePair() >= 1) { UtilityClass.GreenText("1. One Pair\n"); } if (player.Scoreboard.ContainsKey("Two Pairs") && player.Scoreboard["Two Pairs"] == null && player.TwoPairs() >= 1) { UtilityClass.GreenText("2. Two Pairs\n"); } if (player.Scoreboard.ContainsKey("Three Of A Kind") && player.Scoreboard["Three Of A Kind"] == null && player.ThreeOfAKind() >= 1) { UtilityClass.GreenText("3. Three Of A Kind\n"); } if (player.Scoreboard.ContainsKey("Four Of A Kind") && player.Scoreboard["Four Of A Kind"] == null && player.FourOfAKind() >= 1) { UtilityClass.GreenText("4. Four Of A Kind\n"); } if (player.Scoreboard.ContainsKey("Full House") && player.Scoreboard["Full House"] == null && player.FullHouse() >= 1) { UtilityClass.GreenText("5. Full House\n"); } if (player.Scoreboard.ContainsKey("Small Straight") && player.Scoreboard["Small Straight"] == null && player.SmallStraight() >= 1) { UtilityClass.GreenText("6. Small Straight\n"); } if (player.Scoreboard.ContainsKey("Large Straight") && player.Scoreboard["Large Straight"] == null && player.LargeStraight() >= 1) { UtilityClass.GreenText("7. Large Straight\n"); } if (player.Scoreboard.ContainsKey("Chance") && player.Scoreboard["Chance"] == null && player.Chance() >= 1) { UtilityClass.GreenText("8. Chance\n"); } if (player.Scoreboard.ContainsKey("Yahtzy") && player.Scoreboard["Yahtzy"] == null && player.Yahtzy() >= 1) { UtilityClass.GreenText("9. Yahtzy\n"); } // Get player input on which option to save. switch (Console.ReadLine()) { case "1": player.OnePair(true); player.PlayerTurn = false; Console.Clear(); break; case "2": player.TwoPairs(true); player.PlayerTurn = false; Console.Clear(); break; case "3": player.ThreeOfAKind(true); player.PlayerTurn = false; Console.Clear(); break; case "4": player.FourOfAKind(true); player.PlayerTurn = false; Console.Clear(); break; case "5": player.FullHouse(true); player.PlayerTurn = false; Console.Clear(); break; case "6": player.SmallStraight(true); player.PlayerTurn = false; Console.Clear(); break; case "7": player.LargeStraight(true); player.PlayerTurn = false; Console.Clear(); break; case "8": player.Chance(true); player.PlayerTurn = false; Console.Clear(); break; case "9": player.Yahtzy(true); player.PlayerTurn = false; Console.Clear(); break; default: UtilityClass.RedText( "It does not look like you have the right dice, type 'help' to explore other options.\n"); break; } }