我创建了一个简单的游戏,要求您在一定的转数内(例如10)猜测一个数字。但是,这使得很容易被击败。我需要帮助的是如何跟踪游戏进行的时间。创建一个定时应用程序
这是我至今想起来的(减去游戏逻辑),但它似乎并没有被你不使用开始时间被工作
Random ranNum = new Random();
double input; // The input
long startTime; // The time the game started
long curTime; // The time the game ended
double randNum = ranNum.nextInt(100);
while (curTime > 1000){
curTime = System.currentTimeMillis();
input = TextIO.getlnDouble();
if (input = Math.abs(randNum)){
System.out.println("You got the correct answer");
} // End if statement
else {
System.out.println("You did not have the correct answer");
System.out.println("The number was" + randNum + ".");
} // End else statement
} // End while statement
你在哪里初始化curTime? –