bryan177mcsc: Just any book about object oriented design should do.
hyperfine:
First question: yes, but it's generally a bad idea for the function to include the name of the class. Also, although this design is fine, a more flexible design would not tie down a Bat as a subtype of Enemy, but rather would give Actors the concept of Factions or Sides. Such a design would accomodate more complex rules, such as allowing non-player actors to fight amongst themselves, or switch sides.
Second question: There are several reasons why an event-driven design is desirable:
* The code that decides how to "route" an event is in a single place.
* The code that is interested in the event is simpler, as it doesn't have to decide when the event happens.
* All the code is more organized.
I notice that you're checking for input in a Move() function. That's usually a bad sign. Event handling should happen very close to the main loop. Sort of like
1 2 3 4 5
|
while (running){
handle_events();
update_actor_states();
draw();
}
|
The input handling you're using is a symptom of not having the right control flow mechanisms. You'd like to be able to say thing.move(there), and when move() returns, thing is there. It's very difficult to accomplish without having a loop inside move().
There's a control flow mechanism that goes
beautifully with event-driven programming: coroutines. I would dare to say any game can be written more elegantly with coroutines than without. Unfortunately, not many languages support them, but Lua and C++ (through Boost.Coroutines) do.