From 8a63dbae2f814297c16c87cf562f00fbcb8df540 Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Tue, 13 Oct 2020 17:51:49 +0100 Subject: [PATCH] Basic reformatting --- .../Advanced Software Engineering/Command.cs | 83 ++++++------------- .../SettingsAndHelperFunctions.cs | 33 +++----- .../Text Editor.cs | 15 ++-- 3 files changed, 43 insertions(+), 88 deletions(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering/Command.cs b/Advanced Software Engineering/Advanced Software Engineering/Command.cs index c723431..6a7088d 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Command.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Command.cs @@ -9,59 +9,45 @@ using System.Windows.Forms; using System.Windows.Forms.VisualStyles; using System.Xml.Serialization; -namespace Advanced_Software_Engineering -{ - class VerbFactory - { - public static Verb MakeVerb(Drawer drawer, string fullCommand) - { +namespace Advanced_Software_Engineering { + class VerbFactory { + public static Verb MakeVerb(Drawer drawer, string fullCommand) { Dictionary commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand); string command = commandAndParameters["command"][0]; string[] parameters = commandAndParameters["parameters"]; - switch (command) - { + switch (command) { case "moveto": //Check parameters - if (parameters.Length == 2) - { - try - { + if (parameters.Length == 2) { + try { return new MoveTo(drawer, SettingsAndHelperFunctions.ConvertToInt(parameters[0]), SettingsAndHelperFunctions.ConvertToInt(parameters[1])); - } - catch (Exception e) - { + } catch (Exception 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 "line": case "lineto": //Check parameters - if (parameters.Length == 2) - { - try - { + if (parameters.Length == 2) { + try { return new DrawTo(drawer, SettingsAndHelperFunctions.ConvertToInt(parameters[0]), SettingsAndHelperFunctions.ConvertToInt(parameters[1])); - } - catch (Exception e) - { + } catch (Exception 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 "clear": @@ -82,61 +68,51 @@ namespace Advanced_Software_Engineering } } - public interface Verb - { + public interface Verb { void ExecuteVerb(); } - class MoveTo : Verb - { + class MoveTo : Verb { protected Drawer drawer; protected Point moveToPoint; - public MoveTo(Drawer drawer, int x, int y) - { + public MoveTo(Drawer drawer, int x, int y) { this.drawer = drawer; this.moveToPoint = new Point(x, y); } - public MoveTo(Drawer drawer, Point point) - { + public MoveTo(Drawer drawer, Point point) { this.drawer = drawer; this.moveToPoint = point; } - public void ExecuteVerb() - { + public void ExecuteVerb() { 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, Point point) : base(drawer, point) { } - public new void ExecuteVerb() - { + public new void ExecuteVerb() { this.drawer.DrawLine(moveToPoint); } } - abstract class Shape : Verb - { + abstract class Shape : Verb { protected Drawer drawer; protected Point[] vertices; private List lineVerbs; - Shape(Drawer drawer, Point[] vertices) - { + Shape(Drawer drawer, Point[] vertices) { //Throw exceptions if impossible to create Spape Verb - switch (vertices.Length) - { + switch (vertices.Length) { case 0: throw new Exception("Cannot create shape with no vertices."); case 1: @@ -149,8 +125,7 @@ namespace Advanced_Software_Engineering } - public void ExecuteVerb() - { + public void ExecuteVerb() { foreach (Verb verb in lineVerbs) verb.ExecuteVerb(); } } @@ -158,24 +133,20 @@ namespace Advanced_Software_Engineering /// /// A class that generates sets /// - class RegularPolygons : Verb - { + class RegularPolygons : Verb { List 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 { } diff --git a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs index 6d89ab6..67af0f4 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs @@ -3,13 +3,11 @@ using System.Collections.Generic; using System.Security.Policy; using System.Windows.Forms; -namespace Advanced_Software_Engineering -{ +namespace Advanced_Software_Engineering { /// /// This class simply provides settings and some functions that are used across many components. /// - public class SettingsAndHelperFunctions - { + public class SettingsAndHelperFunctions { /// /// The variable simply keep track of the windows that are currently shown (excluding ). /// @@ -18,11 +16,9 @@ namespace Advanced_Software_Engineering /// /// This helper function is executed when a window is closed. It shows the when the count is 0 /// - public static void WindowClosed() - { + public static void WindowClosed() { NumberOfWindows--; - if (NumberOfWindows == 0) - { + if (NumberOfWindows == 0) { System.Console.WriteLine("Showing MainMenu"); Program.MainMenu.Show(); } @@ -49,21 +45,18 @@ namespace Advanced_Software_Engineering /// Console.WriteLine(b); // => "a simple sentence surrounded by spaces"; /// /// - public static string Strip(string text) - { + public static string Strip(string text) { //Console.WriteLine("Stripping: '" + text + "'"); int start; - for (start = 0; start < text.Length; 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--) - { + for (end = text.Length - 1; end >= 0; end--) { char character = text[end]; 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); return int.Parse(text); } - public static List StripStringArray(string[] array) - { + public static List StripStringArray(string[] array) { List newStringList = new List(); - foreach (string arrayElement in array) - { + foreach (string arrayElement in array) { string strippedElement = Strip(arrayElement); if (strippedElement.Length == 0) continue; else newStringList.Add(strippedElement); @@ -98,8 +88,7 @@ namespace Advanced_Software_Engineering return newStringList; } - public static Dictionary CommandAndParameterParser(string text) - { + public static Dictionary CommandAndParameterParser(string text) { Dictionary commandAndParameters = new Dictionary(); //split the command from the parameters diff --git a/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs b/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs index 5d83496..162b1a8 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Text Editor.cs @@ -8,28 +8,23 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace Advanced_Software_Engineering -{ - public partial class Text_Editor : Form - { +namespace Advanced_Software_Engineering { + public partial class Text_Editor : Form { const string DefaultTitleString = "Advanced Software Engineering - Text Editor "; /// /// The text editor is the main window that the user will be using for writing code. /// - public Text_Editor() - { + public Text_Editor() { SettingsAndHelperFunctions.NumberOfWindows++; InitializeComponent(); } - private void Console_FormClosed(object sender, FormClosedEventArgs e) - { + private void Console_FormClosed(object sender, FormClosedEventArgs e) { SettingsAndHelperFunctions.WindowClosed(); } - private void newFileToolStripMenuItem_Click(object sender, EventArgs e) - { + private void newFileToolStripMenuItem_Click(object sender, EventArgs e) { new Text_Editor().Show(); } }