How to Develop Games with Huawei Game Service

Engin Canik
Huawei Developers
Published in
9 min readJul 10, 2020
Photo by Marvin Meyer on Unsplash

What is Huawei Game Service?

The game industry is bigger than ever and mobile games take a big place in it. Developers have a wide range of development tools. Huawei’s Game Service is one of them. User expectations also get bigger throughout the years. Game Service created with these expectations and the needs of game developers in mind. That’s why it offers many features for developers to develop their games more easily. Such as Achievements, Leaderboard, Events, Player Statistics but not limited to these.

Advantages of Game Service

These are the advantages of Game Service according to an official document of Huawei, “With HUAWEI Game Service, you will have access to a range of development capabilities to help you develop your games more efficiently: HUAWEI ID sign-in, Real-name authentication, Bulletins, Achievements, Events, Leaderboards, Saved games, Player statistics

  • You can promote your game quickly and efficiently to Huawei’s vast user base by having users sign in using their HUAWEI IDs. For details about the countries and regions supported by HUAWEI Game Service, please refer to Countries and Regions Supported by HUAWEI Account Kit.
  • You can implement features like achievements and events faster, so you can quickly build the foundations for your game.
  • You can perform in-depth operations tailored to your game content and your users.

Development

I will show how to develop a simple game using the Game Service in this Medium post. It will be a simple Whac-A-Mole clone. We will be using Account Kit, Game Service, Glide, ButterKnife.

Game in action

It will look like this in the end.

Preparation

First, we need to integrate the HMS Core. It is mandatory to use HMS kits and services. You can use these guides to complete integration of HMS Core

Launching the Game

Interaction diagram of game launch

We need to initialize our HMS SDK on the application launch. So after the user started the game by tapping on icon we need to execute to startup program.

Before compilation, ensure that the name of the Application class, for example, android:name=”.MyApplication” has been configured on the application node in the app’s manifest file.

We also need to initialize our game with these 2 lines of code. Don’t forget to add this to the onCreate function.

A Friendly reminder from Huawei:

  • “If your app provides a privacy agreement for users, it should call the init API after the user has accepted the privacy agreement.”

Game Signing In

After launching our game, users need to sign-in so they can use all the features developers delivered without a problem. We will use Huawei ID to sign-in to the game and we will ask the user to sign-in immediately after launch. It is not mandatory, users can play anonymously or by using non-Huawei accounts. Developers can decide what to use. Also, it is good to remember online games released in Mainland China do not allow users to skip sign-in.

Since we are using Huawei ID to sign-in, we will call the sign-in intent from the Account kit. Storing the user login state will be a good idea. We can let users sign-in automatically after the first one. Otherwise, users need to sign-in every time and they will get tired of it and quit.

Sign-in page in action

After a successful sign-in process we can get the current player information such as player id, player name. We can use this information to save players’ state or display their name.

Code snippet for getting the current player

Achievements

Nowadays almost every game has achievements. It is not a game-changer but people seem like loving it. Especially a funny one gives a smiling face to anyone. Game Service offers a really easy and fast solution to game developers for achievements. We only need to create an achievement in AGC. Then we can display it with AppAssistant or with a custom achievement.

To create an achievement we need to login to My apps in AppGallery Connect. Then we need to go to Operate -> Game Achievement and click the Create button.

To create an achievement we need to provide some information. You can look for detailed descriptions of this information using this official page.

After filling all the necessary information we can hit the save button on the top right. When you save an achievement it will become testable. You can test it with a sandbox test account. If there is no problem we can release our achievements by simply hitting the release button on the game achievement page in AGC. While achievement is being reviewed, we can’t edit existing ones or add another one.

To display our achievements we will use AppAssistant first.

Unfortunately, HUAWEI AppAssistant displays achievements only for released games. For games in testing(Open Testing is being counted as released), achievements will not be displayed on HUAWEI AppAssistant. That is why we are also going to create a custom page for achievement.

