4.1P - Drawing Program - Multiple Shape Kinds
4.1P - Drawing Program - Multiple Shape Kinds
Program.cs
using System;
using SplashKitSDK;
namespace Shapedrawerr
{
public class Program
{
private enum ShapeKind
{
Rectangle,
Circle,
Line
}
public static void Main()
{
if (SplashKit.KeyTyped(KeyCode.RKey))
{
kindToAdd = ShapeKind.Rectangle;
}
if (SplashKit.KeyTyped(KeyCode.LKey))
{
kindToAdd = ShapeKind.Line;
}
if (SplashKit.KeyTyped(KeyCode.CKey))
{
kindToAdd = ShapeKind.Circle;
}
//Start
//Use this to draw shape
if (SplashKit.MouseClicked(MouseButton.LeftButton))
{
if (kindToAdd == ShapeKind.Rectangle)
{
MyRectangle ShapeDrawn = new MyRectangle();
ShapeDrawn.X = SplashKit.MouseX();
ShapeDrawn.Y = SplashKit.MouseY();
drawShape.AddShape(ShapeDrawn);
}
if (kindToAdd == ShapeKind.Circle)
{
MyCircle ShapeDrawn = new MyCircle();
ShapeDrawn.X = SplashKit.MouseX();
ShapeDrawn.Y = SplashKit.MouseY();
drawShape.AddShape(ShapeDrawn);
}
if (kindToAdd == ShapeKind.Line)
Pass Task 4.1: Drawing Program — Multiple Shape Kinds
{
MyLine ShapeDrawn = new MyLine();
ShapeDrawn.X = SplashKit.MouseX();
ShapeDrawn.Y = SplashKit.MouseY();
drawShape.AddShape(ShapeDrawn);
}
Console.WriteLine("Mouse Left");
//End
if (SplashKit.MouseClicked(MouseButton.RightButton))
{
drawShape.SelectedShapeAt(SplashKit.MousePosition());
Console.WriteLine("Mouse Right");
}
//Start
//Additional Function
if (SplashKit.KeyDown(KeyCode.EscapeKey))
{
drawShape.ChangingShapeColor();
Console.WriteLine("ESC");
}
//End
if (SplashKit.KeyTyped(KeyCode.BackspaceKey) ||
SplashKit.KeyTyped(KeyCode.DeleteKey))
{
if (SplashKit.KeyTyped(KeyCode.BackspaceKey))
{
Console.WriteLine("Backspace");
}
if (SplashKit.KeyTyped(KeyCode.DeleteKey))
{
Console.WriteLine("Delete");
}
drawShape.RemoveShape();
}
if (SplashKit.KeyTyped(KeyCode.SpaceKey))
{
drawShape.Background = SplashKit.RandomRGBColor(255);
Console.WriteLine("SpaceKey");
}
drawShape.Draw();
SplashKit.RefreshScreen();
}
while (!SplashKit.WindowCloseRequested("Drawing Shape"));
}
}
}
Pass Task 4.1: Drawing Program — Multiple Shape Kinds
Shape.cs
using SplashKitSDK;
namespace Shapedrawerr
{
public abstract class Shape
{
private Color _color;
private float _x, _y;
private int _width, _height;
private bool _selected;
public float X
{
get
{
return _x;
}
set
{
_x = value;
}
}
public float Y
{
get
{
return _y;
}
set
{
_y = value;
}
}
return _selected;
}
set
{
_selected = value;
}
}
Drawing.cs
using SplashKitSDK;
namespace Shapedrawerr
{
}
}
}
}
MyRectangle.cs
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SplashKitSDK;
namespace Shapedrawerr
{
public class MyRectangle : Shape
{
private int _width, _height;
}
}
MyLine.cs
using SplashKitSDK;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shapedrawerr
{
public class MyLine : Shape
{
private int _length;
}
}
MyCircle.cs
using SplashKitSDK;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shapedrawerr
{
}
set
{
_radius = value;
}
}
}
}
Pass Task 4.1: Drawing Program — Multiple Shape Kinds