Exemplo n.º 1
0
        public void play()
        {
            Console.WriteLine("human pick a number form 1-100");
            double Mynum = double.Parse(Console.ReadLine());

            Random r       = new Random();
            int    ans     = r.Next(1, 100);
            int    low     = 1;
            int    hig     = 100;
            bool   correct = false;
            int    c       = 0;

            do
            {
                c++;
                ans = r.Next(low, hig);
                Console.WriteLine($"the low number is {low} the hight is {hig}");
                Console.WriteLine($"computer number is {ans}");

                if (ans < Mynum)
                {
                    Console.WriteLine("to low ");
                    Console.ReadKey();
                    if (true)
                    {
                        low = ans;
                    }
                }
                else if (ans > Mynum)
                {
                    Console.WriteLine("to hight");
                    Console.ReadKey();

                    if (true)
                    {
                        hig = ans;
                    }
                }
                else
                {
                    correct = true;
                    Console.WriteLine("compter guessed right!");
                    Console.WriteLine($"it took {c} guesses");
                    Console.ReadLine();
                    Console.Write("press 1 to go back to main screen \n" +
                                  "press 2 to restart this game \n" +
                                  "press 3 to exit the program \n" +
                                  "input selection--->");

                    string path0 = (Console.ReadLine()).ToLower();
                    if (path0.Contains("1"))
                    {
                        Console.WriteLine("you have select main screen ");
                        Console.Clear();
                        MainScreen a = new MainScreen();
                    }
                    else if (path0.Contains("2"))
                    {
                        Console.WriteLine("you have select to restart this game ");
                        Console.Clear();
                        computer_plays a = new computer_plays();
                    }
                    else
                    {
                        Console.WriteLine("you have select to exit the program ");
                        Console.ReadLine();
                        System.Environment.Exit(0);
                    }
                }
            } while (!correct);
        }
Exemplo n.º 2
0
        public void play()
        {
            Random Randomnumber = new Random();

            int  ans     = Randomnumber.Next(1, 1000);
            int  guess   = 0;
            bool correct = false;
            int  c       = 0;

            //Console.WriteLine(ans);
            Console.WriteLine("I'm thinking of a number between 1 and 1000.");

            while (!correct)
            {
                c++;
                Console.Write("Guess: ");
                string input = Console.ReadLine();

                if (!int.TryParse(input, out guess))
                {
                    Console.WriteLine("That's not a number.");
                    continue;
                }

                if (guess < ans)
                {
                    Console.WriteLine($"No, the number I'm thinking is 'higher' than that number.");
                }

                else if (guess > ans)
                {
                    Console.WriteLine($"No, the number I'm thinking is 'lower' than that number.");
                }

                else
                {
                    correct = true;
                    Console.WriteLine("You guessed right!");
                    Console.WriteLine($"it took {c} guesses");
                    Console.ReadLine();

                    Console.Write("press 1 to go back to main screen \n" +
                                  "press 2 to restart this game \n" +
                                  "press 3 to exit the program \n" +
                                  "input selection--->");

                    string path0 = (Console.ReadLine()).ToLower();

                    if (path0.Contains("1"))
                    {
                        Console.WriteLine("you have select main screen ");
                        Console.Clear();
                        MainScreen a = new MainScreen();
                    }

                    else if (path0.Contains("2"))
                    {
                        Console.WriteLine("you have select to restart this game ");
                        Console.Clear();
                        human_plays a = new human_plays();
                    }

                    else
                    {
                        Console.WriteLine("you have select to exit the program ");
                        Console.ReadLine();
                        System.Environment.Exit(0);
                    }
                }
            }
        }
Exemplo n.º 3
0
 static void Main(string[] args)
 {
     MainScreen a = new MainScreen();
 }