Final tasks

We only have a few more methods to complete and we have already coded the trickiest bits. The takeShot method having just been passed the player's shot coordinates will compare them to the position of the Sub' and either call draw or boom depending on whether the sub' was hit. We will see how we translate the floating-point coordinates retrieved in onTouchEvent to a position on the grid.

After that, we will code the super-simple boom method which is just a case of increasing the font size, drawing a different color background and then waiting for the player to start another game.

The final bit of coding will be to draw the player's shot on the grid. He can then analyze the last shot compared to the distance and guess at his next shot. ...

Get Learning Java by Building Android Games - Second Edition 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.