In the past I have just had a bunch of functions in different classes that I could call. On the map I could check if a tile was blocked and then move the player. That meant that everything basically knew something about everything else. That meant that one change could spill over in multiple classes that didn't have anything to do with the original class.
This time I will try to make a command based system. A global commands list is available to all components. They then generate commands depending on what they want done and a commands processor then executes them. It all sounds weary nice, but at the moment, all I have is a vague idea about what it should look like, and no idea how to actually implement it.
My thoughts is that the processor should call a class that have an execute function, passing along any parameters with the command. The function then performs the action.
Lets say the player wants to move one tile to the left. Player presses "A" button on keyboard.
- A command with name = move and a string containing direction "west" is added to parameters and the player is added.
- Command is placed in the commands list.
- Command is extracted by the processor.
- Processor determines what class should be called "move" and calls execute with the given parameters.
- Move class execute function checks map, moves player