PHP中基于回合的网页游戏-通讯问题 [英] Turn based web game in PHP - communication problem

查看:85
本文介绍了PHP中基于回合的网页游戏-通讯问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在使用PHP5开发回合制网页游戏.

这是一种非常简单的游戏,一种棋盘游戏:两个人加入了一个会话",他们一直玩到其中一个获胜为止.

我的问题简而言之:

*用户A和用户B玩游戏.

*用户A轮到他了
*请求将被发送到服务器以执行必要的操作.
*现在是时候让用户B移动了..

但是我该如何通知用户B?

我的意思是,现在服务器必须与其他用户(非活动用户)进行通信,而不是与发起请求的用户进行通信.

我知道这可以通过某种定期的AJAX调用来实现,该调用可以检查对手是否完成了转牌等,但是这样的事情会产生大量的请求.

没有更好的方法来解决这个问题吗?

我在想这样的事情:

*用户A的回合结束
*服务器保存他的分数
*服务器联系用户B
*用户B的开始.

使用PHP可以做到这一点吗?我应该使用彗星风格的AJAX吗?还是有更好的方法来做到这一点?

任何帮助将不胜感激!

Hi all!

I am working on a turn based web game in PHP5.

This is pretty simple game, a kind of board game: two people join a "session" and they play until one of them wins.

My problem in nutshell:

* User A and User B play a game.

* User A finished his turn
* Request will be sent to the server to perform necessary operations.
* Now it is time for User B to move..

But how could I notify User B about this?

I mean, now the server has to communicate with the other user, the one that is inactive, not the one that initiated the request.

I know that this could be implemented using some kind of periodic AJAX call that checks whether or not the opponent finished his turn etc, but such a thing generates a huge number of requests.

Isn''t there a better way to solve this?

I''m thinking of something like this:

* User A''s turn ends
* Server saves his score
* Server contacts User B
* User B''s turn gets started.

Is this possible using PHP? Should I use comet style AJAX? Or is there a better way to do this?

Any help would be appreciated!

Thanks in advance!

推荐答案

是的,它有可能被称为此处:)

抱歉,没有在您的帖子中注意到彗星. PHP还可以创建可与Flash/flex结合使用的套接字.可能是您需要的吗?
Yes it is possible, it is called Comet. But I''d look for kind of Java solution if you expect large player number. Talking about comet you can use nginx as your webserver and here is the module:
Here :)

Sorry, didn''t notice comet in your post. PHP can create also sockets that can be used in connection with flash/flex. May be this is what you need?


没有菜鸟,您可以用PHP编写此代码,您要做的就是在数据库表上设置字段,以供条件语句使用,您可以检查谁转动了.
no noob u can write this in PHP also what you do is have a feild on a database table which will be used by a condtional statment and u can check to see whos turn it is.


这篇关于PHP中基于回合的网页游戏-通讯问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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