Real-Time Gaming Blog

Syncing State: Building a Basic JavaScript Multiplayer Game

2 min read PubNub 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

Top Trends to Engage Your App Users
InsightsSep 27, 20224 min read

Top Trends to Engage Your App Users

Take a look at the top trends that are the most effective in attracting customers and reducing churn, and how you can incorporate...

PubNub Staff

PubNub Staff

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff