コード例 #1
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
        // 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");
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
 // 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");
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
 // Display command options.
 private void Help()
 {
     UtilityClass.YellowText("\nHey, looks like you are having some trouble. " +
                             "\nHere is a series of commands that can be used at all times during the game." +
                             "\n 'roll' to roll all your dice, which has not been marked with 'hold'." +
                             "\n 'help' to get this message shown." + "\n 'score' to display your scoreboard." +
                             "\n 'save' to view the current possibilities of adding scores and assigning them." +
                             "\n 'hold' to select dice you want to hold for the next roll." +
                             "\n 'more' to change the amount of rolls per round for a player." +
                             "\n 'release' to release all dice that are marked with 'hold'." +
                             "\n 'drop' to drop a score, if it is not possible to assign one." +
                             "\n 'bias' to change the bias of a players rolls." +
                             "\n 'exit' to exit the game completely\n ");
 }
コード例 #4
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
        // Manages rounds and player turns, as well as resetting for next rounds/turns for each player.
        private void NewRound()
        {
            // A Round
            foreach (Player player in Players)
            {
                UtilityClass.YellowText($"\n{player}'s turn.\n");
                player.PlayerRolls = AmountOfRolls;
                player.CheckIfUpperSectionDone();
                Release(player);
                // A Turn
                while (player.PlayerTurn)
                {
                    ReadLine(player);
                }

                player.PlayerTurn = true;
            }
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
        // 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);
            }
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
        // 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");
            }
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
        // 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");
        }
コード例 #8
0
ファイル: Game.cs プロジェクト: simoneliasen/Yahtzy
        // 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;
            }
        }