From 789f74b5445b0c265fec8319b2bdb5cf06df500f Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Fri, 9 Oct 2020 04:19:22 +0100 Subject: [PATCH] Added PenControl and Shape classes in Command --- .../Advanced Software Engineering/Command.cs | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering/Command.cs b/Advanced Software Engineering/Advanced Software Engineering/Command.cs index e486bf0..f39013e 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Command.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Command.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -47,6 +47,8 @@ namespace Advanced_Software_Engineering { { "moveto", typeof(MoveTo) }, { "drawto", typeof(DrawTo) }, + { "line", null }, + { "dot", null }, { "clear", null}, { "rectangle", null }, { "circle", null }, @@ -70,7 +72,7 @@ namespace Advanced_Software_Engineering { get { - return new List> { + return new List> { new List { typeof(Drawer), typeof(int), typeof(int) }, new List { typeof(Drawer), typeof(Point) } }; @@ -114,6 +116,67 @@ namespace Advanced_Software_Engineering } } + abstract class Shape : Verb + { + protected Drawer drawer; + protected Point[] vertices; + private List lineVerbs; + + Shape(Drawer drawer, params Point[] vertices) + { + switch (vertices.Length) + { + case 0: + throw new Exception("Cannot create shape with no vertices."); + case 1: + throw new Exception("Cannot create shape with only one vertex. Are you thinking of 'dot'?"); + case 2: + throw new Exception("Cannot create shape with only two verticies. Are you thinking of 'drawto'/'moveto'/'lineto'?"); + } + + lineVerbs.Add(new PenControl(drawer, false)); + + for (int i = 1; i < vertices.Length; i++) + { + lineVerbs.Add(new DrawTo(drawer, vertices[i])); + } + + } + + public override void ExecuteVerb() + { + + } + + } + + class PenControl : Verb + { + public override List> acceptedTypes + { + get + { + return new List> { + new List { typeof(Drawer), typeof(bool) } + }; + } + } + + bool penStatus; + Drawer drawer; + + public PenControl(Drawer drawer, bool down) + { + penStatus = down; + this.drawer = drawer; + } + + public override void ExecuteVerb() + { + drawer.setPen(penStatus); + } + } + abstract class Value {