Multiplayer game - multiple instances
I have a multiplayer, turn-based, tile-on-board type game. I would like to be able to play more than one instance of the game at one time and I'm unsure of the best way to approach it.
At the moment I have a server applet waiting for players to connect, when someone connects through the Main class it creates a new instance of the Player class. One option would be to make the Main class into a Game class and create a new instance of it for each game. The issues I foresee with this approach would be:
- I have static variables in the Player class to deal with player names, scores etc. I obviously wouldn't would these values to be common across different games. I could get rid of the static variables but I feel it would make the program a bit messy. Is there a way to make that work with static variables?
- Is there a problem with having the server applet running all the time on the server?
- I know that the garbage collector should discard unused classes, would it discard Players when they disconnect? Is there a way of checking if they have been discarded - I want to avoid the situation where it's been running for a month and there are hundreds of player classes not doing anything!
The second option would be to open a new instance of the server applet for each new game. I believe its possible to open the software remotely (I think I read that you can use a WAR file or another method which I can't remember at the moment). This would mean using a new socket for each game though, I'm not sure if this is a problem or not, perhaps I just feel uncomfortable with it because I'm not used to doing it.
Sorry there are a lot of questions there, I just want to try and make the problem clear, I don't want to spend a long time experimenting with one method only to find out that its not plausible.
Thanks in advance