package WheelOfFortune.game;


// Source file: U:\\cse308\\asn8\\src\\game\\Board.java
import WheelOfFortune.storage.*;

public class Board {
 private String availableLetters;
 private Puzzle puzzle;
 private String consonantsLeft;
 private String vowelsLeft;
   
 /**
  * @param puzzle
  * @roseuid 4189339502D8
  */
 public Board(Puzzle puzzle) {
  availableLetters = Utilities.getAlphabetString();
  this.puzzle = puzzle;
  consonantsLeft = "BCDFGHJKLMNPQRSTVWXYZ";
  vowelsLeft = "AEIOU";
 }
   
 /**
  * @param guess
  * @return boolean
  * @roseuid 4189339D0044
  */
 public boolean solvePuzzle(String guess) {
 	boolean result = guess.trim().equalsIgnoreCase(puzzle.getSolution().trim());
 	if(result)
 		availableLetters = "";
 	return result;
 }
   
 public String getPuzzleString()
 {
 	return puzzle.getSolution().trim();
 }
 /**
  * @param letter
  * @return int
  * @roseuid 418933A300E3
  */
 //Return the number of occurences of a letter in the puzzle solution
 //if the letter has already been chosen, return -1
 public int guessLetter(char letter) {
  String letterString = (letter + "").toUpperCase();

  if(availableLetters.indexOf(letterString) == -1) return -1;

  availableLetters = availableLetters.replaceAll(letterString,"");
  vowelsLeft = vowelsLeft.replaceAll(letterString,"");
  consonantsLeft = consonantsLeft.replaceAll(letterString,"");
  
  String ps = puzzle.getSolution();
  int occurences = ps.length() - ps.replaceAll(letterString.toLowerCase(),"").length();
  occurences += ps.length() - ps.replaceAll(letterString.toUpperCase(),"").length();
  return occurences;
 }

 public String display()
 {
 	String ps = puzzle.getSolution();
 	  for(int i = 0;i < availableLetters.length();++i) {
 	   ps = ps.replaceAll(availableLetters.charAt(i) + "","!");
 	   ps = ps.replaceAll((availableLetters.charAt(i) + "").toUpperCase(),"!");
 	  }
 	  return ps;	
 }
 
 //return what the board looks like to the players
 public String appearance() {
  return display() + " Category: " + puzzle.getCategory();
 }
   
 /**
  * @return String
  * @roseuid 418933A80203
  */
 //return all information about the board
 public String toString() {
  return "Available: " + availableLetters + "\n" + puzzle.toString();
 }
 public String getCategory()
 {
 	return puzzle.getCategory();
 }
/**
 * @return Returns the consonantsLeft.
 */
public String getConsonantsLeft() {
	return consonantsLeft;
}
/**
 * @return Returns the vowelsLeft.
 */
public String getVowelsLeft() {
	return vowelsLeft;
}
}
