diff --git a/Advanced Software Engineering/Advanced Software Engineering/Command.cs b/Advanced Software Engineering/Advanced Software Engineering/Command.cs new file mode 100644 index 0000000..7bb32ad --- /dev/null +++ b/Advanced Software Engineering/Advanced Software Engineering/Command.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Advanced_Software_Engineering +{ + class Command + { + Type type; + Drawer drawer; + Verb verb; + + public Command(Drawer drawer, string command) + { + this.drawer = drawer; + + //Seperate Values + string[] commandAndParameters = command.Split(" "[0]); + + //Get command class + type = Verb.verbTypes[commandAndParameters[0]]; + + //Create the command's class + verb = (Verb) Activator.CreateInstance(type); + + } + + public void ExecuteCommand() + { + + } + + public Type getType() + { + return type; + } + + } + + abstract class Verb + { + public static Dictionary verbTypes = new Dictionary() + { + { "moveto", typeof(MoveTo) } + }; + + + + } + + class MoveTo : Verb + { + + } + + abstract class Value + { + + } + + class FlowControl : Verb //This one will help us in part 2 + { + + } +} diff --git a/Advanced Software Engineering/Advanced Software Engineering/CommandParser.cs b/Advanced Software Engineering/Advanced Software Engineering/CommandParser.cs index 65425dc..66ddb41 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/CommandParser.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/CommandParser.cs @@ -12,9 +12,9 @@ namespace Advanced_Software_Engineering Graphics graphics; List commands = new List(); + Drawer drawer; - - void DrawCommands() + void DrawAllCommands() { } @@ -22,11 +22,13 @@ namespace Advanced_Software_Engineering CommandParser(Graphics graphics) { this.graphics = graphics; + this.drawer = new Drawer(this.graphics); } - CommandParser(Graphics graphics, String rawCommands) + CommandParser(Graphics graphics, string rawCommands) { this.graphics = graphics; + this.drawer = new Drawer(this.graphics); this.ProcessCommands(rawCommands); } @@ -35,33 +37,41 @@ namespace Advanced_Software_Engineering commands.Add(command); } - void ProcessCommands(String rawCommands) + void ProcessCommands(string rawCommands) { //ignore case rawCommands = rawCommands.ToLower(); //isolate commands - String[] commands = rawCommands.Split(Environment.NewLine.ToCharArray()); + string[] commands = rawCommands.Split(Environment.NewLine.ToCharArray()); + + for(int i =0; i < commands.Length; i++) + { + commands[i] = SettingsAndHelperFunctions.StripSpaces(commands[i]); + } + + foreach(string rawCommand in commands) + { + //handle errors later + this.commands.Add(new Command(drawer, rawCommand)); + } } } - class Command - { - - - } - - class Verb - { - - - } - - class Value + class Drawer { + protected static Color defaultPenColor = new Color(); + protected static float defaultPenWidth = 1f; + Pen pen = new Pen(defaultPenColor, defaultPenWidth); + bool penDown = true; + Point penPosition; + public Drawer(Graphics graphics) + { + + } } } diff --git a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs index d70eb8e..f5746b2 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs @@ -1,4 +1,5 @@ -using System.Windows.Forms; +using System.Security.Policy; +using System.Windows.Forms; namespace Advanced_Software_Engineering { @@ -16,5 +17,27 @@ namespace Advanced_Software_Engineering } } + + public static string StripSpaces(string 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; + } + + return text.Substring(start, end); + + } } } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs b/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs index 6999c35..5f2b0e9 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs @@ -12,7 +12,7 @@ namespace Advanced_Software_Engineering { public partial class Text_Editor : Form { - const String DefaultTitleString = "Advanced Software Engineering - Text Editor "; + const string DefaultTitleString = "Advanced Software Engineering - Text Editor "; public Text_Editor() {