コード例 #1
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();
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: kostas146/CSharp-Practices
        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();
        }