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!");
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())
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){
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:

If you copy and paste what is in the link to a .txt file, you can have your own copy of this "awesome" dictionary...

how to put the words into "families"

What is a "family" of words?

Suppose that the dictionary contains just the following 9 words:

[ally, beta, cool, deal, else, flew, good, hope, ibex]

Now, suppose that the user guesses the letter ‘e’. You now need to indicate which letters in the word you've “picked” are e's. Of course, you haven't picked a word, and so you have multiple options about where you reveal the e's. Every word in the set falls into one of five “word families:”

· “- - - -”: which is the pattern for [ally, cool, good]

· “- e - -”: which is the pattern for [beta, deal]

· “- - e -”: which is the pattern for [flew, ibex]

· “e - - e”: which is the pattern for [else]

· “- - - e”: which is the pattern for [hope]

Since the letters you reveal have to correspond to some word in your word list, you can choose to reveal any one of the above five families. There are many ways to pick which family to reveal – perhaps you want to steer your opponent toward a smaller family with more obscure words, or toward a larger family in the hopes of keeping your options open. In this assignment, in the interests of simplicity, we'll adopt the latter approach and always choose the largest of the remaining word families. In this case, it means that you should pick the family “- - - -”. This reduces your set of words to:

[ally, cool, good]

Since you didn't reveal any letters, count this as a wrong guess.

Let's see a few more examples of this strategy. Given this three-word set, if the user guesses the letter 'o;, then you would break your word list down into two families:

· “- o o -”: containing [cool, good]

· “- - - -”: containing [ally]

The first of these families is larger than the second, and so you choose it, revealing two 'o's in the word and reducing your set of words to

[cool, good]

In this case, count this as a correct guess because there are two occurrences of 'o' in the new pattern.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.