/**
 * @(#)Letter.java	11/03/05
 * 
 * Copyright 2005 3GP01, KCL.  All unmodified code is copyright of its respective owner.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * The GNU General Public Licence should be contained within licence.txt;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA  02110-1301, USA.
 */


/**
 * This class defines a Letter.
 * A Letter has constituent parts - a symbol, a score, and a character representation. 
 * 
 * @author 3GP01 - Hardev Bhamra, Deepak Chandarana, James Tompkin
 * @version 2.0
 * @see LetterMove
 * @see Word
 */
public class Letter // implements Comparable
{
	private char symbol;

	private char ascii;

	private int score;

	protected boolean blank;

	public Letter(char sym, int scre) 
	{
		symbol = sym;
		ascii = sym;
		score = scre;
	}

	public Letter(char sym, int scre, char asc) 
	{
		this(sym, scre);
		ascii = asc;
	}

	public boolean isBlank() 
	{
		return blank == true;
	}

	public int getScore() 
	{
		return score;
	}

	public String toString() 
	{
		return "" + symbol;
	}

	public String toAscii() 
	{
		return "" + ascii;
	}

	public void resetBlank() // for blanks
	{
		if (isBlank()) {
			symbol = ' ';
		}
	}

	public char getSymbol() 
	{
		return symbol;
	}

	public void setSymbol(char sym) 
	{
		symbol = sym;
	}

	public void setAscii(char asc) 
	{
		ascii = asc;
	}

	public Object clone() 
	{
		return new Letter(symbol, score, ascii);
	}

	public String toXml() 
	{
		return "    <letter>\n" + "      <symbol>" + symbol + "</symbol>\n"
				+ "      <score>" + score + "</score>\n" + "    </letter>\n";
	}

	//what does this do?  does it test to see if an input object is a Letter?
	public boolean equals(Object obj) 
	{
		if (obj instanceof Letter) {
			Letter ll = (Letter) obj;
			if (ll.symbol == symbol && ll.getScore() == score) {
				return true;
			}
			if (ll.getScore() == 0 && score == 0) {
				return true;
			} // But if there are 2 blanks on the rack ... 
		}
		return false;
	}
}

