If you want to inform other classes about a state change, us use the 'observer pattern' (See: http://en.wikipedia.org/wiki/Observer_pattern). There are two parties:
- One party is "the object", which will change state. He has the duty to inform the others.
- The other party is "the observer". Multiple observers want to observe the state change of the object. So they want to be informed.
Try this:
class TheObject
{
public event EventHandler<GameStateEvents> StateChanged;
// If your object changes state, this function should be called. It informs all observers by invoking the StateChanged delegate.
protected virtual void OnStateChanged(GameStateEvents e)
{
if (StateChanged != null)
StateChanged(this, e);
}
}
class TheObserver
{
public TheObserver(TheObject o)
{
o.StateChanged += Object_StateChanged;
}
// This function is called by the object when the object changes state.
private void Object_StateChanged(object sender, GameStateEvents e)
{
}
}