gpt4 book ai didi

java - 不会更新值

转载 作者:行者123 更新时间:2023-12-02 05:10:42 24 4
gpt4 key购买 nike

我正在制作一个非常基本的自动“Cookie Clicker”程序,但我在这行代码中遇到了问题:

z = Math.ceil(15*java.lang.Math.pow(1.15, x));

当 x 在 if 语句中更新时,这行代码似乎不理解这一点,并且 z 继续使用 x 的初始化值(即 0)并保持为 15 (15*1.15^0)。

有人知道该怎么做吗?

public class Tryout {

public static void main(String[] args) {
// TODO Auto-generated method stub
double x = 0; //Number of Cookie Clickers
double z; // Cost of the Cookie Clickers
double cookies = 0; //Amount of Cookies
double count = 0; //Additional amount of cookies per second from the Cookie Clickers
final double constant = 0.1; //Amount of CPS (cookies per second) you get from 1 Cookie Clicker
z = Math.ceil(15*java.lang.Math.pow(1.15, x)); //with 0 CC the cost is 15, with 1 CC the cost is 18, with 2 CC...
while (1>0) { // the game loop, (infinity loop)
if(cookies >= z) { //If you got enough cookies you autobuy a new CC and the number of CC's increase as well as the cost of a CC
System.out.println("cookies" + cookies); //Amount of cookies before you buy
System.out.println("You bought a new Cookie Clicker; +0.1 cookie each second!");
System.out.println(cookies + " - " + z + " = " + (cookies - z));
cookies = cookies - z;
x++;
}


try { //delayer (Uptades 1 time per second)
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}

count = x*constant;
cookies = cookies + 1 + count;
Math.round(cookies);
System.out.println("cookies; " + cookies); // Your current amount of cookies
}
}
}

最佳答案

该行代码只执行一次。将其移至循环内,以便每次 x 更改时重新评估 z。

关于java - 不会更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27362475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com