ketanhwr / chain-reaction

Online version of the famous game "Chain Reaction"!
MIT License
36 stars 40 forks source link

Online multiplayer support #36

Open PlytonRexus opened 4 years ago

PlytonRexus commented 4 years ago

Using socket.io and node.js, it would be possible to create an online multiplayer version of this game. I agree this might make things unnecessarily complicated for the beauty of chain reaction is in its simplicity. But consider the improved utility. I had difficulty in sharing my mouse while playing. Might others have had similar problems?

If not over the internet, then a local setup can be created to play over LAN.

geetp98 commented 4 years ago

So what could be the plan? MySQL, simple APIs and FCM + background jobs to clean up abandoned games? @PlytonRexus

PlytonRexus commented 4 years ago

So what could be the plan? MySQL, simple APIs and FCM + background jobs to clean up abandoned games?

@geetp98 Let me just confirm this FCM is Firebase Cloud Messaging? I guess that's a fair model. Like I mentioned in the OP, a more barebones approach could be using sockets with/without a database. By the way, I recently created a version.

But your approach could be cleaner!

geetp98 commented 4 years ago

Yes, FCM = firebase cloud messaging. With a sockets model, we could run into trouble of one of the players disconnecting and need of creating a robust model to handle that. With fcm, it should be easy considering if a message is not sent successfully, the player has disconnected. We can let all the players know, and the game can continue. Although as of now, I haven't dived into game logic properly, but we would potentially need a nosql to store the game state as well.

PlytonRexus commented 4 years ago

@geetp98 I guess that's true about disconnecting. However, even FCM, uses a socket-based model. That is, if instead of socket IDs, we use Usernames/UIDs to track players, recreating a game state for that username should be easy enough.

For storing a game state, yes, we will need a database. I was thinking we could just make a simple map and store states corresponding to rooms in it. Of course, this will erase data once the server is turned off and will, I guess, keep a child process running indefinitely. The database solution is more elegant.

May I ask, are you making a version?

PlytonRexus commented 4 years ago

@geetp98 Oh, I didn't see a game state sort of thing in this version of Chain Reaction. So, making a multiplayer version is slightly difficult with this one.