Ejemplo n.º 1
0
        public Player(string name, Label[] scoreTOTALS)
        {
            this.name = name;

            // For loop will run through all the 18 ScoreType's to set the array scores[] to a value.
            for (ScoreType combo = ScoreType.Ones; combo <= ScoreType.GrandTotal; combo++)
            {
                switch (combo)
                {
                // For the ScoreType of:
                case ScoreType.Ones:
                case ScoreType.Twos:
                case ScoreType.Threes:
                case ScoreType.Fours:
                case ScoreType.Fives:
                case ScoreType.Sixes: {
                    // Instantains the scores[] array to it corresponding label and passes to its specific score class.
                    scores[(int)combo] = new CountingCombination(combo, scoreTOTALS[(int)combo]);

                    break;
                }

                // For the ScoreType of:
                case ScoreType.ThreeOfAKind:
                case ScoreType.FourOfAKind:
                case ScoreType.Chance: {
                    scores[(int)combo] = new TotalOfDice(combo, scoreTOTALS[(int)combo]);

                    break;
                }

                // For the ScoreType of:
                case ScoreType.FullHouse:
                case ScoreType.SmallStraight:
                case ScoreType.LargeStraight:
                case ScoreType.Yahtzee: {
                    scores[(int)combo] = new FixedScore(combo, scoreTOTALS[(int)combo]);

                    break;
                }

                case ScoreType.SubTotal:
                case ScoreType.SectionATotal:
                case ScoreType.SectionBTotal:
                case ScoreType.BonusFor63Plus:
                case ScoreType.YahtzeeBonus:
                case ScoreType.GrandTotal: {
                    scores[(int)combo] = new BonusOrTotal(scoreTOTALS[(int)combo]);

                    break;
                }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method for initializing the scores of a player
        /// </summary>
        /// <param name="myLabels"> Labels representing the scores </param>
        private void InitializeScoreArray(Label[] myLabels)
        {
            scores = new Score[myLabels.Length];

            foreach (ScoreType i in Enum.GetValues(typeof(ScoreType)))
            {
                switch (i)
                {
                case ScoreType.Ones:
                case ScoreType.Twos:
                case ScoreType.Threes:
                case ScoreType.Fours:
                case ScoreType.Fives:
                case ScoreType.Sixes:
                    scores[(int)i] = new CountingCombination(i, myLabels[(int)i]);
                    break;

                case ScoreType.SmallStraight:
                case ScoreType.LargeStraight:
                case ScoreType.FullHouse:
                case ScoreType.Yahtzee:
                    scores[(int)i] = new FixedScore(i, myLabels[(int)i]);
                    break;

                case ScoreType.ThreeOfAKind:
                case ScoreType.FourOfAKind:
                case ScoreType.Chance:
                    scores[(int)i] = new TotalOfDice(i, myLabels[(int)i]);
                    break;

                case ScoreType.SubTotal:
                case ScoreType.BonusFor63Plus:
                case ScoreType.SectionATotal:
                case ScoreType.SectionBTotal:
                case ScoreType.YahtzeeBonus:
                case ScoreType.GrandTotal:
                    scores[(int)i] = new BonusOrTotal(myLabels[(int)i]);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private void instantiate()
        {
            scores = new Score[scoreTotals.Length];
            for (int i = 0; i < scores.Length; i++)
            {
                switch (scoretype[i])
                {
                case ScoreType.Ones:
                case ScoreType.Twos:
                case ScoreType.Threes:
                case ScoreType.Fours:
                case ScoreType.Fives:
                case ScoreType.Sixes:
                    scores[i] = new CountingCombination(scoretype[i], scoreTotals[i]);
                    break;

                case ScoreType.SmallStraight:
                case ScoreType.LargeStraight:
                case ScoreType.FullHouse:
                case ScoreType.Yahtzee:
                    scores[i] = new FixedScore(scoretype[i], scoreTotals[i]);
                    break;

                case ScoreType.ThreeOfAKind:
                case ScoreType.FourOfAKind:
                case ScoreType.Chance:
                    scores[i] = new TotalOfDice(scoretype[i], scoreTotals[i]);
                    break;

                case ScoreType.BonusFor63Plus:
                case ScoreType.SubTotal:
                case ScoreType.SectionATotal:
                case ScoreType.YahtzeeBonus:
                case ScoreType.SectionBTotal:
                case ScoreType.GrandTotal:
                    scores[i] = new BonusOrTotal(scoreTotals[i]);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public Player(string playerName, Label[] playerScores) {
            name = playerName;
            grandTotal = 0;
            scores = new Score[19];
            for (int i = 0; i <= (int)ScoreType.GrandTotal; i++) {
                switch ((ScoreType)i) {
                    case (ScoreType.Ones):
                    case (ScoreType.Twos):
                    case (ScoreType.Threes):
                    case (ScoreType.Fours):
                    case (ScoreType.Fives):
                    case (ScoreType.Sixes):
                        scores[i] = new CountingCombination((ScoreType)i, playerScores[i]);
                        break;

                    case (ScoreType.ThreeOfAKind):
                    case (ScoreType.FourOfAKind):
                    case (ScoreType.Chance):
                        scores[i] = new TotalOfDice((ScoreType)i, playerScores[i]);
                        break;
                    case (ScoreType.FullHouse):
                    case (ScoreType.SmallStraight):
                    case (ScoreType.LargeStraight):
                    case (ScoreType.Yahtzee):
                        scores[i] = new FixedScore((ScoreType)i, playerScores[i]);
                        break;
                    case (ScoreType.SubTotal):
                    case (ScoreType.BonusFor63Plus):
                    case (ScoreType.SectionATotal):
                    case (ScoreType.YahtzeeBonus):
                    case (ScoreType.SectionBTotal):
                    case (ScoreType.GrandTotal):
                        scores[i] = new BonusOrTotal(playerScores[i]);
                        break;
                }
            }
        }//END Player
Ejemplo n.º 5
0
        /// <summary>
        /// This constructor will assign the name to the player
        /// and the labels will represent the socre totals on the GUI
        /// </summary>
        /// <param name="playerName"></param>
        /// <param name="scoreTotal"></param>
        public Player(string playerName, Label[] scoreTotal)
        {
            name = playerName;

            //instantiate score in scores array
            for (ScoreType index = ScoreType.Ones; index <= ScoreType.GrandTotal; index++)
            {
                switch (index)
                {
                case ScoreType.Ones:
                case ScoreType.Twos:
                case ScoreType.Threes:
                case ScoreType.Fours:
                case ScoreType.Fives:
                case ScoreType.Sixes:
                    scores[(int)index] = new CountingCombination(index, scoreTotal[(int)index]);
                    break;

                case ScoreType.ThreeOfAKind:
                case ScoreType.FourOfAKind:
                case ScoreType.Chance:
                    scores[(int)index] = new TotalOfDice(index, scoreTotal[(int)index]);
                    break;

                case ScoreType.LargeStraight:
                case ScoreType.SmallStraight:
                case ScoreType.Yahtzee:
                case ScoreType.FullHouse:
                    scores[(int)index] = new FixedScore(index, scoreTotal[(int)index]);
                    break;

                default:
                    scores[(int)index] = new BonusOrTotal(scoreTotal[(int)index]);
                    break;
                }
            }
        }//end Player
Ejemplo n.º 6
0
        /// <summary>
        /// Calculates the total of dice combination score for that specific ScoreType.
        /// </summary>
        /// <param name="score">The total of dice combination ScoreType.</param>
        /// <param name="dieValues">An integer array with all of the values from the die.</param>
        private void CalculateTotalOfDiceCombination(ScoreType score, int[] dieValues)
        {
            //cast the specific score element as a FixedScore
            TotalOfDice combination = (TotalOfDice)scores[(int)score];

            combination.CalculateScore(dieValues);

            //if the roll was a yahtzee and the yahtzee combination has been done and
            //is not 0, add a yahtzee bonus to the yahtzee bonus score
            combination.CheckForYahtzee(dieValues);
            if (combination.IsYahtzee && scores[(int)ScoreType.Yahtzee].Points != 0 &&
                scores[(int)ScoreType.Yahtzee].Done)
            {
                scores[(int)ScoreType.YahtzeeBonus].Points += YAHTZEE_BONUS;
            }

            //if the combination was and if the related upper section score was done,
            // perform yahtzee joker rule
            if (combination.IsYahtzee && (!scores[combination.YahtzeeNumber - NUMBER_TO_ADDRESS].Done ||
                                          !scores[(int)ScoreType.Yahtzee].Done))
            {
                combination.Points = 0;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initialises each score label with their specific ScoreType.
        /// </summary>
        /// <param name="score">The ScoreType that is to be assigned.</param>
        /// <param name="label">The Label of the ScoreType that is to be used.</param>
        private void InitialiseScoreLabels(ScoreType score, Label label)
        {
            switch (score)
            {
            case ScoreType.Ones:
                scores[(int)score] = new CountingCombination(score, label);
                break;

            case ScoreType.Twos:
                scores[(int)score] = new CountingCombination(score, label);
                break;

            case ScoreType.Threes:
                scores[(int)score] = new CountingCombination(score, label);
                break;

            case ScoreType.Fours:
                scores[(int)score] = new CountingCombination(score, label);
                break;

            case ScoreType.Fives:
                scores[(int)score] = new CountingCombination(score, label);
                break;

            case ScoreType.Sixes:
                scores[(int)score] = new CountingCombination(score, label);
                break;

            case ScoreType.SubTotal:
                scores[(int)score] = new BonusOrTotal(label);
                break;

            case ScoreType.BonusFor63Plus:
                scores[(int)score] = new BonusOrTotal(label);
                break;

            case ScoreType.SectionATotal:
                scores[(int)score] = new BonusOrTotal(label);
                break;

            case ScoreType.ThreeOfAKind:
                scores[(int)score] = new TotalOfDice(score, label);
                break;

            case ScoreType.FourOfAKind:
                scores[(int)score] = new TotalOfDice(score, label);
                break;

            case ScoreType.FullHouse:
                scores[(int)score] = new FixedScore(score, label);
                break;

            case ScoreType.SmallStraight:
                scores[(int)score] = new FixedScore(score, label);
                break;

            case ScoreType.LargeStraight:
                scores[(int)score] = new FixedScore(score, label);
                break;

            case ScoreType.Chance:
                scores[(int)score] = new TotalOfDice(score, label);
                break;

            case ScoreType.Yahtzee:
                scores[(int)score] = new FixedScore(score, label);
                break;

            case ScoreType.YahtzeeBonus:
                scores[(int)score] = new BonusOrTotal(label);
                break;

            case ScoreType.SectionBTotal:
                scores[(int)score] = new BonusOrTotal(label);
                break;

            case ScoreType.GrandTotal:
                scores[(int)score] = new BonusOrTotal(label);
                break;
            }
        }