在Java游戏中显示分数

时间:2013-04-16 18:09:53

标签: java swing joptionpane

我在java中制作迷宫游戏。我在游戏中添加了玩家,时间限制。现在我将在这个游戏中添加分数。我用这个代码来完成这个任务......

else if(win)
{
long end = System.currentTimeMillis();
long time=end-startTime;
JOptionPane.showMessageDialog(null, time);
//System.exit(0);
//g.drawImage(m.getWinn(), 32, 32, null);
//JOptionPane.showMessageDialog(this, "Winner");
}

这里JOptionPane连续显示时间。我怎样才能只显示一次或获胜的消息,如“你的分数:3450”

1 个答案:

答案 0 :(得分:1)

此代码:

long end = System.currentTimeMillis();
long time=end-startTime;
JOptionPane.showMessageDialog(null, time);

它自己将显示自游戏开始以来的时间(以毫秒为单位)。

  

我怎样才能只显示一次或获胜的消息,例如“你的分数:3450”

同样的原则适用。使用time的值,您只需调用

即可
JOptionPane.showMessageDialog(null, "Your score : " + time);
相关问题