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?
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.
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
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?