update Player class and Entity interface
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
public interface Entity {
|
||||||
void attack(Entity target);
|
void attack(Entity target, double multiplier);
|
||||||
|
|
||||||
void defend();
|
void defend();
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public interface Entity {
|
|||||||
|
|
||||||
int getMaxMP();
|
int getMaxMP();
|
||||||
|
|
||||||
/*
|
boolean isDefending();
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
void setDefending(boolean defending);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import org.project.entity.Entity;
|
|||||||
import org.project.item.armors.Armor;
|
import org.project.item.armors.Armor;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Player {
|
public abstract class Player implements Entity, combatOptions {
|
||||||
protected String name;
|
protected String name;
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
Armor armor;
|
Armor armor;
|
||||||
@@ -13,6 +13,8 @@ public abstract class Player {
|
|||||||
private int maxHP;
|
private int maxHP;
|
||||||
private int mp;
|
private int mp;
|
||||||
private int maxMP;
|
private int maxMP;
|
||||||
|
private boolean defending = false;
|
||||||
|
private double defendRate;
|
||||||
|
|
||||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -24,15 +26,37 @@ public abstract class Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack(Entity target) {
|
public void attack(Entity target,double multiplier) {
|
||||||
target.takeDamage(weapon.getDamage());
|
double finalDamage = multiplier * weapon.getDamage();
|
||||||
|
if (target.isDefending()) {
|
||||||
|
target.takeDamage((int) ( finalDamage * defendRate));
|
||||||
|
target.setDefending(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target.takeDamage((int) ( finalDamage ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lightAttack(Entity target){
|
||||||
|
attack(target,1);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target){
|
||||||
|
attack(target,2);
|
||||||
|
mp -= weapon.getManaCost();
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defend() {
|
public void defend() {
|
||||||
// TODO
|
setDefending(true);
|
||||||
|
mp -= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(){};
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
@@ -45,6 +69,8 @@ public abstract class Player {
|
|||||||
if (hp > maxHP) {
|
if (hp > maxHP) {
|
||||||
hp = maxHP;
|
hp = maxHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mp -= 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,4 +112,10 @@ public abstract class Player {
|
|||||||
return armor;
|
return armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefending() { return defending; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefending(boolean defending) { this.defending = defending; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user