Beispiel #1
0
 private void ResetGame()
 {
     ResetRoll();
     scorecard            = new YahtzeeScorecard();
     dice                 = new YahtzeeDice();
     EScoresTabUpper.Text = "Upper: 0";
     EScoresTabLower.Text = "Lower: 0";
     foreach (Control ctrl in EScoresTabUpper.Controls)
     {
         ctrl.Enabled = true;
     }
     foreach (Control ctrl in EScoresTabLower.Controls)
     {
         ctrl.Enabled = true;
     }
     foreach (Control ctrl in EScoresUpperGroup.Controls)
     {
         ctrl.Text = "0";
     }
     foreach (Control ctrl in EScoresLowerGroup.Controls)
     {
         ctrl.Text = "0";
     }
 }
Beispiel #2
0
        public YahtzeeScorecard CalculateScores()
        {
            YahtzeeScorecard scorecard    = new YahtzeeScorecard();
            List <int>       dieRollCount = new List <int>()
            {
                0, 0, 0, 0, 0, 0
            };

            foreach (int die in dice)
            {
                dieRollCount[die - 1]++;
            }

            for (int i = 0; i < dieRollCount.Count; i++)
            {
                scorecard.ScoreSectionUpper[(YahtzeeScorecard.Upper)i] = dieRollCount[i] * (i + 1);
            }

            // Three of a Kind
            if (dieRollCount.Contains(3))
            {
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.ThreeOfAKind] = SumAllDice();
            }

            // Four of a Kind
            if (dieRollCount.Contains(4))
            {
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.ThreeOfAKind] = SumAllDice();
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.FourOfAKind]  = SumAllDice();
            }

            // Full House
            if (dieRollCount.Contains(3) && dieRollCount.Contains(2))
            {
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.FullHouse] = YahtzeeScorecard.SCORE_FULLHOUSE;
            }

            // Small Straight
            if (dice.Contains(3) && dice.Contains(4))
            {
                if ((dice.Contains(1) && dice.Contains(2)) ||
                    (dice.Contains(2) && dice.Contains(5)) ||
                    (dice.Contains(5) && dice.Contains(6)))
                {
                    scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.SmallStraight] = YahtzeeScorecard.SCORE_SMALLSTRAIGHT;
                }
            }

            // Large Straight
            if ((dice.Contains(1) && dice.Contains(2) && dice.Contains(3) && dice.Contains(4) && dice.Contains(5)) ||
                (dice.Contains(2) && dice.Contains(3) && dice.Contains(4) && dice.Contains(5) && dice.Contains(6)))
            {
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.LargeStraight] = YahtzeeScorecard.SCORE_LARGESTRAIGHT;
            }

            // Yahtzee
            if (dieRollCount.Contains(5))
            {
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.ThreeOfAKind] = SumAllDice();
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.FourOfAKind]  = SumAllDice();
                scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.Yahtzee]      = YahtzeeScorecard.SCORE_YAHTZEE;
            }

            // Chance
            scorecard.ScoreSectionLower[YahtzeeScorecard.Lower.Chance] = SumAllDice();

            return(scorecard);
        }
Beispiel #3
0
        private void EDiceRollButton_Click(object sender, EventArgs e)
        {
            if (dice.CanRoll())
            {
                dice.Roll();
                YahtzeeScorecard scores = dice.CalculateScores();
                this.Text = $"Yahtzee - Roll {dice.RollCount}";

                int i = 0;
                foreach (PictureBox ctrl in EDiceDieGroup.Controls)
                {
                    ctrl.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject($"die{dice[i++]}");
                }

                if (EScoresUpperAcesButton.Enabled)
                {
                    EScoresUpperAces.Text = scores.ScoreSectionUpper[YahtzeeScorecard.Upper.Ones].ToString();
                }
                if (EScoresUpperTwosButton.Enabled)
                {
                    EScoresUpperTwos.Text = scores.ScoreSectionUpper[YahtzeeScorecard.Upper.Twos].ToString();
                }
                if (EScoresUpperThreesButton.Enabled)
                {
                    EScoresUpperThrees.Text = scores.ScoreSectionUpper[YahtzeeScorecard.Upper.Threes].ToString();
                }
                if (EScoresUpperFoursButton.Enabled)
                {
                    EScoresUpperFours.Text = scores.ScoreSectionUpper[YahtzeeScorecard.Upper.Fours].ToString();
                }
                if (EScoresUpperFivesButton.Enabled)
                {
                    EScoresUpperFives.Text = scores.ScoreSectionUpper[YahtzeeScorecard.Upper.Fives].ToString();
                }
                if (EScoresUpperSixesButton.Enabled)
                {
                    EScoresUpperSixes.Text = scores.ScoreSectionUpper[YahtzeeScorecard.Upper.Sixes].ToString();
                }
                if (EScoresLowerThreeKindButton.Enabled)
                {
                    EScoresLowerThreeKind.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.ThreeOfAKind].ToString();
                }
                if (EScoresLowerFourKindButton.Enabled)
                {
                    EScoresLowerFourKind.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.FourOfAKind].ToString();
                }
                if (EScoresLowerFullHouseButton.Enabled)
                {
                    EScoresLowerFullHouse.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.FullHouse].ToString();
                }
                if (EScoresLowerSmallStraightButton.Enabled)
                {
                    EScoresLowerSmallStraight.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.SmallStraight].ToString();
                }
                if (EScoresLowerLargeStraightButton.Enabled)
                {
                    EScoresLowerLargeStraight.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.LargeStraight].ToString();
                }
                if (EScoresLowerYahtzeeButton.Enabled)
                {
                    EScoresLowerYahtzee.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.Yahtzee].ToString();
                }
                if (EScoresLowerChanceButton.Enabled)
                {
                    EScoresLowerChance.Text = scores.ScoreSectionLower[YahtzeeScorecard.Lower.Chance].ToString();
                }

                if (!dice.CanRoll())
                {
                    EDiceRollButton.Enabled = false;
                }
            }
        }
Beispiel #4
0
 public FormMain()
 {
     InitializeComponent();
     scorecard = new YahtzeeScorecard();
     dice      = new YahtzeeDice();
 }