I want to make a 2D turn based multiplayer "Tank Wars" game. Now, the problem is, I've never actually made a single Java game. While I go through a couple of tutorials on Java game programming, I thought I throw out a couple of ideas about the game structure and a question or two.
Classes- Game (main, initResources, gameLoop, endGame) - contains a StateManager
- StateManager (setCurrentState, updateState, drawState) - contains several States
- State (abstract init, abstract update, abstract draw) - base class for different game states
- MenuState (init, update, draw) - here you can choose to host (triggers a host and client thread) or join (triggers a client thread), switches to GameState
- GameState (init, update, draw) - contains all the entities, updates game logic etc
- Entities (get/setPos, get/setAlive, abstract update, abstract draw) - base class for all entities, like players/tanks, projectiles etc
Kind of a rough description but I hope you catch my drift.
Now I'm still pretty shaky when it comes to certain concepts. First of all, is it a good idea or even possible to make host/client threads the way I described above? Let's say we have two players:
Player A 1) Clicks the "Host Game" button
2) A host thread is started in the background acting as the server
3) A client thread is started, connecting to the server
4) The State changes from MenuState to GameState
5) The client thread receives information from the server in order to update the GameState
6) The GameState draws the scene using the updated info
Player B 1) Clicks the "Join Game" button
3) A client thread is started, connecting to the server
4) The State changes from MenuState to GameState
5) The client thread receives information from the server in order to update the GameState
6) The GameState draws the scene using the updated info
This is roughly how I imagine it to be, but since I haven't actually made a multiplayer game before, I have no idea.
Another thing is, where exactly do I put all the instances of my entities? Is there an instance of every entity on the server and on every client, only that the entities are not being drawn on the server but only their status is being updated through the input provided by the clients and then sent out to all clients in order to redraw those entities? Could someone give me a simple example of how this usually is done in games like this?
Well, I'm off to the tutorial section!
Cheers!