Using for loops to draw the Sub' Hunter grid
By the end of this book, we will have used every type of loop, but the first one we will utilize is the for
loop. Can you imagine having to write a line of code to draw 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 will show you the entire draw
method, just to ensure you can clearly recognize what to delete and what to add. Add the following highlighted code:
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...