/**
 * HangmanExtreme class.
 * Modified Hangman class; creates a random string of 10 characters for the word
 * @author Philip Peng
 * @version Oct 17, 2007
 */

import java.util.Scanner;

public class HangmanExtreme
{
  //private static String[] words = {"inheritance", "abstraction", "encapsulation", "polymorphism"};
  
  private static String chars = "abcdefghijklmnopqrstuvwxyz";

  public static void main(String[] args)
  {
	  // Create random sequence of strings!!!
	  String word = "";
	  for (int i = 0; i < 10; i++) {
		  word = word + chars.charAt((int)(Math.random()*chars.length()));
	  }
	  HangmanGame game = new HangmanGame(word.toString());
	  
    Scanner input = new Scanner(System.in);
    //String word = words[(int)(Math.random() * words.length)];
    //HangmanGame game = new HangmanGame(word);
    int count = 0;
    int failedGuesses = 0;

    boolean done = false;
    while (!done)
    {
      System.out.println("Tried: " + game.getTried());
      System.out.println("Failed guesses: " + failedGuesses);
      System.out.println(game.getGuessed());
      System.out.println();

      System.out.print("Enter next letter (or Quit): ");
      String s = input.next();
      if ("quit".equalsIgnoreCase(s))
        break;
      if (s.length() != 1)
      {
        System.out.println("Invalid input");
      }
      else
      {
        int result = game.tryLetter(s.charAt(0));
        switch(result)
        {
          case 0:

          System.out.println("Already tried");
          break;
          
          case -1:

          System.out.println("Sorry, not there");
          failedGuesses++;
          break;

          case 1:

          System.out.println("Yes!");
          break;
        }
      }
      
      count++;

      if (game.getGuessed().indexOf('-') == -1)
      {
        System.out.println("You guessed " + word + " in " + count + " tries.");
        done = true;
      }
      
    }
  }  
}
