0

I have a game - Asteroids - that is currently only a single player game. What I want to do is to have 2 players be able to play at the same time by competing in how many Asteroids they can shoot. Rather then each taking turns, I want them both to compete against each other in the same game session. The code I am using for the Asteroids game is taken from here: http://mikemiller.net/asteroids/Asteroids.java

Its much too long to post in full - over 1000 loc - but I want to make this game into a 2 player game over a network. Does anyone have any tips or advice on how to do so? I have read elsewhere that RMI would be a good choice for this game, if anyone has any advice for that I would appreciate it.

Thanks.

faboys
  • 57
  • 1
  • 1
  • 8

1 Answers1

1

Using simple client-server socket architecture could do what you need. The server part would keep the game state : accept updates from each client, and make them aware of such changes. The clients would send the updates to server (eg player moves) and accept the updated game state from server, and update/draw the GUI/screen accordingly

nullPointer
  • 4,419
  • 1
  • 15
  • 27
  • How would I send messages across the sockets? The issues I am thinking of: the ship will constantly be moving so will have to send messages every time it moves and secondly how would I program those messages? At each stage, I want to send the position of the ship and if its shooting anything etc - would I have to serialize that data? – faboys Mar 14 '19 at 16:36
  • There are tons of java socket examples out there. Here's one close to what you need : http://cs.lmu.edu/~ray/notes/javanetexamples/#tictactoe – nullPointer Mar 14 '19 at 16:42
  • Thank you very much, much appreciated – faboys Mar 14 '19 at 17:26