public class Circle :Shape
{
private int Radius
{
get { return Radius; }
set { if (Radius<12.5) Radius = value; }
}
public Circle()
{}
public Circle(int x, int y, ConsoleColor color, int radius) :base(x,y,color)
{
Radius = radius;
}
public override void InitWithRandomValues()
{
Random rnd = new Random();
X = rnd.Next(1, 80);
Y = rnd.Next(1, 25);
Color = (ConsoleColor)rnd.Next(Enum.GetNames(typeof(ConsoleColor)).Length);
Radius = rnd.Next(1, (int)12.5);
}
public override void Draw()
{
double angleStep = 1.0 / Radius;
Console.SetCursorPosition(X, Y);
Console.ForegroundColor = (System.ConsoleColor)color;
for (double angle = 0; angle <= 2 * Math.PI; angle += angleStep)
{
int x = (int)Math.Round(X + Radius * Math.Cos(angle));
int y = (int)Math.Round(Y + Radius * Math.Sin(angle));
Console.SetCursorPosition(x, y);
Console.Write("*");
}
}
public override double GetArea()
{
return (Math.PI * Radius * Radius);
}
public override double GetPerimeter()
{
return (2 * Math.PI * Radius);
}
public override void ShowDetails()
{
Console.Write("X" + X, "Y" + Y, "Color" + color, "Radius" + Radius + "Area" + GetArea() + "Perimeter" + GetPerimeter());
}
}
}