示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Введите число");
            int a = int.Parse(Console.ReadLine());

            while (a == 0)
            {
                Console.WriteLine("Ноль не подходит, введите другое число");
                a = int.Parse(Console.ReadLine());
            }
            Numbertron tron = new Numbertron();
            Jay        jay  = new Jay();
            SilentBob  bob  = new SilentBob();

            tron.NewNumber += jay.FetchNewNumber;
            tron.NewNumber += bob.FetchNewNumber;
            for (int i = 0; i < a; i++)
            {
                tron.Generate();
            }
            if (jay.Score > bob.Score)
            {
                Console.WriteLine(jay.Name);
            }
            if (jay.Score < bob.Score)
            {
                Console.WriteLine(bob.Name);
            }
            if (jay.Score == bob.Score)
            {
                Console.WriteLine("DRAW");
            }
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            Jay        jay        = new Jay();
            SilentBob  silentBob  = new SilentBob();
            Numbertron numbertron = new Numbertron();

            numbertron.NewNumber += jay.FetchNewNuber;
            numbertron.NewNumber += silentBob.FetchNewNuber;

            int count = 0;

            while (count < 1)
            {
                try
                {
                    Console.WriteLine("Сколько чисел нужно сгенерировать?");
                    count = Convert.ToInt32(Console.ReadLine());
                    if (count < 1)
                    {
                        Console.WriteLine("Число должно быть больше 0!\n");
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Введите число!\n");
                }
                catch (OverflowException)
                {
                    Console.WriteLine("Это слишком большое число!\n");
                }
            }


            for (int i = 0; i < count; i++)
            {
                numbertron.GenerateNumber();
            }

            if (jay.Score < silentBob.Score)
            {
                Console.WriteLine("Победил Джей!");
            }
            else
            {
                if (jay.Score > silentBob.Score)
                {
                    Console.WriteLine("Победил Молчаливый Боб!");
                }
                else
                {
                    Console.WriteLine("Ничья!");
                }
            }
            Console.WriteLine(jay.Score + " " + silentBob.Score);


            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            int        i           = 0;
            bool       exp         = true;
            Numbertron numbertron1 = new Numbertron();
            Gambler    jay         = new Jay();
            Gambler    silentBob   = new SilentBob();

            //var Jay  = new Jay("Jay");
            // Console.WriteLine(Jay.Name);
            // Jay.FetchNewNumber(); //реализация метода
            numbertron1.NewNumber += jay.FetchNewNumber;
            numbertron1.NewNumber += silentBob.FetchNewNumber;
            do
            {
                Console.WriteLine("Введите количество генерируемых чисел (целое число больше нуля):");
                try
                {
                    i = int.Parse(Console.ReadLine());
                    if (i < 1)
                    {
                        exp = false;
                        Console.WriteLine("A figure can't be <0 or =0!");
                    }
                    else
                    {
                        exp = true;
                    }
                }
                catch
                {
                    Console.WriteLine("Wrong number format! Try again...");
                    exp = false;
                }
            } while (exp == false);
            for (var n = 0; n <= i; n++)
            {
                numbertron1.Generate();
            }
            if (silentBob.Score > jay.Score)
            {
                Console.WriteLine("Silent bob win");
            }
            if (silentBob.Score < jay.Score)
            {
                Console.WriteLine("Jay win");
            }
            if (silentBob.Score == jay.Score)
            {
                Console.WriteLine("Draw!");
            }
            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Какое количество чисел использовать?");
            int numb = 0;

            while (numb <= 0)
            {
                Console.WriteLine("Введите положительное целое число!");
                try
                {
                    numb = int.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    numb = 0;
                }
                catch (OverflowException)
                {
                    numb = 0;
                    Console.WriteLine("Вы ввели слишком большое число");
                }
            }
            Jay       jay       = new Jay();
            SilentBob silentBob = new SilentBob();
            Numberton numberton = new Numberton();

            numberton.NewNumber += silentBob.FetchNewNumber;
            numberton.NewNumber += jay.FetchNewNumber;
            for (int i = 0; i < numb; i++)
            {
                numberton.Generate();
            }
            if (jay.Score > silentBob.Score)
            {
                Console.WriteLine($" У {jay.Name} {jay.Score} очков");
                Console.WriteLine($" У {silentBob.Name} {silentBob.Score} очков");
                Console.WriteLine($" Выиграл {jay.Name} ");
            }
            else if (jay.Score < silentBob.Score)
            {
                Console.WriteLine($" У {jay.Name} {jay.Score} очков");
                Console.WriteLine($" У {silentBob.Name} {silentBob.Score} очков");
                Console.WriteLine($" Выиграл {silentBob.Name} ");
            }
            else
            {
                Console.WriteLine($" У {jay.Name} {jay.Score} очков");
                Console.WriteLine($" У {silentBob.Name} {silentBob.Score} очков");
                Console.WriteLine("Draw!");
            }
            Console.ReadKey();
        }
示例#5
0
        static void Main(string[] args)
        {
            while (true)
            {
                Numbertron numbertron = new Numbertron();
                Gambler    jay        = new Jay();
                Gambler    silentBob  = new SilentBob();

                numbertron.NewNumber += jay.FetchNewNumber;
                numbertron.NewNumber += silentBob.FetchNewNumber;

                Console.WriteLine("Наши спорщики: {0} и {1}", jay.Name, silentBob.Name);
                Console.Write("Введите количество чисел: ");
                try
                {
                    var count = Convert.ToInt32(Console.ReadLine());
                    if (count > 0)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            numbertron.Generate();
                            //Thread.Sleep(1); //Необходима для корректной рандомизации
                        }
                        if (jay.Score > silentBob.Score)
                        {
                            Console.WriteLine("Jay победил!");
                        }
                        else if (jay.Score < silentBob.Score)
                        {
                            Console.WriteLine("SilentBob победил!");
                        }
                        else
                        {
                            Console.WriteLine("Ничья!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Введите число больше 0.");
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Вы ввели не число! Попробуйте ещё раз.");
                }
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            int num = 0;

            while (num < 1)
            {
                try
                {
                    Console.WriteLine("Введите необходимое количество случайных чисел (целое неотрицательное число): ");
                    num = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    Console.WriteLine("Введено некорректное значение. Введите целое неотрицательное число.");
                }
            }
            var numb = new Numbertron();
            var jay  = new Jay();
            var sBob = new SilentBob();

            numb.NewNumber += jay.FetchNewNumber;
            numb.NewNumber += sBob.FetchNewNumber;
            for (int i = 1; i <= num; i++)
            {
                numb.Generate();
            }
            if (jay.Score > sBob.Score)
            {
                Console.WriteLine("Jay wins");
            }
            else if (sBob.Score > jay.Score)
            {
                Console.WriteLine("Silent Bob wins");
            }
            else
            {
                Console.WriteLine("Draw");
            }
            Console.ReadLine();
        }