Hello all i am designing a crossword puzzle which is a 12x12 String[][] and when i put a word into the puzzle i want to make sure that it is not touching any other words. in my if statement i test every direction around the word. But lets say the word starting position is at [0][0] when i check up and left to make sure there is an empty space i get an array index out of bounds is there a way to catch this somehow inside an if statement?
//down
if(dir == 0 && x+w.getWordLength() <= 12 /*&& board[x-1][y].equals("o") && board[x][y-1].equals("o") && board[x][y+1].equals("o")*/)
{
dcount=dcount+1;
for(int i=0;i < w.getWordLength();i++)
{
board[x+i][y].setStr(""+w.getWord().charAt(i));
board[x+i][y].setUsed(true);
w.setPosition(board[x][y].getPosition());
}
System.out.println(dcount+" DOWN: @position "+w.getPosition()+", "+w.getDescription());
}
//across
if(dir == 1 && y+w.getWordLength() <= 12 /*&& board[x][y-1].equals("o") && board[x-1][y].equals("o") && board[x+1][y].equals("o")*/)
{
acount = acount +1;
for(int i=0;i < w.getWordLength();i++)
{
board[x][y+i].setStr(""+w.getWord().charAt(i));
board[x][y+i].setUsed(true);
w.setPosition(board[x][y].getPosition());
}
System.out.println(acount+" ACROSS: @position "+w.getPosition()+", "+w.getDescription());
}