develop #1
@@ -1,6 +1,7 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Dragon;
|
||||
import org.project.entity.enemies.Goblin;
|
||||
import org.project.entity.enemies.Skeleton;
|
||||
import org.project.item.armors.Armor;
|
||||
@@ -26,6 +27,10 @@ public abstract class Player implements Entity, CombatOptions {
|
||||
private boolean hasVampireKey = false;
|
||||
private boolean successfulAction = true;
|
||||
private Consumable flask;
|
||||
private int level = 1;
|
||||
private int xp = 0;
|
||||
private static final int BASE_XP = 50;
|
||||
private static final double XP_SCALE = 1.4;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
this.name = name;
|
||||
@@ -216,4 +221,40 @@ public abstract class Player implements Entity, CombatOptions {
|
||||
return flask;
|
||||
}
|
||||
|
||||
public int xpToNextLevel() {
|
||||
return (int) (BASE_XP * Math.pow(XP_SCALE, level - 1));
|
||||
}
|
||||
|
||||
private void levelUp() {
|
||||
level++;
|
||||
maxHP += 10;
|
||||
maxMP += 8;
|
||||
setHP(getHP() + 10); // heal by the amount gained
|
||||
setMP(getMP() + 8);
|
||||
System.out.println("★ LEVEL UP! " + getClass().getSimpleName()
|
||||
+ " is now level " + level
|
||||
+ " | Max HP +" + 10 + " | Max MP +" + 8);
|
||||
}
|
||||
|
||||
public void gainXP(int amount) {
|
||||
xp += amount;
|
||||
System.out.println(getClass().getSimpleName() + " gained " + amount + " XP! ("
|
||||
+ xp + "/" + xpToNextLevel() + ")");
|
||||
while (xp >= xpToNextLevel()) {
|
||||
xp -= xpToNextLevel();
|
||||
levelUp();
|
||||
}
|
||||
}
|
||||
|
||||
public static int xpRewardFor(Entity enemy) {
|
||||
if (enemy instanceof Dragon) return 300;
|
||||
if (enemy instanceof Goblin) return 40;
|
||||
if (enemy instanceof Skeleton) return 50;
|
||||
return 60;
|
||||
}
|
||||
|
||||
public int getLevel() { return level; }
|
||||
|
||||
public int getXP() { return xp; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user