Android Core Implementation

These steps will teach you how to call Skillz function methods to finish the integration process.

 

In order to call Skillz methods from your Android activity, you will need to import the following class:

import com.skillz.Skillz;

Step 1: Launching Skillz from your game

 

You can launch Skillz in one of two ways:

  • A multiplayer-mode button within your game. This is usually done if your game has a splash page or a Single Player (non-Skillz) option.  We find it’s helpful to place this entry point in an obvious and immediately visible location.
  • On launch of your game. This is usually done if your game is a Skillz/multiplayer-only game and has no splash page.

To launch a user into Skillz from an Activity, call the following method:

Skillz.launch(this)
        Contract: launch(Activity) => void
        Launches the user into the Skillz interface.

Example:

mSkillzButton.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
       Skillz.launch(Activity.this);
   }
}
 
You can also check out this commit from our sample game 2048 to see how Skillz.launch(this) is called.

Step 2: Starting a match

 

When a user enters a match from within the Skillz multiplayer functionality, Skillz will launch the activity specified in your manifest file under skillz_game_activity. If you haven’t set skillz_game_acivity before in your manifest file, you can follow Step 4 of the “Adding the Skillz library” tutorial.

To check whether or not a Skillz game is in-progress, use the following method:

Skillz.isMatchInProgress()
        Contract: isMatchInProgress() => boolean
        Returns whether or not a Skillz match is in progress.

This may be useful if, for example, you have a single GameActivity class that is used for both singleplayer and Skillz multiplayer. In this case you will want to use an if check and use isMatchInProgress prior to calling other Skillz methods.

 
You can also check out this commit from our sample game 2048 to see how Skillz.startMatch(this) is called.

Step 3: Handling game rules

 

Game rules can be specified on the Skillz developer portal to permit game types, levels, and parameters to be specified per-Skillz match.

Screen_Shot_2017-02-23_at_3.20.18_PM.pngScreen_Shot_2017-02-23_at_3.20.31_PM.png

To use game rules, use the following method:

Skillz.getMatchRules()
        Contract: Skillz.getMatchRules() => Map<String,String>
        Returns a Map of game rules for the match the user entered.

This will allow you to handle match-specific game rules as defined on the Skillz developer portal. You can also check out this commit from our sample game 2048 to see how Skillz.getMatchRules() is called.

 

Step 4: Implementing Skillz Random for fairness

 

Skillz matches must be fair for all players. To this end, randomly-generated levels and game conditions should be synced across all participants. All players within a match must start with the same game state. For example, in a game of bubble shooter, the starting board and the sequence of bubbles must be identical for both players.

Screenshot_2017-02-23-15-48-30.png

To facilitate this, use the following method:

Skillz.getRandom(this)
        Contract: getRandom(Activity) => Random
        Returns a Skillz-synced Random. This Random must be used to generate board state and any other fairness-related parameters in a game. Values will be between all players in a match. If this is called multiple times, the same Random instance is returned. Only nextInt() and nextFloat() are supported.

 

This Random instance should be used to generate all relevant random numbers within a Skillz match. You can also check out this commit to check how we used Skillz Random in our sample game, 2048.

 

Step 5: Reporting the match score

 

In order to prevent cheating, Skillz requires the user’s current score be reported back on a regular basis within your game loop. To do this, call the following method when the user’s score is updated:

Skillz.updatePlayersCurrentScore(this, score)
        Contract: Skillz.updatePlayersCurrentScore(Activity, BigDecimal) => void
        Sends the player’s current score to the Skillz servers for fairness validation.

This should be called fairly often. Once per game loop cycle is a good rule.

When the match ends, you can report the player’s final score to Skillz and bring them back inside the Skillz UI by using the following method:

Skillz.reportScore(this, score)
        Contract: reportScore(Activity, BigDecimal) => void
        Ends the Skillz match in progress. Submits the user’s final score and brings the user back into the Skillz interface.

The activity should be finished after reporting the score.

finish();
 
You can also check out this commit to check how we used Skillz.ReportScore() in our sample game, 2048.

Step 6: Aborting a match

 

There are instances in which a player might want to voluntarily “abort” (forfeit) a match in progress. If you decide to allow this, use the following method to record an aborted score for the match:

Skillz.abortMatch(this)
        Contract: abortMatch(Activity) => void
        Ends as the Skillz match in progress as an abort. This should be called with the user voluntarily forfeits the match. An “abort” score is the worst possible score. A score of 0 will beat a user who aborted.

The activity should be finished after reporting the abort.

finish();
 
You can also check out this commit to check how we used Skillz.abortMatch() in our sample game, 2048.

Next Steps

Congratulations! After completing the above steps, the Skillz SDK should be properly integrated into your project.

The next steps are to test in Sandbox, then move to Production!