예제 #1
0
 public Form1()
 {
     InitializeComponent();
     dice              = new YahtzeeDice();
     dice.DiceChanged += diceChangedHandler;
     scoreCard         = new YahtzeeScoreCard();
 }
예제 #2
0
        public YahtzeeUI()
        {
            InitializeComponent();
            random = new RandomNumberGenerator();

            dice          = new YahtzeeDice(random);
            dice.Changed += new YahtzeeDice.ChangeHandler(UpdatePossibleScoreLabels);

            scoreCard = new YahtzeeScoreCard();

            dicePictureBoxes = new PictureBox[5]
            {
                die1PictureBox,
                die2PictureBox,
                die3PictureBox,
                die4PictureBox,
                die5PictureBox
            };
            dicePictures = new Bitmap[6]
            {
                Properties.Resources.die_01,
                Properties.Resources.die_02,
                Properties.Resources.die_03,
                Properties.Resources.die_04,
                Properties.Resources.die_05,
                Properties.Resources.die_06
            };
            setScoreButtons(false);
        }
예제 #3
0
        public YahtzeeScoreCard getPossibleScores()
        {
            var scoreCard = new YahtzeeScoreCard();

            int[]      upperScores = new int[6];
            List <int> numberOfTimeEachDieWasRolled = new List <int>()
            {
                0, 0, 0, 0, 0, 0
            };

            foreach (int die in _dice)
            {
                upperScores[die - 1] += die;
                numberOfTimeEachDieWasRolled[die - 1]++;
            }

            scoreCard.Ones   = upperScores[0];
            scoreCard.Twos   = upperScores[1];
            scoreCard.Threes = upperScores[2];
            scoreCard.Fours  = upperScores[3];
            scoreCard.Fives  = upperScores[4];
            scoreCard.Sixes  = upperScores[5];

            if (numberOfTimeEachDieWasRolled.Contains(5))
            {
                scoreCard.Yahtzee = YahtzeeScoreCard.YAHTZEE;
            }

            if (numberOfTimeEachDieWasRolled.Contains(4))
            {
                scoreCard.FourOfAKind  = sumOfDice();
                scoreCard.ThreeOfAKind = sumOfDice();
            }

            if (numberOfTimeEachDieWasRolled.Contains(3))
            {
                scoreCard.ThreeOfAKind = sumOfDice();
            }

            if (numberOfTimeEachDieWasRolled.Contains(3) &&
                numberOfTimeEachDieWasRolled.Contains(2))
            {
                scoreCard.FullHouse = YahtzeeScoreCard.FULL_HOUSE_SCORE;
            }

            if ((_dice.Contains(1) && _dice.Contains(2) && _dice.Contains(3) && _dice.Contains(4)) ||
                (_dice.Contains(2) && _dice.Contains(3) && _dice.Contains(4) && _dice.Contains(5)) ||
                (_dice.Contains(3) && _dice.Contains(4) && _dice.Contains(5) && _dice.Contains(6))
                )
            {
                scoreCard.SmallStraight = YahtzeeScoreCard.SMALL_STRAIGHT_SCORE;
            }

            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.LargeStraight = YahtzeeScoreCard.LARGE_STRAIGHT_SCORE;
            }

            scoreCard.Chance = sumOfDice();



            return(scoreCard);
        }