O'Reilly logo

Beginning Android Tablet Games Programming by Jeremy Kerfs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing Game Outcomes

When the player loses the game and a boat hits the castle, you call reset(). This is a simple and quick function.

Follow these steps:

1. Add the code from Listing 9-19 below the other functions in GameView.

Listing 9-19. reset() Method

private void reset(){         for(int i = 0; i < boat_count; i++){                 boat[i].setstate(boat[i].DEAD);         }         boat_count = 0; }

All you do is destroy the boats. This, in effect, restarts the game, because the boats are randomly created once again. You don’t remove the cannons because there is no need to worry about them. The user can delete them if they wish. If you want to display a message to the user, you can create a sprite and draw it onscreen at this point. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required