How to convert this game into a multiplayer game?

I have been watching a youtube tutorial series.

I haven’t finished it, but I have reached a point where my code looks like a game. However this tutorial series doesn’t cover multiplayer elements, so I tried and tried to see if I could find any other multiplayer java game tutorials online, but there were none. So can anyone simply take this code and add a GameServer, GameClient class to it so that I can have a server running which transfers the player’s co-ordinates and updates them to all clients? In theory it looks simple, but I have been trying it for over a week and I can’t figure out what to do. I have attached my game source code here. Would be a great help if someone could do this?

Thanks

It sounds like what you need is the Generic Multiplayer Connector (https://bitbucket.org/SteveSmith16384/genericmultiplayerconnector), which is designed to do exactly what you want, i.e. quickly and easily broadcast data to all other clients. There’s a link to the wiki on that page that goes through adding it to a game step by step.

No self-advertising there :emo:

OP, you should learn about Sockets. Once you get them running correctly, it’s easy.

Ooops. Disclaimer: I created the Generic Multiplayer Connector. A+, would create again. :wink:

If its not asking too much, would it be possible for you to show me how to do it?

I did learn sockets, but I don’t know how to actually use them and there aren’t many tutorials for java game development. If its not asking too much, would it be possible for you to show me how to do it?

If you actually learned Sockets, you would know how to use them. This may be an example of the pot calling the kettle black, but do not rely on game development tutorials. They limit your java knowledge to what they are teaching you and are basically worthless if you’re actually trying to learn java.

Yeah, but I dont know where to learn them from. There are hardly any textbooks for java multiplayer game programming. Could you just help with basic connection in my game. Just get two players to move, just two clients is enough, which would give me an idea.

Your problem is that your search is too narrow. You need to look for network programming tutorials, not java multiplayer game programming tutorials. Your job then as the programmer is to apply the concepts learned in the network programming tutorials to your purpose of making a game multiplayer.

This is the absolute basic-est client-server socket code:-

On the server:-


ServerSocket sckListener = new ServerSocket(port, backlog);
Socket s = sckListener.accept(); // Loop this line for multiple connections

On the client:-

Socket s = new Socket(server, port);

Both the client and the server will then have a socket object. You can then use Socket.getInput/OutputStream() to get the IO streams to read/write data. As I said, this is very basic and you’ll need to put stuff in threads and design your own protocol among other things. The above should get you on your way, though feel free to ask any questions.