I need to make an Evil Hangman game for my Java class. Can anyone help please? I really need help figuring out how to put the words into "families". Also, if you see any problems with my code or any ways that I can make the code simpler, please let me know!
Here's the code I have:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class WordFamilies {
public static final String DICTIONARY_FILE = "dictionary.txt";
public static final boolean SHOW_COUNT = false; // show # of choices left
private static final int MAX_MISSES = 1000;
private static ArrayList<String> list;
public static void main(String[] args) throws FileNotFoundException {
// String [] input = {"java","push","john","word","four","exi…
// list = new ArrayList<String>();
// int len = 4;
System.out.println("Welcome to Hangman!");
System.out.println();
Scanner console = new Scanner(System.in);
// open the dictionary file and read dictionary into an ArrayList
Scanner input = new Scanner(new File(DICTIONARY_FILE));
List<String> dictionary = new ArrayList<String>();
List<String> correctlength = new ArrayList<String>();
//List<String> firstletter = new ArrayList<String>();
while (input.hasNext())
dictionary.add(input.next().toLower…
System.out.print("Would you like a running total of how many words are left to guess? (y/n)");
String yn = console.next();
if (yn.charAt(0) == 'y'){
System.out.println("Words remianing: " + dictionary.size());
}
System.out.print("What length word do you want to use? ");
int length = console.nextInt();
while (length < 2 || length > 29 || length == 26 || length == 27){
System.out.print("What length word do you want to use? ");
length = console.nextInt();
}
for (int i = 0; i < dictionary.size(); i++){
if(dictionary.get(i).length() == length){
correctlength.add(dictionary.get(i…
}
}
if (yn.charAt(0) == 'y'){
System.out.println("Words remianing: " + correctlength.size());
}
int missesAllowed = 0;
while ((missesAllowed < 1) || missesAllowed > MAX_MISSES) {
System.out.print("How many wrong answers allowed? ");
missesAllowed = console.nextInt();
System.out.println("\nGuess a letter.");
String guess = console.next().toLowerCase();
if (guess.length() > 1 || guess.length() < 0)
System.out.println("Please guess only one letter at a time.");
for (int j = 0; j < correctlength.size(); j++){
char [] answer = new char[length]; //create appropriate length
for (int x = 0; x < length; x++){
if (correctlength.get(j).charAt(x) == guess.charAt(0)){
answer[x*2] = guess.charAt(0);
}
}
addToList(new String(answer));
//System.out.println(new String(answer) + " " + input[j]);// + " " + found + " " + loc + " " + numberOf);
}
// for (String s : list)
// System.out.println(s);
}
}
}
here's the link to the dictionary:
ftp://144.96.100.120/csc/rball/dictionary.txt
If you copy and paste what is in the link to a .txt file, you can have your own copy of this "awesome" dictionary...