Ejemplo n.º 1
0
        public void Game()
        {
            int            attempts = 0;
            int            min      = 1;
            int            max      = 101;
            int            guess    = 50;
            GuessValidator gv       = new GuessValidator(randomNum);
            bool           run      = true;

            while (run)
            {
                int result = gv.Guesses(guess, false);
                if (result == 0)
                {
                    run = false;
                }
                else if (result == 1)
                {
                    max = guess - 1;
                }
                else if (result == -1)
                {
                    min = guess + 1;
                }
                guess = (min + max) / 2;
                attempts++;
            }
            GameResults.Add(attempts);
        }
Ejemplo n.º 2
0
        public void Game()
        {
            int            attempts = 0;
            int            min      = 1;
            int            max      = 101;
            GuessValidator gv       = new GuessValidator(randomNum);
            bool           run      = true;

            while (run)
            {
                int guess = random.Next(min, max);

                int result = gv.Guesses(guess, false);
                if (result == 0)
                {
                    run = false;
                }
                else if (result == 1)
                {
                    max = guess;
                }
                else if (result == -1)
                {
                    min = guess + 1;//min is not exclusive like the max
                }
                attempts++;
            }
            GameResults.Add(attempts);
        }
Ejemplo n.º 3
0
        public void Game()
        {
            int            attempts = 0;
            int            guess    = 100;
            GuessValidator gv       = new GuessValidator(randomNum);
            bool           run      = true;

            while (run)
            {
                int result = gv.Guesses(guess, false);
                if (result == 0)
                {
                    run = false;
                }
                guess--;
                attempts++;
            }
            GameResults.Add(attempts);
        }