I am currently designing a game suite which has at it's core a central set of properties, methods and sub-classes implemented in an abstract class TGameCore. Each game will be a descendant of this core, providing its own special implementation of the abstract methods defined in TGameCore.
Unit Game1 containing:
TGame1 = class(TGameCore)
+ implementation of abstract methods
Unit Game2 containing:
TGame2 = class(TGameCore)
+ different implementation of abstract methods
and MANY more Units
The display on the screen is handled by a separate form with a descendant of TGraphicControl being used as a drawing surface over the client area of the form.
My problem is that I want to link events occurring on the display form and drawing surface (e.g mouse events on the drawing surface and menu/speed button events on the form) to handlers within the TGameCore that is common to each game.
The question is how do I link this significant number of different events to a substantial number of different descendants of TGameCore? I don't know if it makes any difference, but there is only ever one game in existence at the same time. So the none of the events are never linked to two event handlers at the same moment.
I have read a bit about the use of interfaces. However, these only seem to talk about providing access to methods. Are they appropriate for the implementation of event handlers that are accessed via pointers to methods, rather than direct calls to the methods themselves? If so, how is this implemented?
Any advice on this or other more suitable approaches would be very much appreciated.
Unit Game1 containing:
TGame1 = class(TGameCore)
+ implementation of abstract methods
Unit Game2 containing:
TGame2 = class(TGameCore)
+ different implementation of abstract methods
and MANY more Units
The display on the screen is handled by a separate form with a descendant of TGraphicControl being used as a drawing surface over the client area of the form.
My problem is that I want to link events occurring on the display form and drawing surface (e.g mouse events on the drawing surface and menu/speed button events on the form) to handlers within the TGameCore that is common to each game.
The question is how do I link this significant number of different events to a substantial number of different descendants of TGameCore? I don't know if it makes any difference, but there is only ever one game in existence at the same time. So the none of the events are never linked to two event handlers at the same moment.
I have read a bit about the use of interfaces. However, these only seem to talk about providing access to methods. Are they appropriate for the implementation of event handlers that are accessed via pointers to methods, rather than direct calls to the methods themselves? If so, how is this implemented?
Any advice on this or other more suitable approaches would be very much appreciated.