使用 Adob​​e BlazeDS/LiveCycle 向客户推送问题

发布于 2024-09-10 20:42:21 字数 2047 浏览 8 评论 0原文

在过去的几周里,我一直在创建一种完全围绕玩家行为的基于文本的冒险游戏。总的想法是,有一个模拟类来维护世界的状态,并且是模拟控制器(即玩家)保持动作继续进行的责任。大多数时候,会说控制器告诉模拟要做什么(即向前模拟 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() 中实现,但是模拟也可以调用其他方法来向玩家请求一些信息。

我目前正在使用 Adob​​e Flex 和 BlazeDS 创建一个非常简单的用户界面,该用户界面将通过实现或保存实现 SimulationController 接口的东西来与模拟进行通信。有“长轮询”的概念,但我不承认完全知道如何将它与这样的远程对象一起使用。

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄想挽回 2024-09-17 20:42:21

在 wiki 上阅读有关推送技术的内容,了解主要概念。之后阅读 BlazeDS 开发人员指南中的消息传递部分。

我假设您有一些使用 BlazeDS 的经验..(至少您在某些应用程序服务器中安装了它)。查看示例文件夹,您会发现两个有趣的示例(一个聊天应用程序,另一个称为 datapush)。它们非常容易理解。

Read on wiki about Push technology to understand the main concepts. After that read the messaging part from BlazeDS developer guide.

I assume that you have some experience with BlazeDS.. (at least you installed it in some application server). Take a look in the samples folder and you will find two interesting examples (a chat application, and another one called datapush). They are quite simple to understood.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文