开发者

PHP/MySQL game server [closed]

开发者 https://www.devze.com 2023-04-12 00:51 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

This is the current logic behind my game engine:

  1. User logs in
  2. User wants to start a new game and enters lobby
  3. Looks for a game with a space free. (There will be 20 max, 10 min users per game. Once a min of 10, count down starts until the start of the game)
  4. When the user enters a game, the game database entry is updated with the user's ID.
  5. Deliver payload to user (info for the game; for example, questions)
  6. User completes game and sends result to the server
  7. Server checks results, works out who has the 1st, 2nd and 3rd highest score. Adds points to the user database entry, send's results back to all clients (leaderboard)
  8. Game room is destroyed.

This will be done via PHP/MySQL with the clients accessing via JSON. I'm confused how to do step 2 and 3 with these technologies. Specifically, how do I poll for a room to have met the requirements, i.e 20 max, 10 min users. If more than 10 users for say 10 seconds then start start the or if 20 max then 开发者_如何学运维start the game?

I'm trying to think of the logic but struggling.

EDIT: I think that's a little unfair closing this question. I'm not asking for people to code the thing for me, i'm asking for advice on the logic used.


I would create a game logic loop that runs independently on the server, (started by cron for example), which monitors your game rooms (as that's basically as what a player inviting other players can be seen).

If then the room is full enough (or completely filled) with players, it updates the according row in the database to indicate the game has started, and saves at which time that was exactly.

Now the client keeps polling a script, say, once a second, to see whether the game in his room has started and how many milliseconds that was ago. If it's started, the countdown begins. You might have to skip displaying the "10" but start at "9" (or lower even), for when a client receives the answer to its poll a second or more later after the game has started, and all clients will be synchronized.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号