Basic reformatting

This commit is contained in:
Lukasz Baldyga committed 2020-10-13 17:51:49 +01:00
1 parent 456aec28b7
commit 8a63dbae2f
3 files changed
+43 -88

No files matched your search

@@ -9,59 +9,45 @@ using System.Windows.Forms;
using System.Windows.Forms.VisualStyles; using System.Windows.Forms.VisualStyles;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace Advanced_Software_Engineering namespace Advanced_Software_Engineering {
{ class VerbFactory {
class VerbFactory public static Verb MakeVerb(Drawer drawer, string fullCommand) {
{
public static Verb MakeVerb(Drawer drawer, string fullCommand)
{
Dictionary<string, string[]> commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand); Dictionary<string, string[]> commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
string command = commandAndParameters["command"][0]; string command = commandAndParameters["command"][0];
string[] parameters = commandAndParameters["parameters"]; string[] parameters = commandAndParameters["parameters"];
switch (command) switch (command) {
{
case "moveto": case "moveto":
//Check parameters //Check parameters
if (parameters.Length == 2) if (parameters.Length == 2) {
{ try {
try
{
return new return new
MoveTo(drawer, MoveTo(drawer,
SettingsAndHelperFunctions.ConvertToInt(parameters[0]), SettingsAndHelperFunctions.ConvertToInt(parameters[0]),
SettingsAndHelperFunctions.ConvertToInt(parameters[1])); SettingsAndHelperFunctions.ConvertToInt(parameters[1]));
} } catch (Exception e) {
catch (Exception e)
{
throw e; throw e;
} }
} } else throw new Exception("Command has an incorrect number of parameters");
else throw new Exception("Command has an incorrect number of parameters");
case "drawto": case "drawto":
case "line": case "line":
case "lineto": case "lineto":
//Check parameters //Check parameters
if (parameters.Length == 2) if (parameters.Length == 2) {
{ try {
try
{
return new return new
DrawTo(drawer, DrawTo(drawer,
SettingsAndHelperFunctions.ConvertToInt(parameters[0]), SettingsAndHelperFunctions.ConvertToInt(parameters[0]),
SettingsAndHelperFunctions.ConvertToInt(parameters[1])); SettingsAndHelperFunctions.ConvertToInt(parameters[1]));
} } catch (Exception e) {
catch (Exception e)
{
throw e; throw e;
} }
} } else throw new Exception("Command has an incorrect number of parameters");
else throw new Exception("Command has an incorrect number of parameters");
case "dot": case "dot":
case "clear": case "clear":
@@ -82,61 +68,51 @@ namespace Advanced_Software_Engineering
} }
} }
public interface Verb public interface Verb {
{
void ExecuteVerb(); void ExecuteVerb();
} }
class MoveTo : Verb class MoveTo : Verb {
{
protected Drawer drawer; protected Drawer drawer;
protected Point moveToPoint; protected Point moveToPoint;
public MoveTo(Drawer drawer, int x, int y) public MoveTo(Drawer drawer, int x, int y) {
{
this.drawer = drawer; this.drawer = drawer;
this.moveToPoint = new Point(x, y); this.moveToPoint = new Point(x, y);
} }
public MoveTo(Drawer drawer, Point point) public MoveTo(Drawer drawer, Point point) {
{
this.drawer = drawer; this.drawer = drawer;
this.moveToPoint = point; this.moveToPoint = point;
} }
public void ExecuteVerb() public void ExecuteVerb() {
{
this.drawer.MovePen(moveToPoint); this.drawer.MovePen(moveToPoint);
} }
} }
class DrawTo : MoveTo class DrawTo : MoveTo {
{
public DrawTo(Drawer drawer, int x, int y) : base(drawer, x, y) { } public DrawTo(Drawer drawer, int x, int y) : base(drawer, x, y) { }
public DrawTo(Drawer drawer, Point point) : base(drawer, point) { } public DrawTo(Drawer drawer, Point point) : base(drawer, point) { }
public new void ExecuteVerb() public new void ExecuteVerb() {
{
this.drawer.DrawLine(moveToPoint); this.drawer.DrawLine(moveToPoint);
} }
} }
abstract class Shape : Verb abstract class Shape : Verb {
{
protected Drawer drawer; protected Drawer drawer;
protected Point[] vertices; protected Point[] vertices;
private List<Verb> lineVerbs; private List<Verb> lineVerbs;
Shape(Drawer drawer, Point[] vertices) Shape(Drawer drawer, Point[] vertices) {
{
//Throw exceptions if impossible to create Spape Verb //Throw exceptions if impossible to create Spape Verb
switch (vertices.Length) switch (vertices.Length) {
{
case 0: case 0:
throw new Exception("Cannot create shape with no vertices."); throw new Exception("Cannot create shape with no vertices.");
case 1: case 1:
@@ -149,8 +125,7 @@ namespace Advanced_Software_Engineering
} }
public void ExecuteVerb() public void ExecuteVerb() {
{
foreach (Verb verb in lineVerbs) verb.ExecuteVerb(); foreach (Verb verb in lineVerbs) verb.ExecuteVerb();
} }
} }
@@ -158,24 +133,20 @@ namespace Advanced_Software_Engineering
/// <summary> /// <summary>
/// A class that generates sets /// A class that generates sets
/// </summary> /// </summary>
class RegularPolygons : Verb class RegularPolygons : Verb {
{
List<Verb> verbs; List<Verb> verbs;
RegularPolygons(Drawer drawer, Point origin, int sides, int scale) RegularPolygons(Drawer drawer, Point origin, int sides, int scale) {
{
} }
public void ExecuteVerb() public void ExecuteVerb() {
{
} }
} }
abstract class Value abstract class Value {
{
} }
@@ -3,13 +3,11 @@ using System.Collections.Generic;
using System.Security.Policy; using System.Security.Policy;
using System.Windows.Forms; using System.Windows.Forms;
namespace Advanced_Software_Engineering namespace Advanced_Software_Engineering {
{
/// <summary> /// <summary>
/// This class simply provides settings and some functions that are used across many components. /// This class simply provides settings and some functions that are used across many components.
/// </summary> /// </summary>
public class SettingsAndHelperFunctions public class SettingsAndHelperFunctions {
{
/// <summary> /// <summary>
/// The variable simply keep track of the windows that are currently shown (excluding <see cref="MainMenu"/>). /// The variable simply keep track of the windows that are currently shown (excluding <see cref="MainMenu"/>).
/// </summary> /// </summary>
@@ -18,11 +16,9 @@ namespace Advanced_Software_Engineering
/// <summary> /// <summary>
/// This helper function is executed when a window is closed. It shows the <see cref="MainMenu"/> when the count is 0 /// This helper function is executed when a window is closed. It shows the <see cref="MainMenu"/> when the count is 0
/// </summary> /// </summary>
public static void WindowClosed() public static void WindowClosed() {
{
NumberOfWindows--; NumberOfWindows--;
if (NumberOfWindows == 0) if (NumberOfWindows == 0) {
{
System.Console.WriteLine("Showing MainMenu"); System.Console.WriteLine("Showing MainMenu");
Program.MainMenu.Show(); Program.MainMenu.Show();
} }
@@ -49,21 +45,18 @@ namespace Advanced_Software_Engineering
/// Console.WriteLine(b); // => "a simple sentence surrounded by spaces"; /// Console.WriteLine(b); // => "a simple sentence surrounded by spaces";
/// </code> /// </code>
/// </example> /// </example>
public static string Strip(string text) public static string Strip(string text) {
{
//Console.WriteLine("Stripping: '" + text + "'"); //Console.WriteLine("Stripping: '" + text + "'");
int start; int start;
for (start = 0; start < text.Length; start++) for (start = 0; start < text.Length; start++) {
{
char character = text[start]; char character = text[start];
if (character != " "[0]) break; if (character != " "[0]) break;
} }
int end; int end;
for (end = text.Length - 1; end >= 0; end--) for (end = text.Length - 1; end >= 0; end--) {
{
char character = text[end]; char character = text[end];
if (character != " "[0]) break; if (character != " "[0]) break;
} }
@@ -78,18 +71,15 @@ namespace Advanced_Software_Engineering
} }
public static int ConvertToInt(string text) public static int ConvertToInt(string text) {
{
text = Strip(text); text = Strip(text);
return int.Parse(text); return int.Parse(text);
} }
public static List<string> StripStringArray(string[] array) public static List<string> StripStringArray(string[] array) {
{
List<string> newStringList = new List<string>(); List<string> newStringList = new List<string>();
foreach (string arrayElement in array) foreach (string arrayElement in array) {
{
string strippedElement = Strip(arrayElement); string strippedElement = Strip(arrayElement);
if (strippedElement.Length == 0) continue; if (strippedElement.Length == 0) continue;
else newStringList.Add(strippedElement); else newStringList.Add(strippedElement);
@@ -98,8 +88,7 @@ namespace Advanced_Software_Engineering
return newStringList; return newStringList;
} }
public static Dictionary<string, string[]> CommandAndParameterParser(string text) public static Dictionary<string, string[]> CommandAndParameterParser(string text) {
{
Dictionary<string, string[]> commandAndParameters = new Dictionary<string, string[]>(); Dictionary<string, string[]> commandAndParameters = new Dictionary<string, string[]>();
//split the command from the parameters //split the command from the parameters
@@ -8,28 +8,23 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace Advanced_Software_Engineering namespace Advanced_Software_Engineering {
{ public partial class Text_Editor : Form {
public partial class Text_Editor : Form
{
const string DefaultTitleString = "Advanced Software Engineering - Text Editor "; const string DefaultTitleString = "Advanced Software Engineering - Text Editor ";
/// <summary> /// <summary>
/// The text editor is the main window that the user will be using for writing code. /// The text editor is the main window that the user will be using for writing code.
/// </summary> /// </summary>
public Text_Editor() public Text_Editor() {
{
SettingsAndHelperFunctions.NumberOfWindows++; SettingsAndHelperFunctions.NumberOfWindows++;
InitializeComponent(); InitializeComponent();
} }
private void Console_FormClosed(object sender, FormClosedEventArgs e) private void Console_FormClosed(object sender, FormClosedEventArgs e) {
{
SettingsAndHelperFunctions.WindowClosed(); SettingsAndHelperFunctions.WindowClosed();
} }
private void newFileToolStripMenuItem_Click(object sender, EventArgs e) private void newFileToolStripMenuItem_Click(object sender, EventArgs e) {
{
new Text_Editor().Show(); new Text_Editor().Show();
} }
} }