[3] Patterns - Streak System
Patterns is an upcoming Android title developed by myself and Paul Gush. In this post I wanted to cover a key aspect that will be present in Patterns - the Streak System: a counter that tracks the days in a row that the player continually opens and plays the game. Such systems make an appearance in widely known apps such as Duolingo and Snapchat. Developing a Streak System allowed me to get experience in implementing such a system and the challenges faced incorporating the system into other aspects of the game, such as achievements.
Implementing the Streak System
The initial and most basic approach was to count the number of days between the player’s current time and the previous time they gained a streak. From this, a streak can be incremented should the day counter be above zero and the player playing one game. The streak number, and the time and date are saved as both integers and strings respectively alongside the player’s high scores and other pieces of data locally. These are loaded once the player loads the game and compared to determine whether the streak will remain. The streak is saved locally in a binary file alongside other data such as game mode high scores and was implemented following a tutorial by Brackeys that I have also used on other personal projects.
Limited the checking the streak with just days has a flaw - a player could play at 11:59 pm and subsequently play at 0:01 AM , 2 minutes later, and have gained a streak of 2 days in just under 2 minutes. The next stage was to incorporate hours.
Days and Hours
By checking both the amount of time in hours and days between the player’s current time and previously acquired streak, I was able to limit the player from being able to acquire a double-barrel streak in a short space of time. This was done by including a set amount of minimum hours (current set at 6) the player must wait before being able to acquire a second streak, as well as checking whether it is the next day.
Losing a streak
In terms of losing a streak, should a player have spent more than 2 days since acquiring their last streak, their current streak is saved and the streak set to zero. This allows the player to keep track of their longest achieved streak should they lose it. It was also implemented, using Google Admob, that should the number of days between the acquired streak and current time be 2 days that an option to ‘save the streak’ be possible by watching a Reward Ad. This ultimately restores the player’s streak to its previous number and allows the player to increment it should they play a game.
Messages
Custom messages are displayed to the user at the start of the game. The message is based on the number of hours and days between their streak on the start-up of the game. The same pop-up system is used for offering the player the ability to save their streak, and tutorial messages on how to play each game mode.
Procedure
In the order below, when the game is loaded the conditions are checked and depending on each condition will trigger a different message and effect:
If it has been more than 2 days
This saves the streak both as their previous streak and if higher than their previous, the highest streak
If it has been more than 1 day
The streak is saved, but a message offering the player to reacquire their streak is given
If it is the next day from the previous streak and been at least 6 hours
A message prompting the player to play a game and acquire a streak is given
If it is still the same day
A message prompts the player to continue to play, and the main menu message prompts the player to return the next day to advance their streak
If it has not been more than 6 hours
Prompts the player to return later to acquire a streak
If the player has gone back in time
This can occur when the player’s clock is showing a time/date prior to the time of the saved streak.
The same procedure is also called when a player plays a game, however with the added functionality of incrementing the player’s streak if #3’s conditions are also met.
Going Forward
As of the publication of this post, the main features of the game including gameplay, the Steak System, Achievements and Advertisements are complete. Paul and I are now adding the final polish prior to releasing the game. I later intend to make further posts on key features of the game.