// 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"); } }
// Change bias of input by selecting bias and bias percentage. private void Bias(Player player) { UtilityClass.YellowText( "Change the bias of your dice, type in a number: \n1: Lucky dice.\n0: Fair dice.\n-1: Unfair dice.\n"); int bias = Convert.ToInt32(Console.ReadLine()); int weight = 1; if (bias != 0) { UtilityClass.YellowText( "Great! How biased do you want to be? It gets pretty exciting at 10 or above.\n"); weight = Convert.ToInt32(Console.ReadLine()); } for (int i = 0; i < player.DiceList.Count(); i++) { player.DiceList[i] = new BiasedDice(bias, weight); } UtilityClass.GreenText("You successfully changed the bias of the dice!\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; } }