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.