예제 #1
0
        void Start()
        {
            Dice d1 = new Dice();

            for (int i = 0; i < 10; i++)
            {
                d1.Throw();
                d1.DisplayValue();
                Console.Write(" ");
            }
            Console.WriteLine();

            YahtzeeGame yahtzeeGame = new YahtzeeGame();

            yahtzeeGame.Init();

            yahtzeeGame.Throw();
            yahtzeeGame.DisplayValues();

            yahtzeeGame.Throw();
            yahtzeeGame.DisplayValues();

            Console.WriteLine();

            PlayYahtzee(yahtzeeGame);

            EndProgram();
        }
예제 #2
0
        /// <summary>
        /// Roll dice until win condition is reached
        /// </summary>
        void Start()
        {
            YahtzeeGame yahtzeeGame = new YahtzeeGame();

            yahtzeeGame.Init();

            bool stop  = false;
            int  index = 0;

            while (stop == false)
            {
                yahtzeeGame.Throw();         // throw dice

                yahtzeeGame.DisplayValues(); // display result

                // Check for win condition
                stop = yahtzeeGame.Yahtzee();

                //stop = yahtzeeGame.FourOfAKind();

                //stop = yahtzeeGame.ThreeOfAKind();

                stop = yahtzeeGame.FullHose();

                //stop = yahtzeeGame.Straight(5);

                index++;
            }

            Console.WriteLine("Number of attempts needed ({0}): {1}", yahtzeeGame.wincondition, index);

            Console.ReadKey();
        }
예제 #3
0
        void PlayYahtzee(YahtzeeGame game)
        {
            int stop          = 0;
            int timer         = 0;
            int BigStraight   = 9999;
            int SmallStraight = 9999;
            int FourOfAKind   = 9999;
            int ThreeOfAKind  = 9999;
            int FullHouse     = 9999;
            int Yahtzee       = 9999;

            do
            {
                game.Throw();
                Console.Write("{0,3}. ", timer + 1);
                game.DisplayValues();
                timer++;
                if (game.ThreeOfAKind() && timer < ThreeOfAKind)
                {
                    ThreeOfAKind = timer;
                }
                if (game.FourOfAKind() && timer < FourOfAKind)
                {
                    FourOfAKind = timer;
                }
                if (game.Yahtzee() && timer < Yahtzee)
                {
                    Yahtzee = timer;
                }
                if (game.FullHouse() && timer < FullHouse)
                {
                    FullHouse = timer;
                }
                if (game.BigStraight() && timer < BigStraight)
                {
                    BigStraight = timer;
                }
                if (game.SmallStraight() && timer < SmallStraight)
                {
                    SmallStraight = timer;
                }
                if (ThreeOfAKind < 9999 && FourOfAKind < 9999 && Yahtzee < 9999 && BigStraight < 9999 && FullHouse < 9999 && SmallStraight < 9999)
                {
                    stop = 1;
                }
            } while (stop == 0);
            Console.WriteLine("Number of attempts needed (Three of a kind): {0}", ThreeOfAKind);
            Console.WriteLine("Number of attempts needed (Four of a kind): {0}", FourOfAKind);
            Console.WriteLine("Number of attempts needed (Full house): {0}", FullHouse);
            Console.WriteLine("Number of attempts needed (Small straight): {0}", SmallStraight);
            Console.WriteLine("Number of attempts needed (Big straight): {0}", BigStraight);
            Console.WriteLine("Number of attempts needed (Yahtzee): {0}", Yahtzee);
        }
예제 #4
0
        void PlayYahtzee(YahtzeeGame game)
        {
            int nrOfAttempts = 0;

            do
            {
                game.Throw();
                game.DisplayValues();

                nrOfAttempts++;
            }while (!game.Yahtzee());

            Console.WriteLine("Number of attempts needed(Yahtzee): {0}", nrOfAttempts);
            Console.ReadKey();
        }