// 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"); } }
// Change amount of rolls per player. private void ChangeAmountOfRolls(Player player) { UtilityClass.YellowText("Enter how many rolls you want pr. turn:\n"); AmountOfRolls = Convert.ToInt32(Console.ReadLine()); player.PlayerRolls = AmountOfRolls; UtilityClass.GreenText($"You now have {AmountOfRolls} rolls pr. turn.\n"); }
// Assigns bonus points to scoreboard, if total sum is above 63 in upper section. private void Bonus() { if (!(TotalSum() >= 63)) { return; } Scoreboard.Add("Bonus", 50); UtilityClass.GreenText("You got 50 bonus points, because you got over 63 points in the upper section!\n"); }
// Ends game after each player has played 15 rounds, and displays users scores ranked. private bool GameEnd() { if (RoundNumber != 15) { return(false); } var rankedScores = Players.OrderByDescending(player => player.TotalSum()).ToList(); int ranking = 1; foreach (Player player in rankedScores) { UtilityClass.GreenText($"{ranking}. {player}: {player.TotalSum()} points\n"); ranking++; } return(true); }
// Split player input into index numbers of dice to hold. private static void Hold(Player player) { try { UtilityClass.YellowText( "Type in the dice you want to hold in the format '1,2,3' where 1 marks the most left dice in the list.\n"); List <int> diceToHold = Console.ReadLine().Split(',').Select(int.Parse).ToList(); foreach (int dice in diceToHold) { player.DiceList.ElementAt(dice - 1).HoldState = true; } UtilityClass.GreenText("Sucess!\n"); } catch (Exception e) { Console.WriteLine(e.Message); } }
// 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"); }
// 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; } }