Private
Public Access
New class structure and supporting code
This commit is contained in:
1 parent
fa70df2119
commit
c3437c3d6d
4 files changed
+120
-20
No files matched your search
@@ -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<string, Type> verbTypes = new Dictionary<string, Type>()
|
||||
{
|
||||
{ "moveto", typeof(MoveTo) }
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class MoveTo : Verb
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
abstract class Value
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class FlowControl : Verb //This one will help us in part 2
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ namespace Advanced_Software_Engineering
|
||||
|
||||
Graphics graphics;
|
||||
List<Command> commands = new List<Command>();
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+24
-1
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user