Hi all,
Over the past few weeks, I have been creating a sort of text-based adventure game revolving entirely around the actions of a player. The general idea is that there is a Simulation class that maintains the state of the world, and is the responsibility of the SimulationController (ie, the player) to keep actions going. Most of the time, it will be said Controller that is telling the Simulation what to do (ie, simulate 1 timestep forward), but occasionally the Simulation needs to ask something of the controller. Thus, I have created an interface like so:
/**
* An interface to a GUI, command line, etc;
* a way to interact with the Simulation class
* @author dduckworth
*
*/
public interface SimulationController {
/**
* Returns the index of a choice from a list
*
* @param message: prompt for the player
* @param choices: options, in order
* @return: the index of the choice chosen
*/
public int chooseItem(String message, List<String> choices);
/**
* Returns some text the player must type in manually.
*
* @param message
* @return
*/
public String enterChoice(String message);
/**
* Give the user a message. This could be notification
* of a failed action, some response to some random event,
* anything.
*
* @param message
*/
public void giveMessage(String message);
/**
* The simulation this controller is controlling
* @return
*/
public Simulation getSimulation();
/**
* The primary loop for this controller. General flow
* should be something like this:
* 1) Prompt the player to choose a tool and target
* from getAvailableTools() and getAvailableTargets()
* 2) Prompt the player to choose an action from
* getAvailableActions()
* 3) call Simuluation.simulate() with the tool, target,
* action chosen, the time taken to make that decision,
* and this
* 4) while Simulation.isFinished() == false, continue onward
*/
public void run();
}
The main control loop in all this must be implemented in SimulationController.run()
, but the simulation can also call the other methods to request some information from the player.
I am currently using Adobe Flex with BlazeDS to create a very simple user interface that will communicate with the Simulation by implementing or holding something that implements the SimulationController
interface. There is the concept of 'long polling', but I do not admit to knowing quite how to use it with remote objects such as this.
My question is, what is a good design pattern to push information to the player such that all Simulation
requests go straight to the Flash client and that all control loop logic can stay on the Java side?
Thanks!