Good try!
Imagine that QuadNum
has the value 1
. This puts the X in one place, (5,20).
Now imagine that QuadNum
has the value 2
. This puts the X in a different place, (200,20).
Now, how can you get an X at both of those places at the same time? Well, if QuadNum
had a value of both 1 and 2, then it would put X’s in both of those places.
… but QuadNum is only 1 number, and it can;t be both 1 and 2 at the same time.
You will need to take a different approach. Instead of having one number that remembers which spot an X is in, have 9 numbers that represent the spots and record what is in them.
0 | 1 | 2
---------
3 | 4 | 5
---------
6 | 7 | 8
This can then be stored in an ARRAY of numbers:
int[] board = new int[9];
So, board[0]
is the value for the top left corner. board[4]
is the middle space. etc.
Initially, all these spaces will have a value of 0. So we can use 0 to represent nothing in a space. Handy!
If there is a 1 in a space, we will consider that an X:
board[4] = 1; // Put an X in the middle.
And a 2 can be for O:
board[8] = 2;
Now you just need to draw
what goes in each space:
if( board[0] == 1 ){
image(Ximg, 0, 0, width/3, height/3);
} else if( board[0] == 2 ){
image(Oimg, 0, 0, width/3, height/3);
}
if( board[1] == 1 ){
image(Ximg, 200, 0, width/3, height/3);
} else if( board[1] == 2 ){
image(Oimg, 200, 0, width/3, height/3);
}
// ... and so on.
You could write it all out. Or you could make use of some for loops to avoid a lot of typing. This is left as an exercise for you…
Bonus hint: Would these array be useful?
int x_positions = { 0, 200, 400, 0, 200, 400, 0, 200, 400 };
int y_positions = { 0, 0, 0, 200, 200, 200, 400, 400, 400 };