For a school project, we need to create a multi-player game in Java (it must be a client / server) that can be played over the Internet (we program it in school, so this is not homework). The game is turn-based, but there should be a chat, which, of course, in real time. However, none of us have any programming experience on the net, and the more I read about it, the more questions I have.
My first thought was to use the socket API to implement the multi-user part. The server expects new data from clients. However, there are several types of data to receive, such as chat messages, traffic, etc. In addition, after the connection with the server is done, it is necessary to send some initial data (for example, the name of the player). The server should be able to see what message it received, but how? I was thinking of creating a Message class with a type string field. But in my server code, I will get the code as follows:
if (message.type.equals("message")) { // code to execute for chat messages } else if (message.type.equals("movement")) { // code to execute for movement } else if () { // ... } else { // ... } // Please ignore syntax errors :P
When there are many different types of data to send (and there will be), this does not seem to be the most efficient way. In addition, this would mean that both the server and the client must have this Message-class / interface (duplicate code).
What about other games? For example, player 1 moves his character to a position that defeats another character. Player 1's client calculates this defeat and applies the correct actions. But what needs to be sent to the server? Only a new player position or defeat? With the first option, this means that all other clients must perform the calculations. Could this not cause any problems? Since I don't have prior network programming experience, I got a little confused about how to do all this.
I also read in another thread on Stackoverflow that RMI might be a better option. After reading some information about this, I understand what RMI is, but I still cannot figure out if this is a good option for this project or not. Any tips for this?
As you can see, I'm a little confused about how to start from the network part of this project. I was looking for some programming books (for Java, of course), but none of them focus on the network part. I also searched for Java network books, but they seem to be focused on technology, not good code practices.
If someone knows a good book or has any tips for proper disintegration, we will be very grateful.
thanks