public PlayerUserControl(BonesPlayer player)
        {
            InitializeComponent();

            this.player = player;
            BuildGui(); // Build the Gui
        }
예제 #2
0
        /// <summary>
        /// Calculates the score for a player.
        /// </summary>
        /// <param name="player">The Player you wish to calculate the score for.</param>
        /// <returns>The score that the Player has.</returns>
        private void calculateScoreForPlayer(BonesPlayer player)
        {
            // reset the score.
            player.Score = 0;

            // Step 1:
            // Count all the sides on the dice.

            // holds the count of each dice side
            int[] countOfDice = new int[AmountOfSidesOnDice];

            // loop through all the dice the player has rolled
            for (int i = 0; i < player.Dice.Length; ++i)
            {
                countOfDice[player.Dice[i].Value]++;
            }

            // Step 2:
            // Calculate the Score.

            // if the player doesn't have a 6 in his hand
            if (countOfDice[5] < 1)
            {
                // then we'll calculate the score
                double[] pointStructure = { 0, 0, 1.5, 2, 3, 5, 10 };
                int[] scoringTable = { 1, 3, -1, -3, 5 }; // holds the scoring table

                // loop through the count of all the dice
                // i represents the current dice side
                // whereas the value in the countOfDice array
                // is how many sides appeared on the player's roll.
                for (int i = 0; i < countOfDice.Length; ++i)
                {
                    if (i < scoringTable.Length)
                    {
                        player.Score += scoringTable[i] * pointStructure[countOfDice[i]];
                    }
                }
            }
            // otherwise, he has lost everything
            else
            {
                if (player.Score > 0)
                {
                    player.Score = 0;
                }
            }
        }