Solved

Developing a 2 player game on linux server help

Posted on 2011-03-24
4
505 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
[X]
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
  • 2
4 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 35206550
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
ID: 35208180
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
ID: 35260206
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
ID: 35260610
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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

636 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