After we get our achievement list we can simply set it with an adapter for Recycler View. If you are not going to customize your achievement display page AppAssistant display will be a good choice for you. It displays the achievement’s icon, title, state, and player achieve date. For selecting an achievement icon don’t forget minimalist png icon can be hard see.

We need to let the user unlock an achievement after completing the event related to that achievement like hitting a selected score. We can accomplish it with reach(It can be used if there is no network connection or the app does not need to obtain the operation result immediately. It will be submitted after some delay) or reachWithResult(with this option achievement will unlock it immediately).

Leaderboard

Leaderboards are a good way to make players competitive and by doing so players will be more connected to the game. Most players accept this as a challenge and will push themselves to become number one. Using Game Service we can create a leaderboard easily. We need to create a leaderboard in AGC. A game can have up to 70 different leaderboards and a leaderboard can display up to 5000 records. Leaderboards can be daily, weekly, or all-time. You can take a look at this official document to create a leaderboard in AGC.

After creating a leaderboard just like in achievements we need to release it for testing. To submit our player’s score we need to set its state to displayable in the leaderboard.

Status 0 means it can’t be displayable. So we are going to set the status to 1 in onCreate in our game activity. After the player finishes its game session we need to submit the player’s score. We are going use leaderboard id which we will get from the leaderboards page in AGC.

When we finally submit our player’s score. We need to display it so players can see. We will use a custom leaderboard page but just like achievements AppAssistant provides a leaderboard section name “Rankings”. In rankings, you can take a look daily, weekly and all-time scores. Game Service saves game developers who don’t wanna create a custom page for leaderboards or the ones just don’t have time for it.

We are getting ranking scores and displaying with Card View + Recycler View.

Custom Leaderboard Page

Events

The events feature allows game developers to collect specific data generated by your players during gameplay and store them on the Huawei game server for AppGallery Connect to use as feedback to conduct game analytics. We can flexibly define what event data your game should submit, for example, players have paid a specific amount, players reach a certain level, and players perform a specific game action.

We need to create the event in AGC just like previous developments.

After creating our event releasing process same as the achievements and leaderboards. When everything is done with AGC we can display our events. When event display we can choose to display only a single one or all ones.

We will use our event to keep track of the total game score of the player. We will update our event when the game finishes.

Basic Game Information

Basic game information includes the app ID, name, description, and category of your game. Your game can obtain basic game information from Huawei game server or local.

Player Statistics

With this feature, we can the player’s information such as gaming habits, payment routine. We can reward loyal players or send a message like “Don’t leave us” to the player who didn’t sign in for a long time.

You can collect the following statistics about players:

  • The average duration of a session in the statistical period of the past 12 months, in minutes.
  • The number of days since last played. Only data in the statistical period of the past 12 months is collected.
  • The total number of in-app purchases in the statistical period of the past 12 months.
  • The total spending rank, which is an integer ranging from 1 to 6. Only data in the statistical period of the past 12 months is collected.

— 1: no spending

— 2: less than US$10

— 3: US$10 or more and less than US$50

— 4: US$50 or more and less than US$300

— 5: US$300 or more and less than US$1000

— 6: more than US$1000

  • The total number of sessions in the statistical period of the past 12 months.

We will only display our player’s stats but the usage of these statistics only up to developer imagination.

Game Activity

Since we are developing a simple Whac-A-Mole clone. We can use a grid layout with pictures. We will hide all and randomly show a single one. In 10 seconds we will give players a score every time they tap the virus. In the end, we will display an alert dialog to let users about their score and ask them to play again.

You can find the whole code in this GitHub link.

Friendly Reminder; if you are getting duplicate class error including stats you can try adding this to your gradle at the app level.

configurations.all {
exclude group: 'com.huawei.hms', module: 'stats.a.a.a.a'
}

I hope now you have a better understanding of Game Service. In summary, Game Service is a helper and a time server for game developers. They are don’t need to do everything by themselves and sometimes not reinventing the wheel can help you to grow fast.

--

--