Solved

Developing a 2 player game on linux server help

Posted on 2011-03-24
4
490 Views
Last Modified: 2012-05-11
I am a student andI need to implement a 2-player PacMan game (in C) for a Unix Machine. Each player will login into the same server with their respective user accounts, type the command ‘pacman’, and instantly will be placed in a FIFO queue (fifo.c) and wait for access to the game. When it is their turn to play, both users should find themselves in the ‘same maze’, competing against each other.

I did not implement the FIFO queue yet. Up till now, I have a one-player pacman game, pacman.c and in it I already have an IPC between player one and the ghosts via shared memory. Now, I would like to implement another IPC between player 1 and player 2, and I was thinking of using signals but I am not sure whether they are practical.  

Can I assume that one instance of pacman.c is loaded on the server? Therefore, is it possible to load only one instance of the game (fifo.c will call exec() ONCE) and associate different processes (in pacman.c) with different user accounts (one process associated with player one, and maybe the child process with player 2)?

 

0
Comment
Question by:emcict
  • 2
4 Comments
 
LVL 45

Expert Comment

by:Kdo
Comment Utility
Hi emcict,

Signals might be useful within the application (client program) but they aren't much help with the communication to/from the game server.

You'll have to establish a "turn protocol" with the server.  The application will query the server with a simple "is it my turn" question.  If not, the application pauses slightly and resends the question.  When it is this players turn, any update of the game (player position, board changes, etc.) will need to be sent to the application (probably by a different question/message type from the application) and then the turn taken.

What you're describing seems like an awfully complicated way to do this.


Good Luck,
Kent
0
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
We did a project much like this in our OS class. We ran the game on the server and just sent the board position to the clients and accepted the input (we used sockets). Of course, we sent raw position data to the clients and rendered the graphics at the client.
The reason we did it like that was that we were using UDP so that if any packets were dropped, the game just skipped, it didn't make the two clients see totally different games.

I don't see how a "turn protocol" would work for pac-man since it's real-time. But as you've probably noticed, there's a window of time between when you need input (when pac-mac is between intersection points on the grid). So you could just accept one input packet in each period and drop the rest.
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 125 total points
Comment Utility
My 2 cents, rather than having multiple client programs communicating between each other (player 1, player 2, ghosts) you should implement the game server to do all of the tracking and to house all of the data structures (along the lines of Tommy's suggestion) and your clients should simply handle the user input and displaying the game. There should be one copy of the actual gameboard, on the server process. Could be in shared memory allocated by the server and attached by each client, or you could do all communication via IPC.

As far as signals, you don't need them for this. Since you aren't using TCP/UDP for everything, we would simply use shared memory and semaphores to control access to the central game structures.
0
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
Ah, yes. That's good advice. Shared memory isn't really realistic for most Client-Server applications, but if that's what you have then use it! It actually makes it a lot easier. You just need a queue for input commands that the clients add to and the server consumes.
I wasn't really paying attention when you said you had shared memory. I just assumed your project was like mine. Most of my earlier comments still apply though, but the server doesn't need to send the board position, it can just write it to the shared memory.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now