/*
 * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies. Please refer to the file "copyright.html"
 * for further important copyright and licensing information.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */
package bingo.shared;

import java.io.Serializable;

public class BingoBall implements Serializable {
    public int number;		// must be greater than 1 and less than 75
    private char letter;

    public static final int FREE_SPACE = -1;
    public static final int GAME_OVER = -2;

    public static final int MIN = 1;
    public static final int MAX = 75;

    public static final int RANGE = 15;

    public static final int MAX_B = 15;
    public static final int MAX_I = 30;
    public static final int MAX_N = 45;
    public static final int MAX_G = 60;
    public static final int MAX_O = 75;

    public BingoBall(byte[] b) {
	this(b[0]);
    }

    public BingoBall(int n) {
	if (n >= MIN && n <= MAX) {
	    number = n;
	    if (n <= MAX_B) letter = 'B';
	    else if (n <= MAX_I) letter = 'I';
	    else if (n <= MAX_N) letter = 'N';
	    else if (n <= MAX_G) letter = 'G';
	    else if (n <= MAX_O) letter = 'O';
	} else if (n == GAME_OVER) {
	    number = GAME_OVER;
	    letter = ' ';
	} else {
	    number = FREE_SPACE;
	    letter = ' ';
	}
    }
    public boolean equals(Object obj) {
	if (!(obj instanceof BingoBall))
	    return false;
	if (((BingoBall)obj).number == number) {
	    return true;
	} else
	    return false;
    }
    public byte[] getBytes() {
	byte[] answer = { (byte)number };
	return answer;
    }
    public int getNumber() {
	return number;
    }
    public char getLetter() {
	return letter;
    }

    public String toString() {
	return new StringBuffer().append(letter).append(number).toString();
    }
}
