Real-Time Gaming Blog

Syncing State: Building a Basic JavaScript Multiplayer Game

2 min read Michael Carroll on Jun 22, 2015
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

How to build a basic JavaScript multiplayer game, where user moves are synced in real time as the player makes a move.


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 Add a Notification Badge to Icons in React Native
Real-time Chat BlogDec 19, 20226 min read

How to Add a Notification Badge to Icons in React Native

Display real-time notification badges with PubNub and React Native to display important information and bring users back to your...

Michael Carroll

Michael Carroll

Digital Twins and the Future of Real-Time Data
InsightsDec 6, 20224 min read

Digital Twins and the Future of Real-Time Data

The concept of Digital Twins has evolved over the last two decades, however, one thing remains the same: the need for real-time...

Michael Carroll

Michael Carroll

How Many Text Characters Fit in a 32KB PubNub Message?
Real-time Chat BlogNov 24, 20224 min read

How Many Text Characters Fit in a 32KB PubNub Message?

Learn the ins-and-outs of PubNub message size and get a better idea of how many text characters fit in a single message.

Michael Carroll

Michael Carroll