FileDocCategorySizeDatePackage
Card.javaAPI DocExample1887Tue Dec 12 18:58:42 GMT 2000bingo.shared

Card

public class Card extends Object implements Serializable

Fields Summary
public static final int
SIZE
public static char[]
columnTitles
public BingoBall[]
boardValues
private byte[]
signature
Constructors Summary
public Card()


      
	this(new Random(System.currentTimeMillis()));
    
public Card(Random generator)

	int min=0, max=0;

	for (int i = 0; i < SIZE; i ++) {
            int numBalls = BingoBall.RANGE;
            Vector balls = new Vector(numBalls);
	    Stack randomBalls = new Stack();

	    switch (i) {
	    case 0:
		min = BingoBall.MIN;
		max = BingoBall.MAX_B;
		break;
	    case 1:
		min = max + 1;
		max = BingoBall.MAX_I;
		break;
	    case 2:
		min = max + 1;
		max = BingoBall.MAX_N;
		break;
	    case 3:
		min = max + 1;
		max = BingoBall.MAX_G;
		break;
	    case 4:
		min = max + 1;
		max = BingoBall.MAX_O;
		break;
	    }
                // generate all 15 balls in this range
            for (int j = min; j <= max; j++) {
                balls.addElement(new BingoBall(j));
	    }

                // randomize the 15 balls
            for (int k = BingoBall.RANGE - 1; k >= 0; k--) {
                int num = (int)(generator.nextDouble() * (k+1));
                randomBalls.push(balls.elementAt(num));
                balls.removeElementAt(num);
            }

		 // choose 5 of them to put on the card
	    for (int j = 0; j < SIZE; j ++) {
		boardValues[j][i] = (BingoBall)randomBalls.pop();
	    }
	}

	boardValues[2][2] = new BingoBall(BingoBall.FREE_SPACE);

    
Methods Summary
public byte[]getSignature()

	return signature;
    
public voidsetSignature(byte[] sig)

	signature = sig;