Java 使用Adobe BlazeDS/LiveCycle将问题推送到客户端

Java 使用Adobe BlazeDS/LiveCycle将问题推送到客户端,java,flash,design-patterns,blazeds,livecycle,Java,Flash,Design Patterns,Blazeds,Livecycle,在过去的几周里,我一直在创造一种基于文本的冒险游戏,完全围绕玩家的动作展开。一般的想法是,有一个模拟类来维护世界的状态,并且是SimulationController(即,玩家)的责任来保持动作的进行。大多数情况下,控制器会告诉模拟要做什么(即,向前模拟1个时间步),但有时模拟需要询问控制器一些问题。因此,我创建了如下界面: /** * An interface to a GUI, command line, etc; * a way to interact with the Simulat

在过去的几周里,我一直在创造一种基于文本的冒险游戏,完全围绕玩家的动作展开。一般的想法是,有一个模拟类来维护世界的状态,并且是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();
}
/**
*GUI、命令行等的接口;
*与仿真类交互的方法
*@作者杜克沃思
*
*/
公共接口模拟控制器{
/**
*返回列表中选项的索引
* 
*@param消息:提示玩家
*@param选项:选项,顺序
*@return:选择的索引
*/
公共int-chooseItem(字符串消息、列表选项);
/**
*返回一些玩家必须手动输入的文本。
* 
*@param消息
*@返回
*/
公共字符串输入选择(字符串消息);
/**
*给用户一条消息。这可能是通知
*一个失败的动作,对某个随机事件的响应,
*什么都行。
* 
*@param消息
*/
公共消息(字符串消息);
/**
*该控制器控制的仿真
*@返回
*/
公共模拟getSimulation();
/**
*此控制器的主回路。常规流程
*应该是这样的:
*1)提示玩家选择工具和目标
*来自getAvailableTools()和getAvailableTargets()
*2)提示玩家从中选择动作
*getAvailableActions()
*3)使用工具target调用simulation.simulate(),
*选择的行动,做出决定所需的时间,
*还有这个
*4)当Simulation.isFinished()==false时,继续
*/
公开无效运行();
}
所有这些中的主控制循环都必须在
SimulationController.run()
中实现,但是模拟也可以调用其他方法来请求播放器提供一些信息

我目前正在使用AdobeFlex和BlazeDS创建一个非常简单的用户界面,通过实现或持有实现
SimulationController
界面的东西来与仿真进行通信。有“长轮询”的概念,但我不承认我完全知道如何将其用于像这样的远程对象

我的问题是,什么是一种好的设计模式,可以将信息推送到播放器,从而使所有
模拟
请求直接发送到Flash客户端,并且所有控制循环逻辑都可以留在Java端

谢谢

阅读wiki,了解主要概念。然后阅读BlazeDS开发者指南中的消息部分


我想你对BlazeDS有一定的经验。。(至少在某些应用服务器上安装了它)。查看samples文件夹,您将发现两个有趣的示例(一个聊天应用程序,另一个称为datapush)。它们很容易理解。

嗨,康奈尔,这很有帮助,但即使是推,我也看不到简单的方法来询问玩家的回答,并知道他什么时候回答。例如,我可能有一个单独的线程在运行,它推送问题“牛奶在哪里?”客户机可以通过在另一个通道下推送答案或调用原始远程对象的方法来回答,但这一切都不是天衣无缝或直观的。我不确定我是否同意,但我已经花了一段时间处理消息,也许我从不同的角度看待事情……例如,在你的情况下,你只需要创建一条消息,向所有对你的问题感兴趣的订阅者发送“牛奶在哪里”的问题。至少在理论上,消息传递框架应该隐藏各种奇怪的行为,以便模拟没有双工套接字的通信。