import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Interface that defines the methods that must be implement by a Hangman.
 *   @author Dave Reed
 *   @version 2/4/18
 */
public abstract class Hangman {  
    protected List<String> dictionary;
    protected List<Character> guesses;
    protected int wrongCount;

    /**
     * Constructs a Hangman object.
     *   @param words the list of words that can be guessed
     *   @param numGuesses the number of guesses allowed
     */
    public Hangman(Collection<String> words) {
        this.dictionary = new ArrayList<String>(words);
        this.guesses = new ArrayList<Character>();
        this.reset();
    }
    
    /**
     * Returns a collection of all characters guessed so far.
     *   @return the collection of guessed characters
     */
    public Collection<Character> getGuesses() {
        return new ArrayList<Character>(this.guesses);
    }
    
    
    /**
     * Returns the number of wrong guesses made so far.
     *   @return wrong guess count
     */
    public int getNumWrong() {
        return this.wrongCount;
    }
    
    /**
     * Returns the selected word with unguessed letters redacted (i.e., replaced by '-').
     *   @return the redacted word
     */
    public abstract String getRedactedWord();
        
    /**
     * Records a guess and returns a message describing the result.
     *   @param guess the character being guessed
     *   @return a message describing the result of the guess, either 
     *           "You already guessed X.", "Sorry.  X does not appear in the word.",
     *           or "Good guess!".
     */
    public abstract String makeGuess(char guess);
    
    /**
     * Resets the game, selecting a new word and resetting the guesses.
     */
    public abstract void reset();
    
    ////////////////////////////////////////////////////////////////////////////
    
    protected String redact(String s) {
        String result = "";
        for (int i = 0; i < s.length(); i++) {
            char next = s.charAt(i);
            if (this.guesses.contains(next)) {
                result += next;
            } else {
                result += "-";
            }
        }
        return result;
    }
}
