Real-Time Gaming Blog

Syncing State: Building a Basic JavaScript Multiplayer Game

2 min readPubNub Staff 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

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff

Another Step Towards Data Security: ISO-27001 Implementation
BuildMay 2, 20221 min read

Another Step Towards Data Security: ISO-27001 Implementation

Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.

PubNub Staff

PubNub Staff