This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes 2 player internet game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "2 player internet game" Watch "2 player internet game" New topic
Author

2 player internet game

Kieth Nogins
Greenhorn

Joined: Mar 10, 2006
Posts: 18
Hi;

I need to create a 2 player internet game.
My question is : If one player goes to the site and lets say enters his name and then waits for another player on another computer to go to the site and request to play, how do I handle this?
I have basic knowledge in servlets and JSP and pretty good JAVA.
I know I have to use sessions, but how whould the second player know that there is a user waiting for another player to sign in?

I'm not asking for code, but if someone can please explain the idea or the concept to me?

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

I've not done this yet, but I have given some thought to someday modifying my BlackBox game (shameless plug: http://bibeault.org/blackbox/) to be 2-player capable.

While the session is necessary to maintain per-user state, it won't help with total game state. That sort of info would need to be stored in the application context. I envisioned each "game" being assigned a unique key, and a Map in the app context being used to store the state of each running game. The game key would be stored in each player's session context in order for the app to know which game instance each player was participating in.

That enough to get you started?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kieth Nogins
Greenhorn

Joined: Mar 10, 2006
Posts: 18
thank you Bear Bibeault,
the game I have to make is similiar to checkers or chess where each player whould see the same board, so your advice didnt really apply, but aside from that your blackbox game was very impressive.
Do you know where I could get sourcecode for games of that sort(maybe even 2 player games).
Thanks anyway
Ben Zhang
Greenhorn

Joined: Sep 24, 2008
Posts: 12
Hi Bear, et al.,

Sorry for reviving an old thread. The reason is I have some questions regarding Bear's suggestions.

1) I would see the game state stored in the application scope has to be synchronized?
2) If 1) is true, supposed I use Ajax for pulling the data in 1-5 seconds, how do you see the synchronization overhead?
3) Any other ideas for developing multi-user java-based games?

Thanks, Ben
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

1) Yes
2) Only trying it will tell
3) Not at this time -- I still haven't had any time to devote to this
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Nice game Bear. I liked it.


My Blog SCJP 5 SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 player internet game