import java.util.*;

public class JogglePlay implements JoggleFE
{
    public JogglePlay(Vector words)
    {
	myDictionary = words;
	myGraph = new JoggleGraph(words);
	myWords = new Vector();
    }
    public void startGame(char board[][])
    {
	int j;
	int k;
	int size = board[0].length;
	for(j=0; j < size; j++)
	{
	    for(k=0; k < size; k++)
	    {
		System.out.print(board[j][k]+" ");
	    }
	    System.out.println();
	}

	myGraph.init(board);
	FindWords();	
    }

    void FindWords()
    {
	int count = 0;
	Enumeration e = myDictionary.elements();
	while (e.hasMoreElements())
	{
	    String s = (String) e.nextElement();
	    if (myGraph.isWord(s))
	    {
		System.out.println(count + " " + s);
		count++;
		synchronized(myWords)
		{
		    myWords.addElement(s);
		}
	    }
	}
    }

    public String[] stopGame()
    {
	synchronized(myWords)
	{
	    int count = myWords.size();
	    String words[] = new String[count];
	    myWords.copyInto(words);
	    return words;
	}
    }

    private JoggleGraph myGraph;
    Vector myDictionary;
    Vector myWords;
}


