Testing the game

Now we can run the game in the usual way. Notice the subHorizontalposition and subVerticalPosition variables in this abbreviated logcat output:

subHorizontalPosition: 30
subVerticalPosition: 13

Try running the game again and notice you will get different positions demonstrating that our Random based code is working, and we can confidently call newGame whenever we want to start a new game.

subHorizontalPosition: 14
subVerticalPosition: 7

Note

It is possible but very unlikely that you can call newGame and get a sub in the same position.

That's it, we now can spawn our sub' each new game.

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.