Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 player internet game

 
Kieth Nogins
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kieth Nogins
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice game Bear. I liked it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic