ここ数週間、プレイヤーのアクションだけを中心に展開する一種のテキスト ベースのアドベンチャー ゲームを作成してきました。一般的な考え方は、ワールドの状態を維持する Simulation クラスが存在し、SimulationController (つまりプレイヤー) がアクションを継続する責任を負うというものです。ほとんどの場合、シミュレーションに何をすべきか (すなわち、1 タイムステップ前にシミュレートする) を指示しているのはコントローラーと言われますが、シミュレーションがコントローラーに何かを尋ねる必要がある場合もあります。したがって、次のようなインターフェイスを作成しました。
/**
* 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();
}
これらすべてのメイン制御ループは に実装する必要がありますSimulationController.run()
が、シミュレーションは他のメソッドを呼び出してプレーヤーからの情報を要求することもできます。
私は現在、BlazeDS で Adobe Flex を使用して、インターフェイスを実装するものを実装または保持することでシミュレーションと通信する非常に単純なユーザー インターフェイスを作成していSimulationController
ます。「ロング ポーリング」という概念がありますが、このようなリモート オブジェクトでそれを使用する方法をよく知っているとは言えません。
Simulation
私の質問は、すべてのリクエストが Flash クライアントに直接送信され、すべての制御ループ ロジックが Java 側にとどまることができるように、プレーヤーに情報をプッシュするための適切な設計パターンは何ですか?
ありがとう!