vendredi 17 juillet 2020

c# Choose a number between 1-100 game can't generate different/ new number after each round

I'm trying to work with an app/ small game that is about trying to guess the same number between 1-10 same as the program and win, but after that round you are supposed to be able to play again! and my problem is that the program generates the same number everytime... ive looked through other threads on here and none of them seem to help... or at least i cant understand. How can i fix this please! help :)

static void Main(string[] args)
        {
            Random random =    new Random(); 
            bool play = true; 

            int playnum = random.Next(1, 11);

            while (play) 
            {
                Console.Write("\n\tGuess number between 1-10 ");

                int numb;
                bool success = Int32.TryParse(Console.ReadLine(), out numb);

                if (success)
                {
                    if (numb < playnum)
                    {
                        Console.WriteLine(playnum);
                        Console.WriteLine("\tinput number " + numb + " too small, try again.");
                    }

                    if (numb > playnum)
                    {
                        Console.WriteLine(playnum);
                        Console.WriteLine("\tinput number " + numb + " too big, try again.");
                    }

                    if (numb == playnum)
                    {
                        Console.WriteLine(playnum);
                        Console.WriteLine("\tcongrats!");

                        bool LoopBreaker = true;
                        do
                        {
                            Console.WriteLine("continue or finish?");
                            string input = Console.ReadLine();
                            char CharFromTryPass = ' ';
                            bool TryparsResult = char.TryParse(input, out CharFromTryPass);

                            bool IsValidChar = (CharFromTryPass != 'A' && CharFromTryPass != 'F');
                            if (IsValidChar) 
                            {
                                Console.WriteLine(" please write A or F!");
                            }

                            else if (TryparsResult)    
                            {

                                if (CharFromTryPass == 'A')
                                {
                                    Console.WriteLine("see you!");
                                    play = false;
                                    LoopBreaker = false;
                                }

                                if (CharFromTryPass == 'F')
                                {
                                    play = true;
                                    LoopBreaker = false;
                                }
                            }

                        } while (LoopBreaker);




Aucun commentaire:

Enregistrer un commentaire