4

I am doing a multiplayer game where each player draws a picture and then displays his/her pictures to the opponent to answer some questions.

I'm new to game programming and especially multiplayer games.

My question is: how can two players connect to each other and the state of both players updates continuously?

By the way, I'm planning to use JavaScript, PHP and MySQL languages for the implementation.

Update:

I didn't understand until now how can I connect two players. If the first player finished drawing the image, then the game has to find the opponent to answer some question regarding the picture. How can my code find the opponent?

Community
  • 1
  • 1
Amal
  • 41
  • 1
  • 2

2 Answers2

1

If you assign every game a "game id", then you can store that game id in each players session. Store the data for each game id in the database, to keep track of what has happened in the game so far. You may want to also assign each player a role, like "quizzer", and "answerer" to make it easy to keep track of what parts of the game each player should see.

preinheimer
  • 3,712
  • 20
  • 34
0

What you are looking for is push updates (Comet). This can be achieved by having a long polled connection to your web server that sends updates to it's connections as they pop in. You can have two connections open per domain in most web browsers. One connection will be used for this 'update' connection, and the other one will be used to send player actions to the web server.

If you are using PHP it will not be efficient to keep these long polled connections open. You can use an alternative pull strategy that connects to the webserver every few seconds to see if it has an update available.

See this example for a chat room in PHP and JQuery: How to implement a chat room using Jquery/PHP?

You can use these ideas to create your game. For example instead of a chatroom, it connects to a game.

Community
  • 1
  • 1
TomHastjarjanto
  • 5,386
  • 1
  • 29
  • 41