Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

3. Game #2, Rocket Commander > Time for action — modifying the UpdateGame metho...

Time for action — modifying the UpdateGame method

To modify the UpdateGame method, we will follow the ensuing steps:

  1. We need to modify the UpdateGame method in the mainClass.monkey file.
    Method UpdateGame:Int()
    
  2. Check if a random number is equal to 100 and the current active bombs are not more than the level number.
    If Rnd(0,100) > 99 And (GetBombsCount() < levelNumber) Then
    
  3. Create a new bomb.
    CreateBomb()
    Endif
    UpdateLaunchers()
    UpdateBombs()
    UpdateRockets()
    UpdateExplosions()
    
  4. If no city is left, remove all rockets, bombs, and explosions, and set the game mode to gmGameOver.
    If GetCityCount() = 0 Then
    RemoveRockets()
    RemoveBombs()
    RemoveExplosions()
    gameMode = gmGameOver
    Endif
    
  5. Check if the next level is reached by comparing levelNumber times 10 with the total number of destroyed bombs.
    If totalBombsDestroyed >= (levelNumber * 10) Then
    

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint