please format code with </> button * homework policy * asking questions
char player=‘X’+‘O’; // inputs 2 players
int cols=3;
int rows=3;
Cell board= new Cell[cols][rows];
void setup() {
size(600,600);
for(int i=0; i<cols; i++) {
for(int j=0; j<rows; j++) {
board[i][j]= new Cell(i150,j150,150,150);
}
}
}
void draw(){
for(int i=0; i<cols; i++) {
for(int j=0; j<rows; j++) {
board[i][j].display();
}
}
if(mousePressed){
if(mouseButton == RIGHT){
player=‘X’;
stroke(0,255,0); // colour of X
line(mouseX-50,mouseY-50,mouseX+50,mouseY+50);
line(mouseX+50,mouseY-50,mouseX-50,mouseY+50); //Right click the mouse to spawn an X
println(“Player O’s turn”); /Prints when player X took their turn
to indicate player O’s turn/
}
if(mouseButton == LEFT){
player=‘O’;
stroke(255,0,0); //colour of O
ellipse(mouseX,mouseY,50,50); //Left click the mouse to spawn an O
println(“Player X’s turn”); /*Prints when player O took their turn */
}
}
}
class Cell {
float x;
float y;
float w;
float h;
int state;
Cell (float _x, float _y, float _w, float _h) {
x= _x;
y= _y;
w= _w;
h= _h;
}
void display() {
stroke(0);
fill(255,255,255);
tint (rgb,alpha);
rect(x,y,w,h);
}
}