Esempio n. 1
0
 public void TestIsYahtzee()
 {
     Yahtzee.Yahtzee yahtzee = new Yahtzee.Yahtzee(1472); // Seed 1472 is known to produce a Yahtzee with the first throw.
     Assert.IsTrue(yahtzee.IsYahtzee());
     yahtzee.Throw();                                     // Throw again.
     Assert.IsFalse(yahtzee.IsYahtzee());                 // It probably won't throw another Yahtzee in a row.
 }
Esempio n. 2
0
        public void TestThrow()
        {
            Yahtzee.Yahtzee yahtzee        = new Yahtzee.Yahtzee(100);
            int             old_throwcount = yahtzee.GetThrowcount();

            yahtzee.Throw();
            Assert.AreNotEqual(old_throwcount, yahtzee.GetThrowcount());
        }
Esempio n. 3
0
        public void TestConstructor()
        {
            Yahtzee.Yahtzee yahtzee = new Yahtzee.Yahtzee(100);
            int[]           dice    = yahtzee.GetDice();
            // All dice are 0 when initialized, but the constructor throws once.
            Assert.AreNotEqual(0, dice[0]);
            Assert.AreNotEqual(0, dice[1]);
            Assert.AreNotEqual(0, dice[2]);
            Assert.AreNotEqual(0, dice[3]);
            Assert.AreNotEqual(0, dice[4]);

            // Constructor throws the dice once.
            Assert.AreEqual(1, yahtzee.GetThrowcount());
        }
Esempio n. 4
0
        public void TestGetThrowcount()
        {
            Yahtzee.Yahtzee yahtzee = new Yahtzee.Yahtzee(100); // Constructor throws once.
            // Throw four more times.
            int throwtimes = 4;

            for (int i = 0; i < throwtimes; ++i)
            {
                yahtzee.Throw();
            }

            // There should be five throws by now.
            Assert.AreEqual(5, yahtzee.GetThrowcount());
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("============\nAuto Yahtzee\n============");
            Console.WriteLine("This program will start throwing five pieces of six-sided dice until it throws five equal numbers.");
            Console.Write("Enter a seed value to begin or [ENTER] to quit: ");

            while (GetSeed(out int seed))
            {
                Yahtzee.Yahtzee yahtzee = new Yahtzee.Yahtzee(seed);

                while (!yahtzee.IsYahtzee())
                {
                    yahtzee.Throw();
                }

                Console.WriteLine("Yahtzee! after " + yahtzee.GetThrowcount() + " throws. Used seed: " + seed);
                Console.Write("Enter a new seed or [ENTER] to quit: ");
            }
        }