简体   繁体   English

公式不适用于点击器游戏

[英]Formula doesn't work for clicker game

 const buydankMiner1 = () => {

  if (borkCoins >= dankMiner.cost) {
dankMiner.qt += 1;
borkCoins -= dankMiner.cost;
  dankMiner.cost = Math.floor(Math.pow(dankMiner.cost, 1.05) / 1.18); 
 displayScreen()
} else {
  alert("Insufficient funds!");
}
};

  const buydankMiner5 = () => {

  if (borkCoins >= dankMiner.cost * 5) {
dankMiner.qt += 5;
borkCoins -= dankMiner.cost * 5;
 dankMiner.cost = Math.floor(Math.pow(dankMiner.cost * 5, 1.05) / 1.18); 
 displayScreen();
} else {
  alert("Insufficient funds!");
}
};

The code above is from a clicker game I'm attempting to make. 上面的代码来自我尝试制作的点击游戏。 There are two buttons that either buy 1 "dankMiner" or five of it. 有两个按钮可以购买1个“ dankMiner”,也可以购买5个。 What I tried to do was increase the cost of a said "dankMiner" each time it is bought, hence the formula that first raises it to the power of 1.05 and divides it to 1.18. 我试图做的是每次购买所说的“ dankMiner”都会增加其成本,因此该公式首先将其提高至1.05的幂并将其除以1.18。 It works when I buy one "dankMiner," however when I do the option of buying five of it, the cost of it is not the same as when I click on the buy 1 option five times. 当我购买一个“ dankMiner”时,它可以工作,但是当我选择购买五个时,其成本与单击五次“购买1个”选项时的成本不同。

For example, clicking on the buy 1 option fifteen times results to the next one costing 77. However, clicking the buy 5 option three times results to the next one costing over 11,000. 例如,单击“购买1”选项15次将导致下一个成本为77。但是,单击“购买5”选项三次将导致下一个成本超过11,000。

These two are different 这两个是不同的

Math.pow(something * 5, 1.05) / 1.18
Math.pow(something, 1.05) * 5 / 1.18

and also doing five time Math.pow(something, 1.05)/1,18 each time on the result of the precedent one. 并根据先例的结果每次执行五次Math.pow(something, 1.05)/1,18 This latter is the one you need to implement for your purpose I think. 我认为后者是您需要实现的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM