using System;
using [Link];
using SplashKitSDK;
namespace ShapeCalculator
{
public class Program
{
private enum ShapeKind
{
Square,
Triangle,
Circle,
Trapezium,
Rectangle
}
public static void Main()
{
// WIll create a directory for the saved drawings
[Link]("SavedDrawings");
while (true)
{
int choice = GetValidatedChoice();
// Exit the program if 7 is entered
if (choice == 7)
{
break;
}
// Load a saved shape if 6 is entered
if (choice == 6)
{
[Link]("Enter the filename to load: ");
string fileName = [Link]();
ShapeLoader loader = new
ShapeLoader($"SavedDrawings/{fileName}.txt");
Shape loadedShape = [Link]();
if (loadedShape != null)
{
[Link]($"Loaded shape:
{[Link]().Name}");
[Link]($"Area:
{[Link]()}");
[Link]($"Perimeter:
{[Link]()}");
DrawShape(loadedShape);
}
else
{
[Link]("Failed to load shape.");
}
continue; // Skip the rest of the loop and ask for
choice again
}
// Create a shape based on the user's choice
ShapeKind kind = (ShapeKind)(choice - 1);
Shape shape = CreateShape(kind);
if (shape != null)
{
[Link]($"Area: {[Link]()}");
[Link]($"Perimeter:
{[Link]()}");
[Link]("Do you want a visual representation?
(yes/no)");
string response = [Link]();
// Draw the shape if the user wants a visual
representation
if ([Link]() == "yes")
{
DrawShape(shape);
}
// Save the shape if the user wants to save it
[Link]("Do you want to save the shape?
(yes/no)");
response = [Link]();
if ([Link]() == "yes")
{
[Link]("Enter the filename to save: ");
string fileName = [Link]();
ShapeSaver saver = new
ShapeSaver($"SavedDrawings/{fileName}.txt");
[Link](shape);
[Link]("Shape saved successfully.");
}
}
}
}
// Get a validated choice from the user
private static int GetValidatedChoice()
{
int choice;
while (true)
{
[Link]("Choose a shape to create:");
[Link]("1. Square");
[Link]("2. Triangle");
[Link]("3. Circle");
[Link]("4. Trapezium");
[Link]("5. Rectangle");
[Link]("6. Load a shape");
[Link]("7. Exit");
if ([Link]([Link](), out choice) && choice
>= 1 && choice <= 7)
{
return choice;
}
else
{
[Link]("Invalid choice. Please enter a
number between 1 and 7.");
}
}
}
// Create a shape based on the user's choice
private static Shape CreateShape(ShapeKind kind)
{
Shape shape = null;
string color = [Link]("Enter the
color of the shape: ");
string unit = [Link]("Enter the unit
(inches/centimeters): ");
bool isInches = unit == "inches";
// Assign propertires to the shape based on its type
switch (kind)
{
case [Link]:
shape = new Square();
double sideLength =
[Link]("Enter the side
length: ");
((Square)shape).SideLength = isInches ?
[Link](sideLength) :
sideLength;
break;
case [Link]:
shape = new Triangle();
double baseLength =
[Link]("Enter the base
length: ");
double height =
[Link]("Enter the height:
");
((Triangle)shape).Base = isInches ?
[Link](baseLength) :
baseLength;
((Triangle)shape).Height = isInches ?
[Link](height) : height;
break;
case [Link]:
shape = new Circle();
double radius =
[Link]("Enter the radius:
");
((Circle)shape).Radius = isInches ?
[Link](radius) : radius;
break;
case [Link]:
shape = new Trapezium();
double base1 = [Link]("Enter
the first base length: ");
double base2 = [Link]("Enter
the second base length: ");
double trapeziumHeight =
[Link]("Enter the height:
");
((Trapezium)shape).Base1 = isInches ?
[Link](base1) : base1;
((Trapezium)shape).Base2 = isInches ?
[Link](base2) : base2;
((Trapezium)shape).Height = isInches ?
[Link](trapeziumHeight) :
trapeziumHeight;
break;
case [Link]:
shape = new Rectangle();
double width = [Link]("Enter
the width: ");
double rectangleHeight =
[Link]("Enter the height:
");
((Rectangle)shape).Width = isInches ?
[Link](width) : width;
((Rectangle)shape).Height = isInches ?
[Link](rectangleHeight) :
rectangleHeight;
break;
}
// Set the color of the shape
if (shape != null)
{
[Link] = [Link]();
//[Link]($"Shape color set to:
{[Link]([Link])}"); // Debug print
}
return shape;
}
// Draws the shape on a Splashkit window
private static void DrawShape(Shape shape)
{
Window window = new Window("Shape Drawer", 800, 600);
while (![Link])
{
[Link]();
[Link]([Link]);
[Link]();
[Link]();
}
[Link]();
}
}
}