package Cluedo.API;

import java.util.ArrayList;
import java.io.*;
/**
 * 
 * Currently unused but very useful for generating random names
 * 
 * @author Alex
 */
public class NameDictionary {
	ArrayList names = new ArrayList();
	String fileName = "./Resources/names.txt";
	
	String last = "";

	public NameDictionary() {
		
		try {
			BufferedReader stream = new BufferedReader(new FileReader(new File(fileName).getAbsoluteFile()));

			String line = "";
			while((line=stream.readLine())!=null) {
				line=line.trim();
				if(!line.equals(""))
					names.add(line.trim());

			}
		}
		catch(Exception e) {}				
	}
	
	public String getName() {
		int max = names.size();
		int index = (int)(Math.random() * max);

		if(last.equals((String)names.get(index)))
			return getName();
		last = (String)names.get(index);
		return (String)names.get(index);
	}


}