I'm having a design issue using the MVC. I've written the game so that the "game" loop lives inside the Controller.
The Controller is initialised a with a Model and a View.
The Controller is started (enters the "game" loop)
The game loop looks like this:
... and here is engine.stepOver()
public void stepOver()
if (currentGame != null && !currentGame.isGameOver())
I'm trying to decide on the mechanism for actually polling players for their moves. The implementation I am following is to have a queue of Command
objects in the Model, that encapsulate a method call on a Game
object using the Command pattern. These Command
s would then be executed in the stepOver()
method, in the order they were received. When this list is cleared, the method does some more calls on the Game
to check for a win condition or to move to the next player, and then finishes.
What I can't work is how to get the Command
s into the queue. At the moment I have a PlayerInterface
interface, that is implemented by an AIPlayerInterface
and runs in a separate thread, vaguely checking if a move is required of it and queueing one up if so. But I think I might run into concurrency issues and am not sure how to structure that. I'm also not to sure how to implement that interface for a human player, at the moment it is implemented directly by the View (the UserInterface
Is the thread based idea a good one, or can anyone throw in two cents about a better way of queueing commands by a set of players?