import java.util.Scanner;
public class WordSearch
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
}
public static long promptUserForSeed(Scanner input)
{
System.out.println("Enter seed:");
long seed = input.nextLong();
return seed;
}
public static WordBoard findWords(int rows, int cols, long seed)
{
WordBoard board = new WordBoard(rows, cols, WordSearch.promptUserForSeed(Scanner));
System.out.println(board);
System.out.println(board.getSeed());
boolean foundLetter = false;
boolean foundWord = false;
int i2 = 0;
int j2 = 0;
String tempWord = new String();
char[][] puzzle = board.getBoard();
for(String word : board.getDictionary())
{
char letter = word.charAt(0);
boolean up = false;
boolean down = false;
boolean left = false;
boolean right = false;
boolean upLeft = false;
boolean upRight = false;
boolean downLeft = false;
boolean downRight = false;
for(int i1 = 0; i1 < puzzle.length; i1++) //Loop through the puzzle rows
{
for(int j1 = 0; j1 < puzzle.length; j1++) //Loop through puzzle columns
{
if(puzzle[i1][j1] == letter) //When matched with a letter
{
i2 = i1; //Copy location
j2 = j1;
foundLetter = true;
foundWord = false;
if(i1 >= word.length()) //Possible to go up
{
up = true;
}
if((i1 + word.length()) <= puzzle.length) //Possible to go down
{
down = true;
}
if(j1 >= word.length()) //Possible to go left
{
left = true;
}
if((j1 + word.length()) <= puzzle.length) //Possible to go right
{
right = true;
}
if(up == true && left == true) //Possible to go up and left
{
upLeft = true;
}
if(up == true && right == true) //Possible to go up and right
{
upRight = true;
}
if(down == true && left == true) //Possible to go down and left
{
downLeft = true;
}
if(down == true && right == true) //Possible to go down and right
{
downRight = true;
}
if(up == true && foundLetter == true && foundWord == false) //While at a matched letter, go up
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going up
{
tempWord += puzzle[i2][j2];
i2--;
}
if(word.equals(tempWord)) //If the current word matches the word going up
{
board.highlightWord(i1, j1, i2, j2); //Highlight the current word
}
}
i2 = i1; //Reset index for current letter position
j2 = j1;
if(down == true && foundLetter == true && foundWord == false) //While at a matched letter, go down
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going down
{
tempWord += puzzle[i2][j2];
i2++;
}
if(word.equals(tempWord)) //If the current word matches the word going down
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the current word
}
}
i2 = i1; //Reset index for current letter position
j2 = j1;
if(left == true && foundLetter == true && foundWord == false) //While at a matched letter, go left
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going left
{
tempWord += puzzle[i2][j2];
j2--;
}
if(word.equals(tempWord)) //If the current word matches the word going left
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the current word
}
}
i2 = i1; //Reset the index for current letter position
j2 = j1;
if(right == true && foundLetter == true && foundWord == false) //While at a matched letter, go right
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going right
{
tempWord += puzzle[i2][j2];
j2++;
}
if(word.equals(tempWord)) //If the current word matches the word going right
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the word
}
}
i2 = i1; //Reset index for current letter position
j2 = j1;
if(upLeft == true && foundLetter == true && foundWord == false) //While at a matched letter, go up and left
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going up and left
{
tempWord += puzzle[i2][j2];
j2--;
i2--;
}
if(word.equals(tempWord)) //If the current word matches the word going up and left
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the word
}
}
i2 = i1; //Reset the index for current letter position
j2 = j1;
if(upRight == true && foundLetter == true && foundWord == false) //While at a matched letter, go up and right
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going up and right
{
tempWord += puzzle[i2][j2];
j2++;
i1--;
}
if(word.equals(tempWord)) //If the current word matches the word going up and right
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the word
}
}
i2 = i1; //Reset index for current letter position
j2 = j1;
if(downLeft == true && foundLetter == true && foundWord == false) //While at a matched letter, go down and left
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going down and left
{
tempWord += puzzle[i2][j2];
j2--;
i2++;
}
if(word.equals(tempWord)) //If the current word matches the word going down and left
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the word
}
}
i2 = i1; //Reset index for current letter position
j2 = j1;
if(downRight == true && foundLetter == true && foundWord == false) //While at a matched letter, go down and right
{
tempWord = "";
for(int index = 0; index < word.length(); index++) //Make a string with the letters going down and right
{
tempWord += puzzle[i2][j2];
j2++;
i2++;
}
if(word.equals(tempWord)) //If the current word matches the word going down and right
{
foundLetter = false;
foundWord = true;
board.highlightWord(i1, j1, i2, j2); //Highlight the word
}
}
}
}
}
}
return board;
}
}