I can’t get my code to work to print once and leave the X and O there.
Does anyone have tips?
int nRows = 3, nColumns= 3;
int gameBoard [][]=new int [nRows][nColumns];
int player=3;
int symbol=1;
int x=width/nRows;
int y= height/nColumns;
void setup() {
size(800, 800);
rectMode(CORNER);
ellipseMode(CORNER);
}
void draw() {
drawGrid();
oppositePlayer();
drawSymbols(symbol);
}
void drawGrid() {
for (int row=0; row<3; row++) {
for (int column=0; column<3; column++) {
fill(20, 0, 100);
rect (row*width/nRows, column*height/nColumns, width/nRows, height/nColumns);
//drawSymbols(gameBoard[row][column]);
}
}
}
void drawSymbols(int a) {
int row=0;
int column=0;
switch(a) {
default:
if (mousePressed == false);
break;
case 1:
if (mousePressed == true && player ==1 )
fill(0);
textSize(100);
text(("X"), (width/nRows)*row+x/2, (height/nColumns)*column+y/2);
;
case 2:
if (mousePressed == true && player == 2)
fill(255);
textSize(100);
text(("O"), (width/nRows), (height/nColumns)*column+y/2);
}
}
void mouseClicked() {
int row = mouseY;//ellHeight
int column= mouseX;//cellWidth
gameBoard[row][column] = 1;
player = oppositePlayer();
}
int oppositePlayer() {
return 3 - player;
}
void clearBoard() {
for (int row=0; row<2; row++)
for (int column=0; column<2; column++)
gameBoard[row][column] =0;
}