我创建了一个带有计时器的游戏,我试图让当计时器结束时,玩家会看到警报弹出窗口或任何类型的弹出窗口,上面写着“关卡完成”,你的积分是 xxx 和下一个关卡的按钮。我尝试了一些东西,但时间结束了,但没有弹出窗口。任何想法?
时间类:工作正常。
公共课时间{
private String time;
private boolean isDone;
public Time() {
super();
isDone=false;
}
CountDownTimer count = new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
String tempSec=Integer.toString(seconds);
if (tempSec.length()==1){
tempSec="0"+tempSec;
}
time="Time Left: " + minutes + ":"+tempSec;
}
public void onFinish() {
setDone(true);
}
}.start();
这是活动类:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
club=new Club();
clubView = new ClubView(this, club);
mole=new Mole();
stageView=new StageView(this);
moleView=new MoleView(this,mole);
pointsView=new PointsView(this);
time=new Time();
timerView=new TimerView(this, time);
allViews=new AllViews(this);
allViews.setViews(stageView, moleView, pointsView, timerView,clubView);
setContentView(allViews);
allViews.setOnTouchListener((View.OnTouchListener)this);
if (timerView.getTime().isDone()){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Level Complete");
builder.setMessage("your score is"+pointsView.getPoint());
AlertDialog dialog = builder.create();
dialog.show();
}
}