duanjia6959 2015-01-05 12:28
浏览 11

如何一次向所有在线用户显示骰子滚动值? [关闭]

In action script Adobe flash, I created a board game which roll a dice. Although it is a multi-player game & played online, if Player1 roll the dice the rolling action and its "value should be visible to other players" (i.e., Player2, Player3, Player4). How to achieve that?

Using php at server end. Please give some suggestions.

Any Help here?

Thanks.

  • 写回答

1条回答 默认 最新

  • dongtanxi5676756 2015-01-05 13:48
    关注

    This an implentation issue, rather than specific to any particular language. The Observer Design pattern would be ideal for your situation.

    According to Wikipedia:

    The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.

    So in this case, your "Observers" are your players, which you would register with the "Subject". Whenever an Observer changes its state (rolls the dice), the Subject is notified, and then all other Observers are notified as well.

    How you store the data isn't really important here. As long as the Observer notifies the Subject that it has rolled the dice, the Subject can then update all Observers registered with it.

    You could store/retrieve the data from a database table. You then only have to write to it as each player makes their move, and read from it when the Subject is notified to update all the Observers of the move.

    So each player could have their own id, which would be your primary table key, and when one of them makes a move, the table is updated. You'll need a way of notifying your game to know the table has been updated. Writing it to an xml file the game constantly checks would be one way, and it would update the players when the xml data changes.

    There's all sorts of ways you can implement the pattern, but you'll find it much easier to figure out using the Observer pattern.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化