All pastes #718592 Raw Edit

Miscellany

public text v1 · immutable
#718592 ·published 2007-09-28 15:21 UTC
rendered paste body
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;
    }
}