Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am designing a map game, using PHP and MYSQL. I don't know how to make the players who sign-in to the website to see other players who are also connected to the site and be able to chat with one another.

I want to design the game in such a way that 2 players can play with each other and be able to send messages during the game while others groups are playing at the same time.

I have designed the map game successfully, but the problem is making the player 1 who log-in to site to see the player 2 who will also log-in and both can get connected to play each other. http://i.stack.imgur.com/YyCPG.png

I will appreciate your responses.

share|improve this question
    
Make tables in database (2) for active players, store their properties; properties which capture necessary gamestate. In PHP get/set data from/to database + needed processing based on requests (2). I would use ajax to do these requests (1), based on player's actions, timers ... js -> php "joe says hi" ... php-> database "add this message" ... php->js "message added" –  user712092 Oct 12 '11 at 2:55
1  
@user712092 don't write answers in a comment... –  bummzack Oct 12 '11 at 8:28

2 Answers 2

up vote 2 down vote accepted

Buttons (controlls) and graphics handle on browser. With javascript, there is lot of drawing libraries, well, even game libraries (craftyjs, gameQuery ...).

State a current game has will be on server in a database.

table players {id, name, score, actual_game_id ...}
table games {id, name, player_which_is_on_move_id, ... remaining_time (for example) ... }
table card {id, game_it_belongs_to_id, which_player_has_him_in_hand_id, value ...}
table message {id, game_where_it_was_sent_id, player_who_send_it_id, text, ...} 

I derived this from thinking about entity relations (may contain mistakes):
player can play only one game, game has N players
card belongs to only one player, player can have N cards
card belongs to only one game, each game has its own cards (so they are not mixed btw games)
only one player is allowed to move at a time
...

Communication between player and server is trough AJAX. Player side is coded in javascript, server side in PHP (or similar) + SQL. One problem is that You have to periodically ask/query (chat made by periodical query in AJAX) server whether something new happened (server can not contact You trough AJAX); there might be a way to let server contact You trough something else than polling with AJAX, but I do not know what it is.

  • A player sends server messages like "can I play?", "my username and password is ...", "I am moving this card", "I am sending this message to a chat window > hi folks, this game rocks!" ...
  • Server determines whether and how to change database (add message to message table, save the move to tables if it is valid).
  • Player periodically queries server "has something new happened", for example when he is waiting for move of a other players.

You have to figure out rules of communication (communication protocol). Also there is a chance, that some of javascript game libraries has methods to help You handle communication.

share|improve this answer
1  
You often can get a speed boost by saving the chat in a flat file and only syncing that with the database every few new messages. Or never sync it if you don't need the chat to persist. You can then limit the flat files to ~100 lines each. Have one file per 'room.' –  DampeS8N Oct 12 '11 at 18:52
1  
I wish I had 15 reputation to vote you :D Thank you –  Alireza Seifi Oct 12 '11 at 20:04

In SQL, one method could be:

If a player can be in more than one game at a time, you'll need to use a Games table which houses all of the current users mapped to a game_played identifier

If a player can only be in a single game at a time, make a field for the Player table that states what game_played ID each is currently attending.

Search for game_played ID's to help pair players together and reference the data to each other.

As for game state and messages, you can use tables and simply reference the game_played ID to help sort this out.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.