Learning Java by Building Android  Games
上QQ阅读APP看书,第一时间看更新

Testing the game

Run the game in the usual way and observe the output.

This is the logcat output:

Debugging: In onCreate
Debugging: In newGame
Debugging: In draw
numberHorizontalPixels: 1776
numberVerticalPixels: 1080
blockSize: 44
gridWidth: 40
gridHeight: 24
horizontalTouched: -100.0
verticalTouched: -100.0
subHorizontalPosition: 0
subVerticalPosition: 0
hit: false
shotsTaken: 0
debugging: true
distanceFromSub: 0

We can see all the usual methods being activated in the same way as before with the addition of all our debugging variables being printed after the draw method. And if we click the screen all the debugging data is printed out every time the draw method is called. This is because the draw method calls the printDebuggingText method.