The Knights of Game Sparks

In this tutorial we’ll introduce GameSparks platform and we’ll teach you how to build a simple turn-based multiplayer game inspired by a classic Gomoku, under a working title ‘Hearts and Skulls’.
Instructions will be mostly focusing on integrating GameSparks and Unity. We’ll explain some GameSparks basics, but previous Unity knowledge is required (on an intermediate level).
In this tutorial we’ve been using  2017.1.1f1 version of Unity, but any of Unity 5 or 2017 (previous or future releases) versions should work.
Before we get started, you can check out the final result and play our live demo (run it in two separate browser tabs if you can’t find a multiplayer match). After you have an idea about what the finished application looks like, download all Unity assets (sprites and fonts) we’ll be using. If you need more details about how everything is set up in Unity, download the complete project.

Rules of Gomoku

Gomoku, also known as Five in a Row, is a strategy board game for two players. Gomoku boards come in various sizes, but we’ll use one that is 15×15. Players take turns in which they place one of their pieces on one of the empty fields on the board. The goal is to form a consecutive chain of five pieces (no less, no more) either horizontally, vertically or diagonally.
Additional tournament rules can be added to the game to minimize the first-move advantage but we’ll start out with the simplest variant.
You can find more information about Gomoku and some strategy tips at GomokuWorld.

GameSparks

Introduction to GameSparks

GameSparks is a cloud service which offers almost everything you might need for your game when it comes to backend solutions. Among its many features are:
  • User authentication
  • Customizable matchmaking
  • Turn-based or real time multiplayer
  • Server authoritative Cloud Code (which is essentially JavaScript)
  • Player data and game data storage
  • Leaderboards and achievements
  • Economy
  • Analytics
… and many more. For a more complete list of features see GameSparks features description page.
GameSparks and the client app (in our case Unity) can communicate in a couple of ways.
  • Client can send a Request. Many different premade Request types are available. In fact, you can create your own types, called Events.
  • GameSparks can react to a Request, sending a Response. Sometimes, when things go wrong, this might be an error response.
  • GameSparks can also independently send Messages to the client.
You can use interceptors to execute your custom server code (called Cloud Code) in interception points. There are four key interception points:
  • After a Request is received but before it is processed. You can use it to execute a piece of code before GameSparks does its default processing for a given Request. You could, for example, use it for additional server-side validation.
  • Before a Response is sent. Use it to execute a piece of code after GameSparks does its default processing for a given Request. You could for example retrieve some data and append it to the Response.
  • After a Message is created. The same Message could be sent to multiple players. Using this interception point you can ensure that the code will only execute once per Message. This corresponds to GlobalMessages folder in Cloud Code Configurator panel. You could for example initialize your game state before a ChallengeStartedMessage is sent to the players (we’ll soon explain what Challenges are).
  • Before a Message is sent. Use it to execute a piece of code for every player this Message is sent to. This corresponds to UserMessages folder in Cloud Code Configurator. You could for example append some data to the Message only one of the players should know about.
To learn more, see the diagrams at the official documentation page.
All communication with the service is done in the context of a user. Therefore, before your app can make any requests or receive messages you have to use one of the available authentication methods.
You can customize the matchmaking process in any way you want. Skill-based matchmaking is also very easy to implement. GameSparks uses Matches to find groups of players that meet given criteria. After a Match is found, a game or a room has to be created.
In GameSparks this can be achieved by using Challenges. Challenges, however, have a much broader application. You can use them for any activity that is performed by one or more players. They are fully customizable (this is outside of scope of this tutorial, though).
An important feature of GameSparks is the Test Harness. You can use it to fully test your game before launching it with the use of a GUI to send Requests, inspect the platform Responses and debug your Cloud Code.
We’ll further explore all of these concepts. To learn more you can always use the official documentation.

Comments

Popular Posts