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. ...

Get Beginning Android Tablet Games Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.