gamesthread.java

来自「java的一些介绍:基础语法、基本概念、applet、servlet、javab」· Java 代码 · 共 49 行

JAVA
49
字号
package bingo.game;import bingo.shared.*;class GamesThread extends Thread {    private RingMaster ringMaster;    private boolean moreGames = true;    GamesThread(RingMaster ringMaster) {	super("Bingo GamesThread");	this.ringMaster = ringMaster;    }    public void run() {	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();	}    }    void noMoreGames() {	moreGames = false;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?