please format code with </> button * homework policy * asking questions
//A simple tic tac toe by Caleigh Esterhuyse
Grid grid;
int numMoves = 9;
int column, row;
boolean player1Playing = true;
int moves = new int[numMoves];
void setup() {
size(600, 630);
grid = new Grid();
}
void draw() {
background(255);
grid.display();
drawPlayerLabel();
gameElements();
}
void mousePressed() {
column = mouseX/200;
row = mouseY/200;
int indexInArray = column + (row * 3);
if (moves[indexInArray] == 0) {
if (player1Playing) {
moves[indexInArray] = 1;
} else {
moves[indexInArray] = 2;
}
}
player1Playing = !player1Playing;
}
void drawPlayerLabel() {
String label = “Player 1”;
if (player1Playing == false) {
label = “Player 2”;
}
fill(0);
textSize(16);
textAlign(CENTER, BOTTOM);
text(label, width/2, height - 5);
}
void gameElements() {
for ( int i = 0; i < moves.length; i++) {
column = i % 3;
row = i / 3;
switch (moves[i]) {
case 1:
new Cross(column, row);
break;
case 2:
new Circle(column, row);
break;
}
}
}
class Circle {
int column, row;
Circle(int column, int row) {
this.column = column;
this.row = row;
display();
}
void display() {
strokeWeight(10);
stroke(#6DC5D3);
fill(255);
pushMatrix();
//translate( 100 + column * 200, 100 + row * 200);
circle(100 + 200 * column, 100 + 200* row, 100);
popMatrix();
}
}
class Cross {
int column, row;
Cross(int column, int row) {
this.column = column;
this.row = row;
display();
}
void display() {
strokeWeight(10);
stroke(#E37272);
pushMatrix();
translate( 100 + column * 200, 100 + row * 200);
line(- 40, -40, 40, 40);
line(- 40, 40, 40, -40);
popMatrix();
}
}
class Grid {
//Methods
void display() {
strokeWeight(1);
stroke(0);
line(width/3, 15, width/3, height - 15);
line(width/32, 25, width/32, height - 15);
line(0, height/3, width, height/3);
line(0, height/32, width, height/32);
}
}