//create a backup grid first
x is the starting row position, y is the starting col position that were picked randomly
letters is the character array that holds the letters of the current word
//for each spot, check if it is null or has the letter
//we are looking for, if it does, put the letter there
for(int i=0; i<letters.length; i++) {
if(grid[x][y]=='\0' || grid[x][y]==letters[i]) {
grid[x][y]=letters[i];
x+=rowInc;
y+=colInc;
if(x<0) {
x=rows-1;
} else {
x=x%rows;
}
if(y<0) {
y=cols-1;
} else {
y=y%cols;
}
} else {
//if it can't find a spot, copy the old grid back
for(int j=0;j<grid.length; j++) {
for(int k=0;k<grid[j].length;k++) {
grid[j][k]=grid2[j][k];
}
}
wordInserted=false;
}
}