Thursday, May 9, 2019

java - How do we adapt our game to work over a network?


A friend of mine has made a Java version of a popular board game in Java, and has it working for multiplayer on one PC with different turns for each player. He's mentioned he wants it to eventually run from a webserver and people around the world can play the game together, but he's dismissed this as impossible (translated: Too hard to be worthwhile).


I'd like to make this happen for him, and I'm wondering:



  • Do we need to completely rebuild or can we just adapt the existing code, for the game to work across a network?

  • What are the advantages of a GWT based browser game, compared to a swing based client side game that updates to a server?


What is the common practice here, for going from one instance on one PC to multiple instances across several networked PCs?


Edit:



The game code is very well broke and down and generalised; game logic and display are completely seperate. The main GUI is a scroll pane with a dungeon, squares are coloured for monsters, players, doors, floors etc, and are just JButtons essentially. Players have turns and then the monsters have a turn. It's very simple in essence.



Answer



I know nothing of your game design, but I can say that attempting to develop a game in GWT probably isn't the best path to take. A team and I created a Words with Friends clone in GWT, and while we did get it fully working, we were very limited by what we could do graphically within the GWT framework. We also used Google App Engine as the server solution, and outside of using their great, but expensive, Channel API to update data between client and server in near-real-time, we had to just continuously poll the server, which wasn't ideal. This is just one issue you'll have to face when dealing with browser limitations. So, I would say there really is no advantage of using GWT alone, if due to the graphics limitations alone.


I'm not sure why your friend thinks "it's impossible", and it would be helpful to have more details on that, but I would have your friend take a look at PlayN. From the PlayN site:



PlayN is an open-source cross-platform abstraction layer that uses the GWT compiler to take one code base written in Java and compile it into targets that run it as HTML5, Flash, Java, or as a native Android application.



It's hard to say the level of work involved without knowing more about your friends code base other then it's a Swing application, but he could port to PlayN, which I'd imagine would allow him to keep a majority of his game logic code. Regardless of porting or not, he would still need to implement networking capabilities in order to make the game multiplayer, both client and server side, "tack on" as you put it. What is impossible is to tell you if that would relatively be a nightmare or not without knowing about how he implemented his game in Swing.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...