Moved Verb to IVerb

This commit is contained in:
Lukasz Baldyga committed 2020-11-15 05:43:04 +00:00
1 parent 73d6f40639
commit e10f2b3d07
22 files changed
+177 -176

No files matched your search

@@ -89,8 +89,9 @@
<Compile Include="Verbs\DrawingVerbs\ResetPen.cs" />
<Compile Include="Verbs\DrawingVerbs\Square.cs" />
<Compile Include="Verbs\DrawingVerbs\Triangle.cs" />
<Compile Include="Verbs\IValue.cs" />
<Compile Include="Verbs\ValueHelper.cs" />
<Compile Include="Verbs\Verb.cs" />
<Compile Include="Verbs\IVerb.cs" />
<Compile Include="Windows\AboutWindow.cs">
<SubType>Form</SubType>
</Compile>
@@ -9,7 +9,7 @@ namespace Advanced_Software_Engineering {
/// </summary>
public class Commander {
private Graphics graphics;
private List<Verb> commands = new List<Verb>();
private List<IVerb> commands = new List<IVerb>();
private Drawer drawer;
private bool commands_ok = true;
@@ -22,8 +22,8 @@ namespace Advanced_Software_Engineering {
drawer.ResetDrawer();
drawer.SetGraphics(updateGraphicsElement);
foreach (Verb verb in this.commands) {
verb.ExecuteVerb();
foreach (IVerb IVerb in this.commands) {
IVerb.ExecuteVerb();
}
}
@@ -58,10 +58,10 @@ namespace Advanced_Software_Engineering {
}
/// <summary>
/// Adds a verb to the command list to be executed.
/// Adds a IVerb to the command list to be executed.
/// </summary>
/// <param name="command">Verb to be added. <seealso cref="Verb"/></param>
public void AddCommand(Verb command) {
/// <param name="command">IVerb to be added. <seealso cref="IVerb"/></param>
public void AddCommand(IVerb command) {
commands.Add(command);
}
@@ -108,8 +108,8 @@ namespace Advanced_Software_Engineering {
Console.WriteLine("\n\nHere is what the program is going to do:");
Console.WriteLine("Set origin to 0, 0");
foreach (Verb verb in this.commands) {
Console.WriteLine(verb.GetDescription());
foreach (IVerb IVerb in this.commands) {
Console.WriteLine(IVerb.GetDescription());
}
}
@@ -131,7 +131,7 @@ namespace Advanced_Software_Engineering {
/// Removes all commands from the Commander and resets the drawer.
/// </summary>
public void RemoveAllCommands() {
commands = new List<Verb>();
commands = new List<IVerb>();
drawer.ResetDrawer();
}
@@ -141,7 +141,7 @@ namespace Advanced_Software_Engineering {
/// <returns>Explanation of all the commands</returns>
public string ExplainCommands() {
string desc = "";
foreach (Verb command in commands) {
foreach (IVerb command in commands) {
desc += command.GetDescription() + Environment.NewLine;
}
return desc;
@@ -1,14 +1,14 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// Circle Verb class.
/// Circle IVerb class.
/// </summary>
public class Circle : Verb {
public class Circle : IVerb {
private Drawer drawer;
private double scale;
/// <summary>
/// Circle constructor creates the Circle verb.
/// Circle constructor creates the Circle IVerb.
/// </summary>
/// <param name="drawer">drawer</param>
/// <param name="scale">scale of the circle</param>
@@ -18,7 +18,7 @@
}
/// <summary>
/// Execute the Circle verb, which is to draw a circle with the drawer.
/// Execute the Circle IVerb, which is to draw a circle with the drawer.
/// </summary>
public void ExecuteVerb() {
drawer.DrawCircle(scale);
@@ -1,13 +1,13 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The Clear Verb class.
/// The Clear IVerb class.
/// </summary>
public class Clear : Verb {
public class Clear : IVerb {
private Drawer drawer;
/// <summary>
/// Create the clear Verb
/// Create the clear IVerb
/// </summary>
/// <param name="drawer"></param>
public Clear(Drawer drawer) {
@@ -15,7 +15,7 @@
}
/// <summary>
/// Execute the clear verb. It clears the drawer.
/// Execute the clear IVerb. It clears the drawer.
/// </summary>
public void ExecuteVerb() => drawer.ClearCanvas();
@@ -1,13 +1,13 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The Dot Verb class
/// The Dot IVerb class
/// </summary>
public class Dot : Verb {
public class Dot : IVerb {
private Drawer drawer;
/// <summary>
/// Creates the Dot Verb
/// Creates the Dot IVerb
/// </summary>
/// <param name="drawer"></param>
public Dot(Drawer drawer) {
@@ -3,9 +3,9 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// DrawLines Verb class
/// DrawLines IVerb class
/// </summary>
public class DrawLines : Verb {
public class DrawLines : IVerb {
private Drawer drawer;
private Point[] points;
@@ -3,9 +3,9 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// DrawTo Verb class
/// DrawTo IVerb class
/// </summary>
public class DrawTo : Verb {
public class DrawTo : IVerb {
private Drawer drawer;
private Point moveToPoint;
@@ -1,9 +1,9 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// Fill Verb class
/// Fill IVerb class
/// </summary>
public class Fill : Verb {
public class Fill : IVerb {
private Drawer drawer;
private bool enable;
@@ -28,7 +28,7 @@
/// <summary>
/// Describes what the command will do
/// </summary>
/// <returns>Description of what the verb will do</returns>
/// <returns>Description of what the IVerb will do</returns>
public string GetDescription() {
if (enable) return "Enable fill";
else return "Disable fill";
@@ -3,9 +3,9 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The FillColor Verb class
/// The FillColor IVerb class
/// </summary>
public class FillColor : Verb {
public class FillColor : IVerb {
private Drawer drawer;
private Color color;
@@ -3,9 +3,9 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// MoveTo Verb class
/// MoveTo IVerb class
/// </summary>
public class MoveTo : Verb {
public class MoveTo : IVerb {
private Drawer drawer;
private Point moveToPoint;
@@ -3,9 +3,9 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The PenColor Verb class
/// The PenColor IVerb class
/// </summary>
public class PenColor : Verb {
public class PenColor : IVerb {
private Drawer drawer;
private Color color;
@@ -3,10 +3,10 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The Quadrilateral Verb class
/// The Quadrilateral IVerb class
/// </summary>
public class Quadrilateral : Verb {
private Verb verb;
public class Quadrilateral : IVerb {
private IVerb IVerb;
/// <summary>
/// Creates a Quadrilateral instances
@@ -17,18 +17,18 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <param name="point3">third point</param>
/// <param name="point4">fourth point</param>
public Quadrilateral(Drawer drawer, Point point1, Point point2, Point point3, Point point4) {
verb = new DrawLines(drawer, new Point[] { point1, point2, point3, point4 });
IVerb = new DrawLines(drawer, new Point[] { point1, point2, point3, point4 });
}
/// <summary>
/// Draws a quadrilateral from the points
/// </summary>
public void ExecuteVerb() => verb.ExecuteVerb();
public void ExecuteVerb() => IVerb.ExecuteVerb();
/// <summary>
/// Describes all of the points
/// </summary>
/// <returns>Description of the quadrilateral points</returns>
public string GetDescription() => verb.GetDescription();
public string GetDescription() => IVerb.GetDescription();
}
}
@@ -5,12 +5,12 @@ using System.Drawing;
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// Rectangle Verb class
/// Rectangle IVerb class
/// </summary>
/// <todo>
/// Correct
/// </todo>
public class Rectangle : Verb {
public class Rectangle : IVerb {
private Drawer drawer;
private PointF[] points;
@@ -5,9 +5,9 @@ using System.Drawing;
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// A class that generates a RegularPolygon verb.
/// A class that generates a RegularPolygon IVerb.
/// </summary>
public class RegularPolygon : Verb {
public class RegularPolygon : IVerb {
private Drawer drawer;
private int sides;
private double scale;
@@ -3,11 +3,11 @@
/// <summary>
/// Setsets the pen to the initial position.
/// </summary>
public class ResetPen : Verb {
public class ResetPen : IVerb {
private Drawer drawer;
/// <summary>
/// Creates the ResetPen verb
/// Creates the ResetPen IVerb
/// </summary>
/// <param name="drawer">drawer</param>
public ResetPen(Drawer drawer) {
@@ -1,10 +1,10 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The Square Verb class
/// The Square IVerb class
/// </summary>
public class Square : Verb {
private Verb verb;
public class Square : IVerb {
private IVerb IVerb;
/// <summary>
/// A new Squre instance. Draws squares using <see cref="RegularPolygon"/>
@@ -12,7 +12,7 @@
/// <param name="drawer">drawer</param>
/// <param name="scale">size of the square</param>
public Square(Drawer drawer, double scale) {
verb = new RegularPolygon(drawer, 4, scale);
IVerb = new RegularPolygon(drawer, 4, scale);
}
/// <summary>
@@ -22,18 +22,18 @@
/// <param name="scale">size of the square</param>
/// <param name="offset">rotation offset in degrees</param>
public Square(Drawer drawer, double scale, double offset) {
verb = new RegularPolygon(drawer, 4, scale, offset);
IVerb = new RegularPolygon(drawer, 4, scale, offset);
}
/// <summary>
/// Draws the regular polygon (square)
/// </summary>
public void ExecuteVerb() => verb.ExecuteVerb();
public void ExecuteVerb() => IVerb.ExecuteVerb();
/// <summary>
/// Gets description of how it will draw the regular polygon (square)
/// </summary>
/// <returns></returns>
public string GetDescription() => verb.GetDescription();
public string GetDescription() => IVerb.GetDescription();
}
}
@@ -3,10 +3,10 @@
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <summary>
/// The Triangle Verb class
/// The Triangle IVerb class
/// </summary>
public class Triangle : Verb {
private Verb verb;
public class Triangle : IVerb {
private IVerb IVerb;
/// <summary>
/// Creates a new Triangle instance using <see cref="RegularPolygon"/>.
@@ -14,7 +14,7 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <param name="drawer">drawer</param>
/// <param name="scale">the scale of the triangle</param>
public Triangle(Drawer drawer, double scale) {
verb = new RegularPolygon(drawer, 3, scale);
IVerb = new RegularPolygon(drawer, 3, scale);
}
/// <summary>
@@ -24,7 +24,7 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <param name="scale">the scale of the triangle</param>
/// <param name="offset">the offset of the triangle in degrees</param>
public Triangle(Drawer drawer, double scale, double offset) {
verb = new RegularPolygon(drawer, 3, scale, offset);
IVerb = new RegularPolygon(drawer, 3, scale, offset);
}
/// <summary>
@@ -35,18 +35,18 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
/// <param name="point2">second point</param>
/// <param name="point3">third point</param>
public Triangle(Drawer drawer, Point point1, Point point2, Point point3) {
verb = new DrawLines(drawer, new Point[] { point1, point2, point3 });
IVerb = new DrawLines(drawer, new Point[] { point1, point2, point3 });
}
/// <summary>
/// Executes the created verb, either <see cref="RegularPolygon"/> or <see cref="DrawLines"/>.
/// Executes the created IVerb, either <see cref="RegularPolygon"/> or <see cref="DrawLines"/>.
/// </summary>
public void ExecuteVerb() => verb.ExecuteVerb();
public void ExecuteVerb() => IVerb.ExecuteVerb();
/// <summary>
/// Describes how the triangle will be drawn
/// </summary>
/// <returns>Description of how the triangle will be drawn</returns>
public string GetDescription() => verb.GetDescription();
public string GetDescription() => IVerb.GetDescription();
}
}
@@ -0,0 +1,19 @@
namespace Advanced_Software_Engineering {
/// <summary>
/// IVerb is an interface for executing and getting the descriptions of Verbs. Some Verbs draw lines, some verbs will assign
/// </summary>
public interface IVerb {
/// <summary>
/// This executes the IVerb to the drawer inside it.
/// </summary>
void ExecuteVerb();
/// <summary>
/// The description of what the IVerb will do.
/// </summary>
/// <returns>A string description of what the IVerb will do</returns>
string GetDescription();
}
}
@@ -1,19 +0,0 @@
namespace Advanced_Software_Engineering {
/// <summary>
/// Verb is an interface for executing and getting the descriptions of Verbs. Some Verbs draw lines, some verbs will assign
/// </summary>
public interface Verb {
/// <summary>
/// This executes the verb to the drawer inside it.
/// </summary>
void ExecuteVerb();
/// <summary>
/// The description of what the Verb will do.
/// </summary>
/// <returns>A string description of what the Verb will do</returns>
string GetDescription();
}
}
@@ -12,15 +12,15 @@ namespace Advanced_Software_Engineering {
public class VerbFactory {
/// <summary>
/// This function returns a Verb from a command and drawer.
/// This function returns a IVerb from a command and drawer.
/// </summary>
/// <remarks>
/// This factory is specifically useful since it automatically converts the parameters to what they should be.
/// </remarks>
/// <param name="drawer">The drawer to affect</param>
/// <param name="fullCommand">The command as a string</param>
/// <returns>A verb that maches the command</returns>
public static Verb MakeVerb(Drawer drawer, string fullCommand) {
/// <returns>A IVerb that maches the command</returns>
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
Dictionary<string, string[]> commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
if (!commandAndParameters.Keys.Contains("command")) throw new Exception("There is no command to process");