等级计算

Level calculation

我怎么想不出一个实际上很简单的问题的解决方案。 是关于关卡系统的,我需要一种很简单但想不出来的公式

我根据经验值计算等级,你需要例如1 级 1.000 EXP,2 级 3.000 EXP,3 级 6.000 EXP 等等。

希望可以理解。

唯一的问题是它不会持续上升。 因此,对于 2 级,例如,3,000 EXP 是由于您在 1 级已经有 1,000 EXP,然后添加 2,000 EXP(2 级)。在第 3 级是 6,000,因为第 1 级有 1,000,第 2 级有 2,000,然后第 3 级有 3,000。

再进一步的话,比如5级需要5000 EXP,刚好从4级升到5级,而在此之前你还有其他等级的其他EXP。也就是说你升到5级总共需要15,000 EXP

这是一个列表,其中包含级别和所需的 EXP:

Level 2 -> 3.000
Level 3 -> 6.000
Level 4 -> 10.000
Level 5 -> 15.000
Level 6 -> 21.000
...
Level 10 -> 55.000
int xp=500;

//list of xp land marks to level up[adjust them to your needs]
int[] checkPoints=
{
  0,2000,3000,6000
 ,10000,15000,21000,
 ,25000,30000,35000
 ,40000,45000,50000
 ,55000
};

int level=0;
for(int i=0;i<checkPoints.length-1;i++)
{
 /*
  if xp lies with this range then level=i
  example xp=11000 lies between 10000[i=4] && 15000[i=5]
  so level=4
 */
 if(xp>=checkPoints[i] && xp<=checkPoints[i+1])
 {
   level=i;
 }
}

System.out.println("You are level="+level);