Пример #1
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);
        }