Time for action — updating the text info

We will build the functionality to update text info into a method that will update not only the time left, but also the game's score value.

  1. Add a new method called UpdateInfoText in the game class.
    Method UpdateInfoText:Int()
    
  2. Set the text property of txtScore with the score value.
    txtScore.SetText(score)
    
  3. Calculate the number of seconds left by subtracting the current millisecond value from the end time, after adding 750 (to make it more accurate), and then dividing everything by 1000, to get seconds.
    seconds = (endTime-Millisecs()+750)/1000
    
  4. Determine the number of minutes left using the value of seconds.
    minutes = seconds/60
    
  5. Subtract the result of minutes times 60 to get the seconds left.
    seconds -= (minutes*60)
    
  6. Depending on how many seconds are left, set the text property of txtTime.
    If seconds > 9 Then
    txtTime.SetText(minutes+":"+seconds)
    Else
    txtTime.SetText(minutes+":0"+seconds)
    Endif
    
  7. Close this method.
    Return 0
    End
    End
    

What just happened?

The method UpdateInfoText will update the game's score text object and also calculate the time left in minutes and seconds. During the game, the updated info text objects will look like this:

What just happened?

Showing the "game over" screen

The 'game over' screen in Treasure Chest is a very simple one. It will display a little box with the text Game Over and your score.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset