I am trying to customize some simple 2D shapes that can be dragged around the window with the mouse. I want the shapes to record a collision when I drag one into the other. I have an interface.
interface ICollidable { bool CollidedWith(Shape other); }
Then I have an abstract Shape class that implements the above interface.
abstract class Shape : ICollidable { protected bool IsPicked { private set; get; } protected Form1 Form { private set; get; } protected int X { set; get; }
Then I have ten concrete classes of Circle, Square, Rectangle, etc. that extend the Shape class and implement abstract methods. What I would like to do is come up with a clean and elegant way to do collosion detection instead of having a large block of if statements in a CollidedWith method such as
public bool CollidedWith(Shape other) { if(other is Square) {
Does anyone have any ideas. This is a problem that I thought about before, but now Iβm only practicing.
source share