示例#1
0
        public static int PlayGame(Game game, int guess, string name)
        {
            Console.WriteLine("Enter your guess number: " + name);

            if(name==null)
                name = Console.ReadLine();
            while (!game.GameOver)
            {
                string guessNum = Console.ReadLine();
                if (!string.IsNullOrEmpty(guessNum))
                    guess = int.Parse(guessNum);

                game.Play(guess, name);
                Console.WriteLine(game.Message);
                Console.WriteLine("Attempts: {0}", game.Attempts);
            }
            Console.WriteLine("Do you want to play a new game? yes/no");
            string playAgain = Console.ReadLine();
            if (playAgain.ToLower() == "yes" || playAgain.ToLower() == "y")
            {
                game.Reset();
                PlayGame(game, -1, name);
            }
            return guess;
        }
 private static int PlayGame(Game game, int guess)
 {
     while (!game.GameOver)
     {
         guess = int.Parse(Console.ReadLine());
         game.Play(guess);
         Console.WriteLine(game.Message);
         Console.WriteLine("Attempts: {0}", game.Attempts);
     }
     Console.WriteLine("Do you want to play a new game? yes/no");
     string playAgain = Console.ReadLine();
     if (playAgain == "yes")
     {
         game.Reset();
         PlayGame(game, -1);
     }
     return guess;
 }