I have to put a together a game of tic tact toe via processing for a class, but I'm pretty stumped.
The trick is that we have to use a search and storage algorithm which was given to us;
int pX = map(mouseX, 0, width, 0, gridwidth);
int pY = map(mouseY, 0, height, 0, gridheight);
Any help regarding this would be greatly appreciated, the code I have so far is below.
stroke(0);
strokeWeight(5);
line (100,0,100,300);
line (200,0,200,300);
line (0,100,300,100);
line (0,200,300,200);
}
void readArray(){
//searching 2d space and convertin it to 2D spaace
for (int gridRow = 0; gridRow < gridHeight; gridRow ++){
for (int gridCol = 0; gridCol < gridWidth; gridCol++){
//convert grid location to array location
int index = (gridRow * gridWidth) + gridCol;
//output to text window
// print(alphabet[index]);
//translate grid location to pixel location
int pixelX= (int) map(gridRow, 0, gridWidth, 0, width);
int pixelY= (int) map(gridCol, 0, gridHeight, 0, height);
void checkwin(){
// check to see if any COLUMNS are filled with same charcter
// columns are indexed -- > 0,1,2 .. gridWidth
for (int i = 0; i < gridWidth; i++){
if ( (alphabet[i] != ' ')
&& (alphabet[i] == alphabet[ i + 1 * gridWidth])
&& (alphabet[i] == alphabet[ i + 2 * gridWidth]) )
{
print("column " + i + " is all " + alphabet[i]);
} // end if
} // end for
// check to see if any ROWS are filled with same charcter
// you must look in both cells of the row
// the first cell in each rows is INDEXED as a multiple of gridWidth
// therefore the iterator <i> is multiplied by gridWidth -- this ensures that
// your search begins at the start of each row and carries on across
for (int i = 0; i < gridHeight; i++){
if ( (alphabet[i*gridWidth] != ' ')
&& (alphabet[i*gridWidth] == alphabet[i*gridWidth+1]) )
{
println("\trow " + i + " is all " + alphabet[i*gridWidth]);
} // end if
}
}
void alternatePlayer(){
if (currentPlayer == 1) {
println("currentplayer is X");
fill(0);
text("X", mouseX, mouseY);
}
if (currentPlayer == 0) {
println("currentplayer is O");
text("O", mouseX, mouseY);
}