/// <summary> /// Run method which holds the game logic /// </summary> public void Run() { ScoreCategoryBinaryTree.PopulateNodes(); while (window.IsOpen) { if (ScoreCard.numberOfRounds >= ScoreLinkedList.maxRounds) { messageType = "Finished"; message = new MessageDisplay(); colour = Color.Green; messageText = message.GetMessage(messageType); messageOpen = true; } Update(); Draw(); } }
/// <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); }