Ejemplo n.º 1
0
        static void Main()
        {
            Console.Write("Duration in seconds: ");

            int duration = Convert.ToInt32(Console.ReadLine());

            Task.Run(() =>
            {
                Ping ping = new Ping();
                Pong pong = new Pong();

                ping.PingOccured += pong.PingHandler;
                pong.PongOccured += ping.PongHandler;

                pong.OnPongOccured();
            });

            Thread.Sleep(duration * 1000);
        }
Ejemplo n.º 2
0
        public string ThrowPing()
        {
            Random rnd         = new Random();
            int    magicNumber = rnd.Next(0, 10);

            if (magicNumber > 2)
            {
                var pong = new Pong();

                Console.WriteLine("Ping получил Pong!");

                return(pong.ThrowPong());
            }

            else
            {
                Console.WriteLine("Ping промахнулся! Победил Pong!");
                return(null);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            PingPong game = new PingPong();

            Ping ping = new Ping();
            Pong pong = new Pong();

            game.OnGame += ping.GameMessage;
            game.OnGame += pong.GameMessage;

            string decision;

            do
            {
                game.Play();

                do
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Хотите сыграть еще раз? (Y/N)\n");
                    Console.ResetColor();

                    decision = Console.ReadLine();

                    Console.WriteLine();

                    if (decision != "Y" && decision != "y" && decision != "N" && decision != "n")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Не понятно! Попробуем еще раз...\n");
                        Console.ResetColor();
                    }
                } while (decision != "Y" && decision != "y" && decision != "N" && decision != "n");
            } while (decision != "N" && decision != "n");

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Игра окончена!");
            Console.ResetColor();
        }