update Player and Knight class
This commit is contained in:
@@ -1,6 +1,66 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Knight extends Player {
|
||||
|
||||
public Knight(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
super(name, hp, mp, weapon, armor);
|
||||
setDefendRate(.9);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
attack(target, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Entity target) {
|
||||
if (getMp() >= 8) {
|
||||
attack(target, 1.8);
|
||||
setMp(getMp() - 8);
|
||||
}
|
||||
else {
|
||||
System.out.println("Not enough MP");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
if (getMp() >= 4) {
|
||||
super.defend();
|
||||
setMp(getMp() - 4);
|
||||
}
|
||||
else {
|
||||
System.out.println("Not enough MP");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
if (getMp() >= 20) {
|
||||
attack(target, 2);
|
||||
setMp(getMp() - 20);
|
||||
//incomplete
|
||||
}
|
||||
else {
|
||||
System.out.println("Not enough MP");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
if (getMp() >= 5) {
|
||||
super.heal(health);
|
||||
setMp(getMp() - 5);
|
||||
}
|
||||
else {
|
||||
System.out.println("Not enough MP");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,36 +26,30 @@ public abstract class Player implements Entity, combatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target,double multiplier) {
|
||||
double finalDamage = multiplier * weapon.getDamage();
|
||||
public void attack(Entity target, double multiplier) {
|
||||
double damage = multiplier * weapon.getDamage();
|
||||
if (target.isDefending()) {
|
||||
target.takeDamage((int) ( finalDamage * defendRate));
|
||||
target.takeDamage( (int) (damage * (1 - getDefendRate())));
|
||||
target.setDefending(false);
|
||||
}
|
||||
else {
|
||||
target.takeDamage((int) ( finalDamage ));
|
||||
target.takeDamage((int) damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target){
|
||||
attack(target,1);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Entity target){
|
||||
attack(target,2);
|
||||
mp -= weapon.getManaCost();
|
||||
public abstract void lightAttack(Entity target);
|
||||
|
||||
@Override
|
||||
public abstract void heavyAttack(Entity target);
|
||||
|
||||
@Override
|
||||
public void defend(){
|
||||
setDefending(true);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
setDefending(true);
|
||||
mp -= 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(){};
|
||||
public abstract void specialAbility(Entity target);
|
||||
|
||||
|
||||
@Override
|
||||
@@ -69,8 +63,6 @@ public abstract class Player implements Entity, combatOptions {
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
|
||||
mp -= 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,6 +91,10 @@ public abstract class Player implements Entity, combatOptions {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public void setMp(int mp) {
|
||||
this.mp = mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
@@ -118,4 +114,8 @@ public abstract class Player implements Entity, combatOptions {
|
||||
@Override
|
||||
public void setDefending(boolean defending) { this.defending = defending; }
|
||||
|
||||
public double getDefendRate() { return defendRate; }
|
||||
|
||||
public void setDefendRate(double defendRate) { this.defendRate = defendRate; }
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ public interface combatOptions {
|
||||
void lightAttack(Entity target);
|
||||
void heavyAttack(Entity target);
|
||||
void defend();
|
||||
void heal();
|
||||
void specialAbility();
|
||||
void heal(int health);
|
||||
void specialAbility(Entity target);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.Item;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
|
||||
public abstract class Weapon implements Item {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user