FileDocCategorySizeDatePackage
GamesThread.javaAPI DocExample1110Tue Dec 12 18:58:40 GMT 2000bingo.game

GamesThread

public class GamesThread extends Thread

Fields Summary
private RingMaster
ringMaster
private boolean
moreGames
Constructors Summary
GamesThread(RingMaster ringMaster)


      
	super("Bingo GamesThread");
	this.ringMaster = ringMaster;
    
Methods Summary
voidnoMoreGames()

	moreGames = false;
    
public voidrun()

	long now, startGameAt;
	int timeRemaining;

	while (moreGames) {
	    ringMaster.waitForFirstPlayer();

	    now = System.currentTimeMillis();
	    startGameAt = now + ringMaster.getGameParameters().getCountDown();

	    while (ringMaster.isCountingDown()) {
	        timeRemaining = (int)(Math.ceil((double)(startGameAt - now)/Constants.ONE_SECOND));
	        ringMaster.sendTimeRemainingMessage(timeRemaining);

	        try {
	            Thread.currentThread().sleep(Constants.FIVE_SECONDS);
	        } catch (InterruptedException e) {
	        }

	        now = System.currentTimeMillis();
	        if (now > startGameAt) {
 		    ringMaster.startGame();
		}
	    }
            new BallAnnouncer(ringMaster).start();

	    ringMaster.waitForGameToEnd();
	}