Syncing State: Building a Basic JavaScript Multiplayer Game

2 min readJun 22, 2015

Warning

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?

Remotely Flipped MultiplePlayers

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.

More from PubNub

How to Create a Dating App: 7 Steps to Fit Any Design
Insights6 minMar 15, 2023

How to Create a Dating App: 7 Steps to Fit Any Design

There are common underlying technologies for a dating app, and in this post, we’ll talk about the major technologies and designs...

Michael Carroll

Michael Carroll

How to Create a Real-time Public Transportation Schedule App
Build6 minMar 14, 2023

How to Create a Real-time Public Transportation Schedule App

How to use geohashing, JavaScript, Google Maps API, and BART API to build a real-time public transit schedule app.

Michael Carroll

Michael Carroll

How to Create Real-Time Vehicle Location Tracking App
Build2 minMar 9, 2023

How to Create Real-Time Vehicle Location Tracking App

How to track and stream real-time vehicle location on a live-updating map using EON, JavaScript, and the Mapbox API.

Michael Carroll

Michael Carroll

Talk to an expert