Exemple #1
0
        public static void Start()
        {
            Console.WriteLine($"\n{"",30}MAIN MENU");

            while (true)
            {
                Console.WriteLine();
                var userChoice = ValidateUserData.AcceptIntDataInRange("\n\nAvailable commands:\n0 - exit the program\n1 - switch to drawing mode\n" +
                                                                       "2 - view rules\n\nPlease, choose menu item:", 0, 2);

                switch (userChoice)
                {
                case 0:
                {
                    Console.WriteLine("\n\nGoodbye!\n\n\n");
                    return;
                }

                case 1:
                {
                    DrawingMode.Draw();
                    Console.WriteLine($"\n{"",30}MAIN MENU");
                }; break;

                case 2:
                {
                    InfoMode();
                }; break;
                }
            }
        }
        static void AddShape()
        {
            Console.Clear();
            Console.WriteLine($"{"", 26}ADDING A NEW SHAPE");

            if (Shapes.CurrentShapesNumber == Shapes.MaxShapesNumber)
            {
                Console.WriteLine($"\n\nYou already have created {Shapes.CurrentShapesNumber} shapes. Sorry, you can't create more.");
                Console.WriteLine("\n\n\nEnter any key to return to the drawing mode:");
                Console.ReadKey();
                return;
            }

            bool success     = false;
            bool contourOnly = false;
            int  contourChoice;

            var shapeType = ValidateUserData.AcceptShapeType();

            if (shapeType == null)
            {
                return;
            }

            if (!(shapeType is ShapeType.Line))
            {
                contourChoice = ValidateUserData.AcceptIntDataInRange("\n\n\nChoose a drawing shape method:\n0 - fully filled\n" +
                                                                      "1 - only contour\n\nSelected method:", 0, 1);
                contourOnly = contourChoice != 0;
            }

            switch (shapeType)
            {
            case ShapeType.Line:
            {
                var lineType = ValidateUserData.AcceptLineType();

                if (lineType == null)
                {
                    return;
                }

                var length = ValidateUserData.AcceptIntDataInRange("\n\nEnter the line length:", Shape.MinParameterValue + 1, Shape.MaxParameterValue - 1);
                success = shapes.Add((ShapeType)shapeType, length, (int)lineType, 0);
            }; break;

            case ShapeType.Circle:
            {
                var radius = ValidateUserData.AcceptIntDataInRange("\n\nEnter the circle radius:", Shape.MinParameterValue + 1, Shape.MaxParameterValue - 1);
                success = shapes.Add((ShapeType)shapeType, radius, 0, 0, contourOnly);
            }; break;

            case ShapeType.Rectangle:
            {
                var width  = ValidateUserData.AcceptIntDataInRange("\n\nEnter the rectangle width:", Shape.MinParameterValue + 1, Shape.MaxParameterValue - 1);
                var height = ValidateUserData.AcceptIntDataInRange("\n\nEnter the rectangle height:", Shape.MinParameterValue + 1, Shape.MaxParameterValue - 1);
                success = shapes.Add((ShapeType)shapeType, height, 0, width, contourOnly);
            }; break;

            case ShapeType.Triangle:
            {
                var triangleType = ValidateUserData.AcceptTriangleType();

                if (triangleType == null)
                {
                    return;
                }

                var height = ValidateUserData.AcceptIntDataInRange("\n\nEnter the triangle height:", Shape.MinParameterValue + 1, Shape.MaxParameterValue - 1);
                success = shapes.Add((ShapeType)shapeType, height, (int)triangleType, 0, contourOnly);
            }; break;
            }

            if (success)
            {
                Console.WriteLine("\nThe shape was successfully added.");
            }
            else
            {
                //if(Shapes.CurrentShapesNumber == Shapes.CurrentShapesNumber)
                //    Console.WriteLine($"\n\nYou already have created {Shapes.CurrentShapesNumber} shapes. Sorry, you can't create more.");
                //else
                Console.WriteLine("\n\nSorry, there are some problems on our side. Please, contact the author of the application.");
            }

            Console.WriteLine("\n\n\nEnter any key to return to the drawing mode:");
            Console.ReadKey();
        }