I need to to make for school a simple “strategy game simulator”. To do this I need to make an Event Dispatcher (event loop) that will send the event to the registered parties. For example, I have resources on the map. One event is “resource at location 1 depleted”. And one “player” is interested on that event.
How would I create the dispatcher (and register one player for one particular event). Also, how does the dispatcher check for the event? Does it simply do something like if(resourceLocation1.getNoResource()==0) trigerEvent(); or is there some other, more elegant way.
I worked with event listeners (mostly in ActionScrip3) but never made a custom event and a custom event dispatcher. Any help is appreciated, including some links to some tutorials or sample codes.
If I am not clear what I am searching for please let me know and I will try to explain it better
Thanks.
Your
EventDispatcherdoes not need to check every possible condition and notify all possible listeners. Just notify listeners registered for a certain type of event.Register
Playerto be notified depending on the game eventThen your
Resourcewould supply an event when resources reached0Otherwise you are going to end up with a massive logic-containing event loop that eats up performance and will be difficult to debug.