Developer Console

Leaderboards and Tournanaments Tutorial - Game Walkthrough

Return to Tutorial Overview


Our sample game implements three screens (Android Activities):

  1. Splash Screen: set the player name and launch the game.

    Fruit Quiz Splash Screen
    Enter your name to play.
  2. Question/answer screen: presents a question and four possible answers. This screen loops until the player answers three questions.

    Fruit Quiz Splash Screen
    Answer questions about fruit.
  3. Leaderboard: displays a list of players sorted by high score.

    Fruit Quiz Splash Screen
    See the leaderboard.

Integration Strategy

The Tournament Integration document describes the general workflow of how to integrate Leaderboards and Tournanaments into a game. We will implement a subset of this workflow.

Register/Authenticate Player

When the splash screen is loaded, we check to see if a player name has been saved from a previous session (all persistent game state will use Android's SharePrefs facility.) If the player name is available, we check to see if the player has been registered. We do this by saving the token that the API sends in response to Register Player. No token means that we need to register the player.

Next, we use the player token to authenticate. If this is not the first time the player has played, we may already have a valid session id. If not, we call Authenticate Player to get a new session. Sessions expire periodically, so a real game would need to do a little more work to verify the validity of the session. Once we have a valid session, we enable the button to allow the player to begin a game.

Enter Tournament or Match

The player must enter the competition before the player can submit a score. To enter the first time, we call Enter Tournament. For subsequent attempts, we call Enter Match. To keep the tutorial as simple as possible, we hardcoded our tournament into the game. However, in a real game, the player can view the list of tournaments that they can enter. Depending on game style, it may make sense to enter a competition at other times during game play, but the simplest approach is to enter the tournament before playing.

Submit a Score

After a game session is complete and a final score can be calculated, we can submit that score to Leaderboards and Tournanaments.

Get a Leaderboard

Finally, once the score is submitted, we can request a leaderboard for the competition. This will return a list of players and their scores, ordered by score. We display this list on the leaderboard screen of our game.

APIs Not Covered in this Tutorial

This tutorial does not cover the topic of prizes. Because we are simply using an open-ended tournament to get a leaderboard, we will not award prizes.

To award prizes in your game, you must create the prizes and associate them with a tournament. The prizes are then awarded when the tournament concludes. There is nothing particularly complex about prizes and implementation is a natural progression to what this tutorial provides.

Getting Started

We will start with game source code without any Leaderboards and Tournanaments integration, which can be found here. We will begin the integration by adding tasks to register and authenticate the player.

Next - Player Registration and Authentication