0

特定のターン数 (例: 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
4

2 に答える 2

0

startTime を使用していませんか?

long startTime = System.currentTimeMillis();

currTime = System.currentTimeMillis() - startTime

これで、currTime にはミリ秒単位の時間差が含まれます。

于 2013-10-06T18:32:28.000 に答える