Multiplayer game design

Posted on 2007-03-28
Last Modified: 2012-06-21
I need help! I am designing a Map Game using google map as a platform, Php server, Mysql, javascript and HTML.
I dont know how to get players signing-in to the website to see one another (screen names) and be able to chat (problem 1)
I want the system to randomly choose and connect players to play one another (problem 2)
I dont know how to make players connected to share the same screen image and be able to communicate and play the game together. I will really appreciate your responses.

Question by:vivaldino
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 36

Assisted Solution

Zyloch earned 250 total points
ID: 18819607
A very simplistic model would do the following:

1) Chat -- When a user sends a chat, it gets added to the database. Have each user's screen refresh every few seconds, possibly with AJAX. Each time, they check the database to see if there is a new message for them to display. If so, display the message and delete it from the database.

2) Random Connect -- Just make sure to keep a database table or field with all the active users and choose from among them.

3) Same Screen Image -- Make sure you have the master data on the server. Then, just check the current data the user has with the master data and update when they refresh. I do not know how to do this with Google Maps, since I have not used it. The concept is clear, but it is difficult to do.

All of these might take up more bandwidth than you want, and it may not be as fast as you'd like. If you can, you should try making network games with more amenable languages, such as Flash or Java.

Author Comment

ID: 18821166
Thank you Zyloch,  for responding to the questions, though the problem is not yet solved.
1. I  designed a map Game, users need to register to access the page. When a player sign-in, I want the list of players that have signed-in to be listed on the following page. so the players can see the list of players on site and they can chat with one another. I am using Mysql database, PHP on window. thanks.

LVL 36

Expert Comment

ID: 18821267
I would suggest a separate sessions table to hold the current active sessions. Periodically, you can delete sessions that have remained inactive for too long, thus automatically logging out those players. The pseudocode is follows:

When users are logging in
   Connect to database
   Add user and time of login to the sessions table
   Grab the entire sessions table and display

When users perform an action (e.g. automatically retrieve update through AJAX)
   Connect to database
   Update the time for the session to the new time

When users log out
   Connect to database
   Delete the user from the database

In any of these three sections, you can also intersperse the action of deleting inactive sessions from the database. You only need to check the time of the session; if it is too long in the past, then it has been inactive for too long and may be deleted.
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.


Author Comment

ID: 18826795
I really appreciate you. I tried to figure it out the way you explained but it did not work. Please can you help me out with sample code. So I can have something to build on.

LVL 36

Expert Comment

ID: 18830994
What do you have, or what have you tried, so far? It would be easier to have something of which to work off.

Author Comment

ID: 18831648
I have been able to design the website database using PHP, mysql, From the website players need to register, after registration they can now login, all these had been done.  I have a database that holds the name of all players that have registered

not yet done!

after signing-in I want the players to be directed to a page  where can view the list of other players who want to play the game who are online or who had been engaged already playing the game. on this page they can chat fom this page, then they will be engaged to players they will play with from this page.

also connecting the players to play themselves.
LVL 36

Expert Comment

ID: 18831671
Let's take care of the first part. You should create a sessions table, and it should have (at least) the following fields:

id (auto_increment)    userid          login [int(11)]        active [int(11)]

This setup may require that you use a join with your main user table to find the username, for instance.

Since you have knowledge of mysql, it'll be easier to tell you the queries you need instead of all the code. When they first login, you should have a query such as

$time = time();
$qry = 'INSERT INTO sessions (userid, login, active) VALUES (' . $userid . ', ' . $time . ', ' . $time . ')';

Then, at your list of other pages, you can always do

$qry = 'SELECT * FROM sessions, users WHERE sessions.userid =';

where you have to fill in the necessary fields. You can then grab all the results and do a print_r() on them to see what they are.

Author Comment

ID: 18834091
really appreciate you for the help. I created the table sessions the way you explained, not working yet.  I think it is not working due to the fact that I am misinterpreting your explanation. I posted my code here, may be you can figure out the problem.



if(!$user|| !$pas)
echo'!!! you have not entered all the required details.<br/>'
       .'Please go back and try again.';

@ $db = mysql_pconnect('localhost', 'root', 'vivaldino);

if (!$db)

 echo 'Error: Could not connect to database.  Please try again later.';

      // select the appropriate database
    $mysql = mysql_select_db( 'google2' );
      echo 'Cannot select database.';


  // query the database to see if there is a record which matches
    $query = "select count(*) from cluegame where
              user = '$user' and

  pas = '$pas'";

    $result = mysql_query( $query );
      echo 'Cannot run query.';

    $count = mysql_result( $result,

0, 0 );

    if ( $count > 0 )

// visitor's name and password combination are correct
      echo '<h1>Here it is!</h1>';
      echo 'Welcome to GeoSmart Game.';   }

visitor's name and password combination are not correct
      echo '<h1>GO AND REGISTER!</h1>';
      echo 'You are not authorized to play the game.';

$time = time();
$query = 'INSERT INTO sessions (user, login, active) VALUES (' . $user . ', ' . $time . ', ' . $time . ')';

$query = "SELECT * FROM sessions, users WHERE user = user'";

echo '$user <br>';
echo '$time <br>';


Please I don't know if you have time, I wish to contact you beside this medium to help me out with the code, thank you, really appreciate you.
LVL 10

Accepted Solution

Andrew Beers earned 250 total points
ID: 18908314
I have experienced the best approach to Chat is to use an AJAX control to pass a XML argument back to a PhP control.  It has been ages since I've toyed around with PhP but here goes.

I'll help Zyloch out a bit with the chat explination:

PhP has a cache control, at the time I was using PhP it was not built into the PhP version and had to be installed.  ((Thus I ended up switching to C#))

Your chat object needs to have a few objects.

-From User
-Time Stamp
-Message Content

PublicChat -- Array Implementation
!!This is an array of MessageInstnaces

When a new chat is recieved through the AJAX control you insert it at the 0 index of the array and return the entire array collection parsed into HTML to return it back through the AJAX control, this can then be inserted into a DIV tag that renders the chat.  

This is the simplest way to do it, and I have example code (although it plugs to a C# control) will work the same for a PhP control.

Login:  Test
Passwod: password123

On -- Once logged in using a IE brower, click on Chaos Chat and check it out.  The source can be viewed from the window that it opens.

As far as user validation goes, I've always used session to store this information, you query the database of registered users and validate their login credentials, you then populate a User object and store it in the Session Array.

I have always stayed away from logging chat into a database as it requires too much over head and is unbearably slow with a larger user base.

As for your map questions, if you want users to real-time be able to see eachother there too, you can use another cached control for User locations.  Once again you can see my ajax code on under beta map movement.

Let me know if you are interested in persuing this method, I can explain further if you have more questions.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question