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;
private ArrayList<Character> guessedLetters;
char [] wordArray;
String wordToConvert;
char charGuess;
char correctChar;
boolean duplicateGuess;
boolean usedBefore;
boolean correctGuess;
public Word()
{
usedWords = new ArrayList<String>();
guessedLetters = new ArrayList<Character>();
}
/**
* 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
for( int index = 0; index < wordArray.length; index++ )
{
System.out.print(" _ ");
}
System.out.println();
}
/**
* 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;
}
/**
* Stores the current word in an array
*/
public void addWord()
{
usedWords.add(wordToConvert);
}
/**
* Checks player's character input against previously guessed letters
*
* @return duplicateGuess
*/
public boolean checkLetter()
{
for( int index = 0; index < guessedLetters.size(); index ++ )
{
if( charGuess == guessedLetters.get(index) )
{
duplicateGuess = true;
}
else
{
duplicateGuess = false;
}
}
return duplicateGuess;
}
/**
* Checks player's character guess
*
* @return correctGuess
*/
public boolean checkGuess()
{
System.out.println(duplicateGuess);
for( int index = 0; (index <= wordArray.length-1); index++ )
{
if( (charGuess == wordArray[index]) && (!duplicateGuess) )
{
correctGuess = true;
guessedLetters.add(charGuess);
correctChar = charGuess;
System.out.print(" " + correctChar + " ");
}
else
{
correctGuess = false;
System.out.print(" _ ");
}
}
return correctGuess;
}
/**
* Print out guessed letters
*/
public void showGuessedLetters()
{
System.out.println("Incorrect guesses:");
for( int index = 0; index < guessedLetters.size(); index++ )
{
System.out.println(guessedLetters.get(index));
}
}
}