42 lines
899 B
Java
42 lines
899 B
Java
package letzplay.core;
|
|
|
|
public class LevelSystem {
|
|
private int currentLvl;
|
|
private float experience;
|
|
|
|
private LevelSystem(int currentLvl, float experience) {
|
|
this.currentLvl = currentLvl;
|
|
this.experience = experience;
|
|
}
|
|
|
|
public static LevelSystem getInstance() {
|
|
return new LevelSystem(0, 0);
|
|
}
|
|
|
|
private void lvlUp() {
|
|
currentLvl++;
|
|
}
|
|
|
|
public void addExperience(float exp) {
|
|
experience += exp;
|
|
if (experience >= 100) {
|
|
lvlUp();
|
|
experience = experience % 100;
|
|
}
|
|
}
|
|
|
|
public int currentLvl() {
|
|
return currentLvl;
|
|
}
|
|
|
|
public float currentExperience() {
|
|
return experience;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Current Level: " + currentLvl + "\n" + "Experience to next " +
|
|
"Level: " + experience + "%";
|
|
}
|
|
}
|