Your First Kotlin Android App: Polishing the App

Jul 14 2022 · Kotlin 1.6, Android 12, Android Studio Bumblebee | 2021.1.1

Part 1: Build Out the App

07. Challenge: Add Bonus Points

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Improve the Alert Title Next episode: 08. Restart the Game

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 07. Challenge: Add Bonus Points

I have an idea on how to make Bullseye a bit more fun. What if we modified bullsye to give the player an additional 100 bonus point when they hit a perfect score? This would encourage the players to really try and place the bullseye exactly on the target.

Otherwise, there isn’t much difference between 100 points for a perfect score and 98 or 95 points if you’re close but not quite there.

While you’re at it, give the player 50 bonus points if they’re just one off from the perfect score.

That’s it - go ahead and pause the video and give it a shot, and stay tuned for the solution.

How was the challenge? Hopefully, you did well. As always, if you got stuck, feel free to follow along.

Start by heading over to the pointsForCurrentRound method. Then create a new bonus variable and set it to 0:

var bonus = 0

After that, create an if block to determine the bonus amount based on the difference. Enter the following code:

if (difference == 0) {
  bonus = 100
} else if (difference == 1) {
  bonus = 50
}

Finally, add the bonus to the returned score like so:

return maxScore - difference + bonus

Run your app.

Then try to get the slider right on the exact target.

When you do, you’ll see your new bonus point which would be an extra 100 if you hit a perfect score. Or an extra 50 if you’re 1 point away from the perfect score.

Well done!