Final tasks
We only have a few more methods to complete, and we have already coded the trickiest bits. The takeShot
method that's 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 learn how we translate the floating-point coordinates we retrieved from onTouchEvent
into 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. They can then analyze the last shot compared to the distance and guess their next shot.
Coding the takeShot method
Let's redo the entire takeShot
method since the signature is changing too. Adapt the takeShot
method so that it looks like this; then, we will analyze the code...