I wrote a client-server pair for a 2D top down RPG game using sockets. However, I’m not clear on how exactly to transmit what the user wants to do.
Would I simply transmit a string like “Move north” and then use switch statements to decide what action to take or is there a more elegant solution?
If both client and server are java programs, then I would go with Command
pattern where each command class does a specific job (like “Move north” in your case) and the command objects are exchanged between the client and the server.
We used to use this approach in our enterprise application (though not a game), while implementing multi-master replication and it was quite extendible without any if/else chains or switch statements anywhere, just receive command and call command.execute() without worrying about what the command is.