import java.util.ArrayList;
/**
* Controls various functions relating to the word being guessed
*
* @author Leon Traill
* @version 0.01
*/
public class Word
{
private ArrayList<String> usedWords;
char [] wordArray;
char [] guessedLetters;
String wordToConvert;
char charGuess;
char correctChar;
boolean usedBefore;
boolean correctGuess;
public Word()
{
usedWords = new ArrayList<String>();
}
/**
* Checks if the current word has already been used in the game
*/
public boolean checkUsedBefore()
{
for( int index = 0; index < usedWords.size(); index++ )
{
if( usedWords.get(index).equals(wordToConvert) )
{
usedBefore = true;
}
else
{
usedBefore = false;
}
}
return usedBefore;
}
/**
* Convert the current word into a char array, and display a series of placeholer dashes
*/
public void convertToDashes()
{
// Split the current word into seperate characters
//char [] wordArray = wordToConvert.toCharArray();
for( int index = 0; index < wordArray.length; index++ )
{
System.out.print("_");
System.out.print(" ");
}
System.out.println();
}
/**
* Stores the current word in an array
*/
public void addWord()
{
usedWords.add(wordToConvert);
}
/**
* Checks player's character guess
*
* @return correctGuess
*/
public boolean checkGuess()
{
for( int index = 0; index < wordArray.length; index++ )
{
if( charGuess == (wordArray[index]) )
{
correctGuess = true;
correctChar = charGuess;
for( int i = 0; index < wordArray.length; i++ )
{
if( wordArray[i] == correctChar )
{
System.out.print(correctChar);
}
else
{
System.out.print(" _ ");
}
}
}
else
{
correctGuess = false;
}
}
return correctGuess;
}
}