If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Scrabble, puting chars into a 2d array

OK im making a game of scrabble in java for Computer Science.

The thing I can't work out, is how when given a string for a word and its direction (horizontal, vertical) can I check whether it goes there ( 1 char per cell-thingo without leaving the 15x15 array, and whether it will be allowed, must have a common letter with a word already placed (unless first word).

I assume the user is putting the pieces in the grid 1 letter at a time.

using the piece's coordinates as index numbers, plug it in the array. The array could hold "0" for an empty spot and "1" for an already occupied spot. Then you can check for combinations of letters around it. This would probably be a recursive method.
For instance, lets say the word "dog" takes up spots (1,1), (1,2),(1,3). Now the user puts in an "s" at (x,y), where x=1 and y=4. Now check surrounding tiles. Eventually, it'll see there's a letter at (1,y-1), the "g". Have it continue searching for letters in that direction, the Y-direction. Eventually, it'll either find a blank spot, or in this case hit the edge of the board. So now you have letters from (1,1) to (1,4). Combine the 4 letters into a String and check the word against known words in your dictionary. The dictionary is needed to make sure the words exists in the language. Using a binary search, you can make this check perform relatively quickly.