Testing the game
Now, we can run the game in the usual way. Notice the subHorizontalposition
and subVerticalPosition
variables in the following abbreviated logcat output:
subHorizontalPosition: 30 subVerticalPosition: 13
Try running the game again; you will get different positions, demonstrating that our Random
-based code is working and that we can confidently call newGame
whenever we want to start a new game:
subHorizontalPosition: 14 subVerticalPosition: 7
Important note
It is possible but very unlikely that you can call the newGame
method and get a sub' in the same position.
That's it – now, we can spawn our sub' each new game!