【发布时间】:2017-05-09 16:41:53
【问题描述】:
我正在尝试制作答题器游戏,我希望机器人价格像 cookie 答题器游戏一样成倍增长。我尝试使用 cookie clicker 的价格计算公式 (http://cookieclicker.wikia.com/wiki/Building)。
if (cookies >= robotPrice) {
cookies -= robotPrice;
cps ++;
//Here is the algorithm
robotPrice = 100 * (int)Math.pow(1.15, cps);
System.out.println("robotPrice set to " + robotPrice);
}
但是当我运行程序时,我得到以下输出:
robotPrice set to 100
robotPrice set to 100
robotPrice set to 100
robotPrice set to 100
robotPrice set to 200
robotPrice set to 200
robotPrice set to 200
robotPrice set to 300
robotPrice set to 300
等等。 请帮忙。
【问题讨论】:
-
这个 "(int)Math.pow(1.15, cps)" 给你一个,这就是为什么
-
你可能想要
(int) (100 * Math.pow(1.15, cps))。 -
不知何故cps值在0到4之间,调试你的代码
-
显示有循环的代码。这个 sn-p 只有
If条件。我很确定cps在这里被重置为1,否则代码中没有错误。甚至类型转换也不是问题。