所以我有这个:
if (bought.count == bought.needForUpgrade)
{
bought.timeToComplete /= 2;
bought.needForUpgrade += 25;
}
这很好,但是我做了一个购买功能,所以你可以买1,10,25的物品。我想减少其计数通过的每25个数字的bought.timeToComeplete by 2
,所以例如我有1来自那个项目,然后我决定购买25,然后我会有26个。我可以用很多if statements
来做,但我不想整天写if(bought.count >= 25 && bought.count <= 50)
..等等p>
答案 0 :(得分:1)
只需添加一个额外的值即可保存已升级的频率,并检查您是否获得了下一个&#34;级别&#34;。
对于此解决方案,我假设bought.count
和bought.needForUpgrade
的类型为整数:
int boughtLevel = 0;
if (bought.count / bought.needForUpgrade > boughtLevel)
{
// Do your stuff here
boughtLevel = bought.count / bought.needForUpgrade;
}
否则你必须在分裂之前施放它们:
int boughtLevel = 0;
if ((int)(bought.count / bought.needForUpgrade) > boughtLevel)
{
// Do your stuff here
boughtLevel = (int)(bought.count / bought.needForUpgrade); // Not necessary because boughtLevel is of type integer
}