PHP/MySQL 中的游戏大厅
我正在各种移动平台上创建手机游戏,并决定使用 PHP/MySQL 作为后端并通过 JSON 与其进行通信。 (游戏将基于文本)。
我缺乏如何实现这一点的想法,我所追求的逻辑如下;
- 用户需要注册一个帐户
- 用户将进入游戏大厅寻找空位
- 如果有合适的游戏准备好并等待(未满并等待新玩家),则加入
- 如果没有创建新游戏并等待玩家
我在想每场比赛有 20 名玩家,只有当有 3 名或更多玩家等待时才允许游戏开始。当有 3 名或更多玩家等待时,游戏开始前会有 60 秒倒计时。
现在我知道其中一些可能需要在客户端完成。我正在纠结从哪里开始!!因此,任何可能有帮助的想法、代码示例或阅读材料的链接将不胜感激。 谢谢!
I'm creating a mobile game on various mobile platforms and have decided to use PHP/MySQL as the back end and communicate with this via JSON. (The game will be text based).
I'm lacking on idea's on how to implement this, the sort of logic i'm after is as follows;
- User will need to register an account
- User will enter the game lobby looking for an open slot
- If there is a suitable game ready and waiting (not full and waiting for new players) then join
- If not create a new game and await players
I was thinking of having 20 players for each game and only allowing the game to start when there's 3 or more players waiting. When there's 3 or more players waiting there would be a count down of say 60 seconds until the game began.
Now i know some of this might need to be done on the client side. I'm struggling on where to start!! So any idea's, code samples or links to reading material that may help would be very much appreciated.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据评论,我猜您正在寻找有关数据库模式的一些想法,就像 Brad Christie 所建议的那样。所以我要从这个开始。
首先,您需要一张供玩家使用的桌子。我猜您已经拥有其中一个,但您可能需要包含一个字段来表示它们所在的游戏 ID。
接下来,您需要一个游戏表。这是您存储游戏本身信息的地方,包括游戏是否处于活动状态。要获取玩家数量,您只需使用该游戏的 ID 查询玩家列表即可。您还可以跟踪玩家数量,并在玩家离开或加入游戏时更新它,具体取决于几个因素。
现在,游戏大厅本身。这里的确切方法实际上取决于您希望它如何运行。您可以使用 AJAX 来更新当前活动游戏的列表(并设置某种聊天系统以让玩家在等待时进行交谈),也可以使用游戏大厅作为路由页面。如果您选择后一种路线,则查询活动游戏,自动将玩家转储到符合您条件的游戏,然后将用户发送到“主游戏页面”。
希望这将为您提供有关如何开始的坚实概述。恐怕除非我更多地了解您的要求,否则我无法为您提供更多帮助。
Based on comments, I'm guessing you're looking for some ideas on database schema, like Brad Christie suggests. So I'm going to start with that.
First, you'll need a table for the players. I'm guessing you already have one of those, but you'll probably want to include a field for the game ID that they're in.
Next, you'll need a table for the games. This is where you store information on the game itself, including whether it's active. To get the player count, you simply query the list of players with that game's ID. You could also keep track of player count and update it whenever the player leaves or joins the game, depending on a few factors.
Now, the game lobby itself. The exact method here really depends on how you want it to function. You can either use AJAX to keep a list of currently active games up to date (and set up some sort of chat system to let players talk while waiting), or you can use the game lobby as routing page. If you go the latter route, then query the active games, automatically dump the player into one that meets your criteria, then send the user to the 'main game page'.
Hopefully this will give you a solid outline on how to start. I'm afraid I can't help you much more unless I know more about your requirements.
要注册用户,您只需要一个表格并将该表格保存在数据库中。当用户登录时,您会查询与密码和用户名匹配的数据库。
For register a user you simply need a form and save that form in your database. When the user logs in the you query the database matching the password and user name.