November 2011
Beginner
196 pages
5h 3m
English
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. ...
Read now
Unlock full access