Exemplo n.º 1
0
        /// <summary>
        /// Displays the menu.
        /// </summary>
        public void DisplayMenu()
        {
            while (true)
            {
                if (this.Canvases.Count > 0)
                {
                    OutputWriter.SendToOutput("1. Create a new canvas, (If you already have one canvas created, select option 2 to start drawing shapes and paint over it)", true);
                }
                else
                {
                    OutputWriter.SendToOutput("1. Create a new canvas in order to draw shapes and paint over it", true);
                }
                OutputWriter.SendToOutput("2. Start drawing on the canvas by issuing various commands", true);
                OutputWriter.SendToOutput("3. Quit", true);

                char input = '0';
                try
                {
                    input = InputCommandReader.ReadCommands()[0];
                }
                catch (Exception)
                {
                    OutputWriter.SendToOutput("Press Enter...", true);
                }

                ProcessInput(input);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the canvas.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="InvalidInputDataException">
        /// </exception>
        public Canvas CreateCanvas()
        {
            OutputWriter.SendToOutput("Please enter the canvas width and height with a space ex:20 4", true);

            Canvas canvas = null;

            try
            {
                string input = InputCommandReader.ReadCommands();

                string[] commandArgs = Regex.Split(input, @"\s+").Where(s => s != string.Empty).ToArray();

                if (commandArgs.Count() < 2 || commandArgs.Count() > 2)
                {
                    throw new InvalidInputDataException();
                }

                int width  = commandArgs[0].AsInt();
                int height = commandArgs[1].AsInt();

                if (width < 1 || height < 1)
                {
                    throw new InvalidInputDataException();
                }

                canvas = new Canvas(width, height);

                // Set the new canvas on the drawer
                if (CanvasRenderer == null)
                {
                    CanvasRenderer = new CanvasRenderer(canvas, OutputWriter);
                }
                else
                {
                    CanvasRenderer.Canvas = canvas;
                }

                CanvasRenderer.SetTheCanvas();
                CanvasRenderer.Draw();

                OutputWriter.SendToOutput("Canvas created", true);
            }
            catch (Exception ex)
            {
                if (ex is InvalidInputDataException | ex is FormatException)
                {
                    OutputWriter.SendToOutput(ex.Message, true);
                }
            }

            return(canvas);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Displays the menu.
        /// </summary>
        public void DisplayMenu()
        {
            bool exit = false;

            while (!exit)
            {
                OutputWriter.SendToOutput("enter command ", true);
                OutputWriter.SendToOutput("ex: L 1 2 6 2, L 6 3 6 4 for drawing a line, R 16 1 20 3 to draw a rectangle, B 10 3 o to paint or", true);
                OutputWriter.SendToOutput("q to go back to main menu", true);

                String input = null;
                try
                {
                    input = InputCommandReader.ReadCommands();
                }
                catch (Exception exception)
                {
                    OutputWriter.SendToOutput("Enter...", true);
                }

                exit = ProcessInput(input);
            }
        }