By the end of the book we will have used every type of loop but the first one we get to utilize is the for
loop. Can you imagine having to write a line of code to draw each and every line of the grid in Sub' Hunter?
We will delete the existing drawLine…
code in the draw
method and replace it with two for
loops that will draw the entire grid!
Here I show you the entire draw
method just to be sure you can clearly recognize what to delete and what to add. Add the highlighted code shown next.
void draw() { gameView.setImageBitmap(blankBitmap); // Wipe the screen with a white color canvas.drawColor(Color.argb(255, 255, 255, 255)); // Change the paint color to black paint.setColor(Color.argb(255, 0, 0, 0)); // Draw the vertical lines of the grid for(int i = 0; i < gridWidth; i++){ canvas.drawLine(blockSize * i, 0, blockSize * i, numberVerticalPixels, paint); } // Draw the horizontal lines of the...