New to the forum, and I am stuck on the logic of creating an abstract class from a pretty basic function. I know how inherit and override works with abstract classes, but I can't figure out the logic behind converting this function to an abstract class. Any help would be appreciated.
To add to this, I am doing this to help me understand the fundamentals and view what other options or good practices I should apply. Thanks again for any help.
Code:
private readonly List<Shape> Square1 = new List<Shape>();
private void GenerateSquare()
{
Shape newSquare = RandomSquareLocation();
while (Square1.Any(square => square.X == newSquare.X && square.Y == newSquare.Y))
{
newSquare = RandomSquareLocation();
}
Square1.Add(newSquare);
}
private Shape RandomSquareLocation()
{
int maxXPosition = pictureBox1.Size.Width / playerOne.Width;
int maxYPosition = pictureBox1.Size.Height / playerOne.Height;
return new Shape { X = random.Next(0, maxXPosition), Y = random.Next(0, maxYPosition) };
}
private readonly List<Shape> Square1 = new List<Shape>();
private void GenerateSquare()
{
Shape newSquare = RandomSquareLocation();
while (Square1.Any(square => square.X == newSquare.X && square.Y == newSquare.Y))
{
newSquare = RandomSquareLocation();
}
Square1.Add(newSquare);
}
private Shape RandomSquareLocation()
{
int maxXPosition = pictureBox1.Size.Width / playerOne.Width;
int maxYPosition = pictureBox1.Size.Height / playerOne.Height;
return new Shape { X = random.Next(0, maxXPosition), Y = random.Next(0, maxYPosition) };
}
The GenerateSquare
is just going to spawn a Square somewhere on the pictureBox. The reason at least for my point of view to why I need abstract class for this is. GenerateSquare
function would need to be replemented over and over again if there a need for multiple different Squeares. The RandomSquareLocation
function acts as a base for the position that the squares spawn