First, let me apologize for asking a question that may seem a bit vague (or poorly formalized), but I don't have enough experience to ask something more specific.
I create an engine for playing 2D adventure games (sort-by-you-on-object-and-something-happens) in C #, and I am considering the best structure for it. As you can imagine, different things can happen when you interact with an object: if it is a door, you expect to enter another room, if it is a person, you expect to start a conversation with them, etc. My idea is to achieve this behavior with delegates, for example:
public abstract class GameObject {
public delegate void onAction();
public onAction Click;
}
public class Door : GameObject {
public Door() {
Click = new onAction(ChangeRoom);
}
private void ChangeRoom() {
}
}
public class Person : GameObject {
public Person() {
Click = new onAction(StartTalking);
}
private void StartTalking() {
}
}
, , , , :
specialObject.Click += new onAction(SpecialMethod);
. , , , SpecialMethod - , . (de), , , . ?
P.S.: , , , , , .