Added some actions to Command

This commit is contained in:
Lukasz Baldyga committed 2020-10-08 17:43:13 +01:00
1 parent c3437c3d6d
commit f423716054
1 file changed
+61 -3
@@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
namespace Advanced_Software_Engineering namespace Advanced_Software_Engineering
{ {
@@ -29,7 +31,7 @@ namespace Advanced_Software_Engineering
public void ExecuteCommand() public void ExecuteCommand()
{ {
verb.ExecuteVerb();
} }
public Type getType() public Type getType()
@@ -43,16 +45,72 @@ namespace Advanced_Software_Engineering
{ {
public static Dictionary<string, Type> verbTypes = new Dictionary<string, Type>() public static Dictionary<string, Type> verbTypes = new Dictionary<string, Type>()
{ {
{ "moveto", typeof(MoveTo) } { "moveto", typeof(MoveTo) },
{ "drawto", typeof(DrawTo) },
{ "clear", null},
{ "rectangle", null },
{ "circle", null },
{ "triangle", null },
{ "pen", null},
{ "fill", null }
}; };
public abstract List<List<Type>> acceptedTypes {
get;
}
public abstract void ExecuteVerb();
} }
class MoveTo : Verb class MoveTo : Verb
{ {
public override List<List<Type>> acceptedTypes
{
get
{
return new List<List<Type>> {
new List<Type> { typeof(Drawer), typeof(int), typeof(int) },
new List<Type> { typeof(Drawer), typeof(Point) }
};
}
}
protected Drawer drawer;
protected Point moveToPoint;
public MoveTo(Drawer drawer, int x, int y)
{
this.drawer = drawer;
this.moveToPoint = new Point(x, y);
}
public MoveTo(Drawer drawer, Point point)
{
this.drawer = drawer;
this.moveToPoint = point;
}
public override void ExecuteVerb()
{
this.drawer.MovePen(moveToPoint);
}
}
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 override void ExecuteVerb()
{
bool penStatus = drawer.isPenDown();
if(!penStatus) drawer.PenDown();
base.ExecuteVerb();
if (!penStatus) drawer.PenUp();
}
} }
abstract class Value abstract class Value
@@ -60,7 +118,7 @@ namespace Advanced_Software_Engineering
} }
class FlowControl : Verb //This one will help us in part 2 class FlowControl //: Verb //This one will help us in part 2
{ {
} }