for class I've been tasked with making a text based adventure game. Recently, I've been trying to program in battling and exp in the game. Here is what I am using to calculate it in the Player class:
int level = 1;
int exp = 0;
int close;
public void levelup() {
level += 1;
}
public int nextlevel() {
int x = level;
close = (4 * (x ^ 3) / 5);
return close;
}
public boolean levelready() {
return exp >= nextlevel();
}
Here is the calculations from the BattleManager class:
public void battleend() {
player.exp += expgain;
if (player.levelready()) {
print("You leveled up!");
player.levelup();
}
}
Now, the difficulty I'm having is that the nextlevel() method doesn't seem to always return the amount of exp required for the next level, it just returns 0. In the Room class I have a method that prints your stats to the screen.
The code is something like:
public void printstats() {
print("Level " + player.level);
print("EXP " + player.exp);
print("Next Level " + player.nextlevel());
}
Here is what's printed out before the battle:
Level 1
EXP 0
Next Level 1
Here is what's printed out after the battle:
Level 2
EXP 1
Next Level 0
Can somebody please help me with this? I would really appreciate it. Thank you!