Using for loops to draw the Sub' Hunter grid

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)); ...

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.