Multiplayer Games using Google Sheets
Google Sheets For Multiplayer Prototyping
The most essential part of a multiplayer game is the ability for players to communicate with each other in some way. The simplest way to achieve this is for players to have shared access to a database that they both can read from and write to. When building multiplayer prototypes, it can be a hassle to setup a server and database and to then manage connections between players. What if there was a free database that existed somewhere and which players could perform operations on? Well, a database can simply be a table consisting of columns and rows; exactly the same as a spreadsheet. Google Sheets is a popular free online spreadsheet application which can be read from and written to via APIs.
In order to structure things properly, each row in the sheet must be identified by a unique id. This id can then be used to retrieve and update information in the specific row. When a player sets up a multiplayer game, a new id is randomly generated and a row is added to the sheet with this id. The Google App Script returns the id that was generated and the player is presented with a URL which includes the id. The player can then send this URL to a friend to challenge him to a game.
When the opponent browses to this URL, we can extract the game id from the query string and use it to read and write to the database. In order to detect changes to the database, the clients must poll the Google Sheet periodically. By interacting with the sheet in this way, the players can effectively play with each other. This type of setup lends itself well to turn-based multiplayer games.