Say I have an array with the require xp for each level so for instance
0 == Level 1
83 == Level 2
174 == Level 3
276 == Level 4
388 == Level 5
512 == Level 6
650 == Level 7
801 == Level 8
969 == Level 9
...
What's the most efficient way to increment an int to the corresponding level?
So I'd have an int like this
ìnt currentLevel = 1;
and then then say I added 25 xp, that would still put me at level 1, but then I added 800 xp which would set me at 825xp which then would put me at level 8
This was my solution but it keeps running at 98 and won't stop since it never levels up to 99. Not sure how to fix it.
internal class Program
{
private const int XPGain = 500;
static int currentLevel = 1;
static int currentXP = 0;
static void Main(string[] args)
{
string[] levels = File.ReadAllLines("XPTable.txt");
while (currentLevel < 99)
{
currentXP += XPGain;
for (int i = currentLevel; i < levels.Length; i++)
{
if (currentXP >= Convert.ToInt32(levels[i]))
{
//Set appropriate level
for (int l = 1; l < levels.Length + 1; l++)
{
if (currentXP <= Convert.ToInt32(levels[l - 1]))
{
currentLevel = l - 1;
Console.WriteLine("Level up!");
break;
}
}
break;
}
}
Console.WriteLine($"[Action] - Current Level: {currentLevel}. Added XP: {XPGain} - Current XP: {currentXP}");
}
}
}
Here's the XP table I'm using. https://www.klgrth.io/paste/g79ht