So far the only bit of success I get is if I comment out the last line of code you see
(shadePtr = shadePtr + 3)
but then only one row is shaded in. I can't seem to figure out what I am doing wrong here and would appreciate your time and effort.
If I understood your code right the thing is:
yPointer
is the "row" number in your grid.shadePtr
is the index to the next row to be shaded.
The problem is you increase yPointer
in 1 unit in each iteration (which is fine) but shadePtr
is increased in 3 units also in each iteration. As yPointer
starts at 7 and shadePtr
starts at 8, then those variables never be equals because shadePtr
will always be greater than yPointer
.
If you comment that last line in the second iteration yPointer == shadePtr == 8
which is the first shaded row. But later yPointer
will be increased and shadePtr
still 8 so no row will be shaded anymore.
The number 3 is important to solve your problem but making this little change at the end:
int yPointer = 7;
int xPointer = 3;
int shadePtr = 8;
for (int j = 0; j <= 299; j++) {
...
if(xPointer == 13) { //if end of column then go to next row and reset column pointer to 3 and increment shade pointer by 3
yPointer++; //go down a row
xPointer = 3;
if((j % 3) == 0) {
shadePtr = yPointer;
}
}
}
This means, if j
is a multiple of 3 then the next row should be shaded so make this assignment: shadePtr = yPointer
after increase yPointer
. This will shade these row numbers: 8, 11, 14, 17, 20, 23, 26, 29, 32 and 35.
In this way your problem should be solved by making a little change but note shadePtr
is actually unnecessary. You can have a simple boolean to know if the row should be shaded:
int yPointer = 7;
int xPointer = 3;
boolean shade = false;
for (int j = 0; j <= 299; j++) {
...
if(xPointer == 13) { // end of column
yPointer++; //go down a row
xPointer = 3;
shade = (j % 3) == 0;
}
}