Exemplo n.º 1
0
        /// <summary>
        /// Method to get the colour of the pen based on the combobox value
        /// </summary>
        private void GetPenColour()
        {
            switch (penBox.SelectedIndex)
            {
            case 0:
                PenColourClass.PenColourSet("blue");
                break;

            case 1:
                PenColourClass.PenColourSet("red");
                break;

            case 2:
                PenColourClass.PenColourSet("green");
                break;

            case 3:
                PenColourClass.PenColourSet("orange");
                break;

            case 4:
                PenColourClass.PenColourSet("yellow");
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to process all possible commands entered along with error handling for empty box and unregistered commands
        /// </summary>
        private void ProcessCommands()
        {
            // if combo box is selected, get the colour
            if (penBox.SelectedIndex > -1)
            {
                GetPenColour();
            }

            // move to command
            if (_commandList[0].Equals("moveto"))
            {
                try
                {
                    if (_commandList.Length > 3)
                    {
                        MessageBox.Show(@"Too many parameters.");
                    }

                    else
                    {
                        try
                        {
                            MoveToClass.MoveTo(int.Parse(_commandList[1]),
                                               int.Parse(_commandList[2]));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show(@"Parameters must be a number!");
                        }
                    }
                }
                catch (IndexOutOfRangeException) // catch if no number has been entered after command
                {
                    MessageBox.Show(@"Must enter 2 numbers after command.");
                }
            }
            // draw line commands
            else if (_commandList[0].Equals("drawline"))
            {
                try
                {
                    if (_commandList.Length > 3)
                    {
                        MessageBox.Show(@"Too many parameters.");
                    }
                    else
                    {
                        try
                        {
                            _lineDraw.DrawLine(int.Parse(_commandList[1]),
                                               int.Parse(_commandList[2]));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show(@"Parameters must be a number!");
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show(@"Must enter 2 numbers after command.");
                }
            }
            // draw square command
            else if (_commandList[0].Equals("square"))
            {
                try
                {
                    if (_commandList.Length > 2)
                    {
                        MessageBox.Show(@"Too many parameters.");
                    }
                    else
                    {
                        try
                        {
                            _squareDraw.DrawSquare(int.Parse(_commandList[1]));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show(@"Parameters must be a number!");
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show(@"Must enter a number after command.");
                }
            }
            // draw rectangle command
            else if (_commandList[0].Equals("rectangle"))
            {
                try
                {
                    if (_commandList.Length > 3)
                    {
                        MessageBox.Show(@"Too many parameters.");
                    }
                    else
                    {
                        try
                        {
                            _rectangleDraw.DrawRectangle(int.Parse(_commandList[1]),
                                                         int.Parse(_commandList[2]));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show(@"Parameters must be a number!");
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show(@"Must enter 2 numbers after command.");
                }
            }
            // draw circle command
            else if (_commandList[0].Equals("circle"))
            {
                try
                {
                    if (_commandList.Length > 2)
                    {
                        MessageBox.Show(@"Too many parameters.");
                    }
                    else
                    {
                        try
                        {
                            _circleDraw.DrawCircle(int.Parse(_commandList[1]));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show(@"Parameters must be a number!");
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show(@"Must enter a number after command.");
                }
            }
            // set fill true command
            else if (_commandList[0].Equals("fill"))
            {
                Fill.CheckFill(true);
                fillCheckBox.Checked = true;
            }
            // set fill false command
            else if (_commandList[0].Equals("filloff"))
            {
                Fill.CheckFill(false);
                fillCheckBox.Checked = false;
            }
            // draw triangle command
            else if (_commandList[0].Equals("triangle"))
            {
                try
                {
                    if (_commandList.Length > 5)
                    {
                        MessageBox.Show(@"Too many parameters.");
                    }
                    else
                    {
                        try
                        {
                            _triangleDraw.DrawTriangle(int.Parse(_commandList[1]), int.Parse(_commandList[2]),
                                                       int.Parse(_commandList[3]), int.Parse(_commandList[4]));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show(@"Parameters must be a number!");
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show(@"Must enter 4 numbers after command.");
                }
            }
            // change pen colour command
            else if (_commandList[0].Equals("pencolour"))
            {
                PenColourClass.PenColourSet(_commandList[1]);
            }
            // reset pen position command
            else if (_commandList[0].Equals("reset"))
            {
                Reset.CheckReset(true);
            }
            // clear bitmap
            else if (_commandList[0].Equals("clear"))
            {
                ClearImage();
                drawBox.Refresh();
            }
            // leave application
            else if (_commandList[0].Equals("quit"))
            {
                Application.Exit();
            }
            // if nothing entered throw message
            else if (_commandList[0] == String.Empty)
            {
                MessageBox.Show(@"No command entered!");
            }
            // if no command recognised show error
            else
            {
                MessageBox.Show(@"Command not recognised!");
            }

            commandLine.Text = "";
            Refresh();
        }