Hiya, I need to make a game for my cs class.
My game is the word find game and it plays like this:
You are given a long word like "antidisestablishmentarianism"
and your goal is to find as many words in to word given as possible.
My program will save the word inputed and check if they have been used before and check if the word inputed is inside the word given.
My game currently compiles but is missing some key ingredients like a loop to repeat
JOptionPane.showInputDialog("Please Enter a String");
asking the user to input words.
public class WordFind
{
public static void main(String[] args)
{
String word = "antidisestablishmentarianism";
System.out.println(word);
String input = JOptionPane.showInputDialog("Please Enter a String");
WordsEntered game = new WordsEntered();
if (game.check(input)) //checks if input was used before
{
for (int i = input.length()-1; i == 0; i--) //gets the last letter from input
{
for (int c = word.length()-1; c == 0; c--) //gets the last letter from word
{
if ((input.substring(i)).equals(word.substring(c))) //checks input's last letter with word's last letter
{
if (input.substring(0).equals(word.substring(0))) //checks if the checking letters if done then input is added
{
game.add2Array(input);
game.lastWord();
}
}
else
{
System.out.println("Invalid Word:" + input.substring(i) + "is not in word");
break;
}
}
}
}
else
{
System.out.println("Invalid Word: input found in wordsUsed");
}
}
}
public class WordsEntered
{
ArrayList<String> wordsUsed;
public WordsEntered()
{
wordsUsed = new ArrayList<String>();
}
public void add2Array(String input) // adds word to wordsUsed array
{
wordsUsed.add(input);
}
public String lastWord()
{
return wordsUsed.get(wordsUsed.size()-1);
}
public boolean check(String input)
{
Iterator<String> itr = wordsUsed.iterator();
while(itr.hasNext())
{
if (itr.next().equals(input))
{
return false;
}
}
return true;
}
}