示例#1
0
        static void Main(string[] args)
        {
            Program pr = new Program();

            do
            {
                try
                {
                    Console.WriteLine("Выберите фигуру:\n1: Линия\n2: Окружность\n3: Прямоугольник\n4: Круг\n5: Кольцо");
                    int figure = int.Parse(Console.ReadLine());

                    if (figure == 1)
                    {
                        Line f = new Line(2, 5, 1, 4);
                        Console.WriteLine(f.Info());
                    }
                    else if (figure == 2)
                    {
                        Circle f = new Circle(0, 0, 2);
                        Console.WriteLine(f.Info());
                    }
                    else if (figure == 3)
                    {
                        Reсtangle f = new Reсtangle(0, 0, 2, 3);
                        Console.WriteLine(f.Info());
                    }
                    else if (figure == 4)
                    {
                        Round f = new Round(0, 0, 3);
                        Console.WriteLine(f.Info());
                    }
                    else if (figure == 5)
                    {
                        Ring f = new Ring(0, 0, 5, 2);
                        Console.WriteLine(f.Info());
                    }
                    Console.WriteLine("Повторить? [Нажмите любую кнопку для продолжения или Esc для выхода]");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Ощибка: {0}", ex.Message);
                }
            }while (pr.replay() == true);
        }
示例#2
0
        public static bool CheckCommand(ref Figures figures)
        {
            Random r       = new Random();
            var    command = SetCommand();
            bool   exit    = false;

            switch (command)
            {
            case (int)FigureType.Line:
            {
                var figure = new Line(r.Next(1, 100), r.Next(1, 100), r.Next(1, 100));
                figures.SetFigures(figure);
                Console.WriteLine(figure.Info());
                break;
            }

            case (int)FigureType.Rectangle:
            {
                var figure = new Rectangle(r.Next(1, 100), r.Next(1, 100), r.Next(1, 100), r.Next(1, 100));
                figures.SetFigures(figure);
                Console.WriteLine(figure.Info());
                break;
            }

            case (int)FigureType.Circle:
            {
                var figure = new Circle(r.Next(1, 100), r.Next(1, 100), r.Next(1, 100));
                figures.SetFigures(figure);
                Console.WriteLine(figure.Info());
                break;
            }

            case (int)FigureType.Round:
            {
                var figure = new Round(r.Next(1, 100), r.Next(1, 100), r.Next(1, 100));
                figures.SetFigures(figure);
                Console.WriteLine(figure.Info());
                break;
            }

            case (int)FigureType.Ring:
            {
                var figure = new Ring(r.Next(1, 100), r.Next(1, 100), r.Next(1, 100), r.Next(1, 100));
                figures.SetFigures(figure);
                Console.WriteLine(figure.Info());
                break;
            }

            case 0:
            {
                exit = true;
                break;
            }

            default:
            {
                Console.WriteLine("Command does not exist.");
                exit = CheckCommand(ref figures);
                break;
            }
            }

            return(exit);
        }