diff --git a/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.Designer.cs b/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.Designer.cs index 3b08ff3..d4f11c6 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.Designer.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.Designer.cs @@ -45,6 +45,7 @@ this.button1.TabIndex = 0; this.button1.Text = "Submit"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.SubmitCommand); // // textBox1 // diff --git a/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.cs b/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.cs index ad5483b..bef01dc 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/DrawPreview.cs @@ -12,6 +12,10 @@ namespace Advanced_Software_Engineering { public partial class Draw_Preview : Form { + + Graphics graphics; + Commander commander; + /// /// The draw preview window. /// @@ -22,6 +26,8 @@ namespace Advanced_Software_Engineering { InitializeComponent(); SettingsAndHelperFunctions.NumberOfWindows++; + graphics = panel1.CreateGraphics(); + commander = new Commander(graphics); } private void DrawPreview_FormClosed(object sender, FormClosedEventArgs e) @@ -31,9 +37,16 @@ namespace Advanced_Software_Engineering private void DrawPreviewPane_Paint(object sender, PaintEventArgs e) { - Graphics g = e.Graphics; - Pen myBlackPen = new Pen(Color.Black, 5); + commander.DrawAllCommands(); + } + private void SubmitCommand(object sender, EventArgs e) + { + commander.ProcessCommands(textBox1.Text); + textBox1.Text = ""; + + //Makes sure that the panel updates + panel1.Invalidate(); } } } diff --git a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs index cb03603..6d89ab6 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs @@ -1,4 +1,6 @@ -using System.Security.Policy; +using System; +using System.Collections.Generic; +using System.Security.Policy; using System.Windows.Forms; namespace Advanced_Software_Engineering @@ -24,8 +26,99 @@ namespace Advanced_Software_Engineering System.Console.WriteLine("Showing MainMenu"); Program.MainMenu.Show(); } - + + } + /// + /// This function removes spaces from the start and the end of the text. This should be unit tested. + /// + /// Simply any string of any size + /// A string without spaces at the begining or the end + /// + /// For example + /// + /// string a = " a simple sentence surrounded by spaces "; + /// string b = StripSpaces(a); + /// Console.WriteLine(b); // => "a simple sentence surrounded by spaces"; + /// + /// + /// + /// The code won't remove internal double spaces: + /// + /// string a = " a simple sentence surrounded by spaces "; + /// string b = StripSpaces(a); + /// Console.WriteLine(b); // => "a simple sentence surrounded by spaces"; + /// + /// + public static string Strip(string text) + { + //Console.WriteLine("Stripping: '" + text + "'"); + int start; + + for (start = 0; start < text.Length; start++) + { + char character = text[start]; + if (character != " "[0]) break; + } + + int end; + + for (end = text.Length - 1; end >= 0; end--) + { + char character = text[end]; + if (character != " "[0]) break; + } + + string result = text.Substring(start, end - start + 1); + + //Console.WriteLine("Started at: " + start); + //Console.WriteLine("Ended at: " + end); + //Console.WriteLine("Result: " + result); + + return result; + } + public static int ConvertToInt(string text) + { + text = Strip(text); + return int.Parse(text); + } + + public static List StripStringArray(string[] array) + { + List newStringList = new List(); + + foreach (string arrayElement in array) + { + string strippedElement = Strip(arrayElement); + if (strippedElement.Length == 0) continue; + else newStringList.Add(strippedElement); + } + + return newStringList; + } + + public static Dictionary CommandAndParameterParser(string text) + { + Dictionary commandAndParameters = new Dictionary(); + + //split the command from the parameters + string[] parameters = Strip(text).Split(new char[] { " "[0] }, 2); + + //set command var + string command = Strip(parameters[0]); + commandAndParameters["command"] = new string[] { command }; + + //seperate all of the parameters by a comma + parameters = parameters[1].Split(","[0]); + + //Remove spaces around parameters + parameters = StripStringArray(parameters).ToArray(); + + //set parameter list + commandAndParameters["parameters"] = parameters; + + return commandAndParameters; + } } }