如何为android游戏添加java记分系统
我有一个游戏,它有一个开始/停止按钮。游戏的目的是看你是否能在头脑中数到10。当您按下开始按钮时,(不可见)计时器开始,当您按下停止按钮时,它应停止计时器并在页面上显示您的分数。距离10秒越近,得分越高。 我想知道我如何实现一个评分系统,因为它是基于时间的,我不知道如何将它转换成整数?下面是使其运行的代码如何为android游戏添加java记分系统,java,android,timer,Java,Android,Timer,我有一个游戏,它有一个开始/停止按钮。游戏的目的是看你是否能在头脑中数到10。当您按下开始按钮时,(不可见)计时器开始,当您按下停止按钮时,它应停止计时器并在页面上显示您的分数。距离10秒越近,得分越高。 我想知道我如何实现一个评分系统,因为它是基于时间的,我不知道如何将它转换成整数?下面是使其运行的代码 private Runnable updateTimerThread = new Runnable() { public void run() { timeInM
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
timerValue.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));
customHandler.postDelayed(this, 0);
}
};
您可以实现一个评分系统,用户在10秒的点击时间内最多可以得到10000分,随着时间差的增大,分数会变小
long clickTime = System.currentTimeMillis() - startTime; //time between start and stop clicks
long timeDifference = Math.abs(10000L - clickTime); //absolute time difference between 10 second and the users clicks
int score = 10000; //set maximum score
score = score - (int) clickTime; //subtract the time difference from the score to get actual score
您应该记住使用System.currentTimeMillis()
查找开始时间。如果用户单击时间超过20秒,此方法将给出一个负值,因此如果愿意,您可以添加另一条语句将其重置为0