Example #1
0
        /// <summary>
        /// Searches the Linked List to see if a score has already been entered into the chosen category for this round.
        /// Returns true if it is found, false if it is not, and is therefore available for scoring.
        /// </summary>
        /// <param name="roundCategory"></param>
        /// <returns></returns>
        public bool ContainsNode(ScoreCategoryBinaryTree.ScoringCategories roundCategory)
        {
            ScoreNode traversalNode = this.head;

            while (traversalNode != null)
            {
                if (traversalNode.roundCategory == roundCategory)
                {
                    return(true);
                }
                else
                {
                    traversalNode = traversalNode.next;
                }
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Traverses through the list to retrieve the score that belongs to the specified category.
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public int RetrieveScore(ScoreCategoryBinaryTree.ScoringCategories category)
        {
            ScoreNode traversalNode = this.head;

            while (traversalNode != null)
            {
                if (traversalNode.roundCategory == category)
                {
                    return(traversalNode.roundScore);
                }
                else
                {
                    traversalNode = traversalNode.next;
                }
            }
            return(0);
        }
Example #3
0
        /// <summary>
        /// Adds a new ScoreNode to the ScoreLinkedList as long as the chosen category has not already recorded a score.
        /// Also checks if the player is eligable for the Upper Section Bonus and the Yahtzee Bonus.
        /// Returns a bool to confirm that the node was able to be created.
        /// </summary>
        /// <param name="roundDiceTotals"></param>
        /// <param name="roundCategory"></param>
        public bool AddNode(int[,] roundDiceTotals, ScoreCategoryBinaryTree.ScoringCategories roundCategory)
        {
            if (ContainsNode(roundCategory))
            {
                return(false);
            }
            else
            {
                ScoreNode newNode = new ScoreNode(roundDiceTotals, roundCategory);
                newNode.next = this.head;
                this.head    = newNode;
                numberOfRounds++;

                ScoreCategoryBinaryTree.ScoringDelegate CalculationMethod
                    = ScoreCategoryBinaryTree.SearchScoringDelegates(roundCategory, ScoreCategoryBinaryTree.root);
                newNode.roundScore = CalculationMethod(roundDiceTotals);
                if (hasYahtzee == true && Scoring.IsYahtzee(newNode.roundDiceTotals) == true)
                {
                    newNode.roundScore += Scoring.yahtzeeBonus;
                }
                if (newNode.roundCategory == ScoreCategoryBinaryTree.ScoringCategories.Yahtzee && newNode.roundScore > 0)
                {
                    hasYahtzee = true;
                }

                if ((int)roundCategory < Dice.diceSides)
                {
                    this.upperSectionScore += newNode.roundScore;
                    if (this.upperSectionScore >= Scoring.upperSectionBonusRequired)
                    {
                        this.hasUpperSectionBonus = true;
                        this.upperSectionScore   += Scoring.upperSectionBonus;
                    }
                }
                else
                {
                    this.lowerSectionScore += newNode.roundScore;
                }
                this.totalScore = this.lowerSectionScore + this.upperSectionScore;
            }
            return(true);
        }
Example #4
0
 /// <summary>
 /// Alternate constructor method
 /// </summary>
 /// <param name="name"></param>
 /// <param name="method"></param>
 /// <param name="parent"></param>
 public ScoreCategoryNode(ScoreCategoryBinaryTree.ScoringCategories name, Delegate method, ScoreCategoryNode parent) : this(name, method)
 {
     this.parent = parent;
 }
Example #5
0
 /// <summary>
 /// Alternate constructor method
 /// </summary>
 /// <param name="name"></param>
 /// <param name="method"></param>
 public ScoreCategoryNode(ScoreCategoryBinaryTree.ScoringCategories name, Delegate method) : this()
 {
     this.name   = name;
     this.method = method;
 }
Example #6
0
 /// <summary>
 /// Alternate constructor method
 /// </summary>
 /// <param name="roundDiceTotals"></param>
 /// <param name="category"></param>
 public ScoreNode(int[,] roundDiceTotals, ScoreCategoryBinaryTree.ScoringCategories category) : this()
 {
     this.roundDiceTotals = roundDiceTotals;
     this.roundCategory   = category;
 }