PHP AJAX多人游戏 [英] PHP AJAX Multiplayer Game

查看:130
本文介绍了PHP AJAX多人游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在计划一个相对简单的在线多人游戏,而我对如何用于人与人之间的交流感到困惑.

I'm planning a relatively simple, online, multiplayer game and I'm stumped on what to use for player to player communication.

游戏详细信息:

  • 6位玩家
  • 聊天框
  • 30秒回合(间歇)
  • 时间同步很重要

玩家选择并采取行动,在这一回合结束时,将执行该行动,短暂停留以详细说明行动,然后开始新一轮.

Players select and action and at the end of the round, the action is performed, there is a brief intermission to detail actions and a new round begins.

我已经决定完全使用JS和PHP(当然是AJAX)来构建此游戏.我只是不知道我应该如何使用客户端与客户端之间的通信-我最初计划使用mySQL对PHP脚本进行固定的1/2秒AJAX调用,以存储游戏/用户数据,但恐怕会太慢且不可预测.

I've determined to build this game entirely in JS and PHP (of course AJAX). I just don't know what I should use for the client to client communication - I initially planned on using constant 1/2 second AJAX calls to the PHP script using mySQL to store the game/user data, but I'm afraid that will be too slow and unpredictable.

我考虑过使用XML之类的东西代替mySQL,并使用php fopen()函数之类的东西-你们对此有何看法?

I considered using something like a XML instead of mySQL and using something like the php fopen() function - what do you guys think about that?

我在这个问题中读了

I read in this question here, where the poster is considering using XMPP, could that be a good solution?

我应该去找个插座吗?对于不需要交换这么多数据的游戏,这是否必要?要做到这一点需要什么?

Should I go for a socket? Is that necessary for a game that doesn't require all that much data to be exchanged? What would be required to get this going?

关于同步舍入时间有什么建议吗?还是我什至真的需要关注自己的事情?

Any suggestions on syncing the round time? Or is this something that I even really need to concern myself with?

我愿意接受所有建议,并非常感谢我能提供的任何帮助.

I'm open to all suggestions and really appreciate any help I can get.

推荐答案

选择Comet,您不需要套接字.彗星是一种反向AJAX.例如,由于它可以将数据推送到浏览器,而无需浏览器持续不断地轮询服务器,因此它可以完美地用于p2p之类的即时通讯程序.在JS/PHP中,Comet有很多实现,仅Google就是这样.然后,作为后端,您可以使用MySQL或XML或任何您想使用的东西(但我认为MySQL是更好的解决方案,因为XML只是一个文本文件,需要打开,读取,写入和关闭,并且必须对数据库进行设计比那更快.

Go for Comet, you don't need sockets. Comet is a kind of reverse-AJAX. Works perfectly for p2p things like instant messenger, for example, because it pushes data to browser without browser needing to constantly poll the server. And there are many implementations for Comet in JS/PHP, just Google that. Then, as a backend, you could use MySQL or XML or whatever you want (but I would consider MySQL as a better solution, because XML is just a text file which needs to be opened, read, written and closed and the database is designed to be faster than that).

这篇关于PHP AJAX多人游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