Syncing State: Building a Basic JavaScript Multiplayer Game
We’ve updated our SDKs, and this code is now deprecated.
Good news is we’ve written a comprehensive guide to building a multiplayer game. Check it out!
Our development team at AgilityFeat loves working with PubNub for many of our real-time applications, and we also love agile development methods. So why not combine the two?
That’s what we did in this real-time game for agile/lean teams that we’re calling Remotely Flipped. It’s a multiplayer, online version of the popular agile/lean game called penny flipping or pass the pennies, which is often used to educate teams on the value of doing work in small batches.
This video gives you a short overview of the concept and the game that we built:
JavaScript Multiplayer Project Overview
We built the application in Clojure. We used PubNub to glue the multiplayer game together, for communications between the different players to keep the status of the coins in sync across multiple browsers. When a user makes a move, their move is reflected in real time across all other connected browsers.
This allows an agile trainer to setup a game with four participants, and then the players have to “pass” the coins through all 4 players online.
Resources and Getting Started
You can find a detailed walkthrough and code repository for our JavaScript multiplayer game here. We’ll go step-by-step through the code, and in the end, you’ll have a fully functioning JavaScript multiplayer game.
The concept of the game is pretty simple, and PubNub makes implementation of real-time games like this a lot simpler. The game itself only took a few days to implement because we didn’t have to worry about any of the infrastructure behind the messaging … PubNub has us covered there!
Give it a try at Remotely Flipped and we’d love to hear your feedback on our blog.