【问题标题】:Pushing Questions to a client using Adobe BlazeDS/LiveCycle使用 Adob​​e BlazeDS/LiveCycle 向客户推送问题
【发布时间】:2010-07-22 19:30:34
【问题描述】:

在过去的几周里,我一直在创建一种完全围绕玩家行为展开的基于文本的冒险游戏。一般的想法是有一个模拟类来维护世界的状态,并且是模拟控制器(即玩家)的责任来保持动作的进行。大多数情况下,会说控制器告诉模拟要做什么(即模拟向前 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 的 Adob​​e Flex 创建一个非常简单的用户界面,该用户界面将通过实现或持有实现SimulationController 接口的东西来与模拟通信。有“长轮询”的概念,但我不承认完全知道如何将它用于诸如此类的远程对象。

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

谢谢!

【问题讨论】:

    标签: java flash design-patterns blazeds livecycle


    【解决方案1】:

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

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

    【讨论】:

    • 您好 Cornel,这有帮助,但即使使用 Push,我也没有简单的方法可以要求玩家回复并知道他何时回复。例如,我可能有一个单独的线程正在运行,它提出了“牛奶在哪里?”的问题。客户端可以通过将答案推送到另一个频道或调用原始远程对象的方法来回答,但这些都不是无缝的或直观的。
    • 不确定我是否同意,但我正在为消息传递工作一段时间,也许我会从不同的角度看待事情......例如,在你的情况下,你只需要创建一个带有问题的消息对所有对您的问题感兴趣的订阅者“牛奶在哪里”。并且至少从理论上讲,消息传递框架应该隐藏各种怪癖,以便在没有双工套接字的情况下模拟通信。
    猜你喜欢
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    相关资源
    最近更新 更多