implement new armors
This commit is contained in:
@@ -22,9 +22,9 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Weapon wp = new Sword();
|
Weapon wp = new Sword();
|
||||||
ArrayList<Player> players = new ArrayList<>();
|
ArrayList<Player> players = new ArrayList<>();
|
||||||
players.add(new Assassin(new KnightArmor(8, 1)));
|
players.add(new Assassin());
|
||||||
players.add(new Knight());
|
players.add(new Knight());
|
||||||
players.add(new Wizard(new KnightArmor(2,1)));
|
players.add(new Wizard());
|
||||||
ArrayList<Enemy> enemies = new ArrayList<>();
|
ArrayList<Enemy> enemies = new ArrayList<>();
|
||||||
enemies.add(new Goblin(80, 100, wp));
|
enemies.add(new Goblin(80, 100, wp));
|
||||||
enemies.add(new Skeleton(70, 100, wp));
|
enemies.add(new Skeleton(70, 100, wp));
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ public interface Entity {
|
|||||||
|
|
||||||
void takeDamage(int damage);
|
void takeDamage(int damage);
|
||||||
|
|
||||||
|
void takeDamage(int damage, Entity target);
|
||||||
|
|
||||||
int getHP();
|
int getHP();
|
||||||
|
|
||||||
void setHP(int hp);
|
void setHP(int hp);
|
||||||
|
|||||||
@@ -34,16 +34,18 @@ public abstract class Enemy implements Entity {
|
|||||||
System.out.println(this.getClass().getSimpleName() + ": attacking " + target.getClass().getSimpleName());
|
System.out.println(this.getClass().getSimpleName() + ": attacking " + target.getClass().getSimpleName());
|
||||||
double damage = getAttackMultiplier() * weapon.getDamage();
|
double damage = getAttackMultiplier() * weapon.getDamage();
|
||||||
if (target.isDefending()) {
|
if (target.isDefending()) {
|
||||||
target.takeDamage((int) (damage * (1 - target.getDefendRate())));
|
target.takeDamage((int) (damage * (1 - target.getDefendRate())),this);
|
||||||
target.setDefending(false);
|
target.setDefending(false);
|
||||||
} else {
|
} else {
|
||||||
target.takeDamage((int) damage);
|
target.takeDamage((int) damage);
|
||||||
}
|
}
|
||||||
setMP(getMP() - weapon.getManaCost());
|
setMP(getMP() - weapon.getManaCost());
|
||||||
}
|
}
|
||||||
else System.out.println("not enough mana");
|
else {
|
||||||
|
System.out.println("not enough mana");
|
||||||
setSuccessful(false);
|
setSuccessful(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defend(){
|
public void defend(){
|
||||||
@@ -72,6 +74,11 @@ public abstract class Enemy implements Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage, Entity target) {
|
||||||
|
this.takeDamage(damage);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHP() {
|
public int getHP() {
|
||||||
return hp;
|
return hp;
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ package org.project.entity.players;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.armors.Armor;
|
import org.project.item.armors.Armor;
|
||||||
|
import org.project.item.armors.AssassinArmor;
|
||||||
import org.project.item.weapons.Dagger;
|
import org.project.item.weapons.Dagger;
|
||||||
import org.project.item.weapons.Sword;
|
import org.project.item.weapons.Sword;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public class Assassin extends Player {
|
public class Assassin extends Player {
|
||||||
|
|
||||||
public Assassin(Armor armor) {
|
public Assassin() {
|
||||||
super("ASSASSIN",100,100, new Dagger(), armor);
|
super("ASSASSIN",100,100, new Dagger(), new AssassinArmor());
|
||||||
setDefendRate(.7);
|
setDefendRate(.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +90,11 @@ public class Assassin extends Player {
|
|||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
if (getUsingSpecialAbility()) {
|
if (getUsingSpecialAbility()) {
|
||||||
System.out.println("player using special ability");
|
System.out.println("player using special ability");
|
||||||
|
} else {
|
||||||
|
damage = ((AssassinArmor) (getArmor())).reduceDamage(damage, this);
|
||||||
|
super.takeDamage(damage);
|
||||||
|
|
||||||
}
|
}
|
||||||
else super.takeDamage(damage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.project.item.weapons.Weapon;
|
|||||||
public class Knight extends Player {
|
public class Knight extends Player {
|
||||||
|
|
||||||
public Knight() {
|
public Knight() {
|
||||||
super("Knight",100,90, new Sword(), new KnightArmor(10,1));
|
super("Knight",100,90, new Sword(), new KnightArmor());
|
||||||
setDefendRate(.9);
|
setDefendRate(.9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,5 +81,14 @@ public class Knight extends Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void takeDamage(int damage, Entity attacker) {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
if (!getArmor().checkBrake()) {
|
||||||
|
int reflected = ((KnightArmor) armor).getReflectedDamage(damage);
|
||||||
|
attacker.takeDamage(reflected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,11 @@ public abstract class Player implements Entity, combatOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage, Entity target) {
|
||||||
|
this.takeDamage(damage);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void heal(int health) {
|
public void heal(int health) {
|
||||||
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
|
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package org.project.entity.players;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.armors.Armor;
|
import org.project.item.armors.Armor;
|
||||||
|
import org.project.item.armors.KnightArmor;
|
||||||
|
import org.project.item.armors.WizardArmor;
|
||||||
import org.project.item.weapons.Bow;
|
import org.project.item.weapons.Bow;
|
||||||
import org.project.item.weapons.Sword;
|
import org.project.item.weapons.Sword;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public class Wizard extends Player{
|
public class Wizard extends Player{
|
||||||
|
|
||||||
public Wizard(Armor armor) {
|
public Wizard() {
|
||||||
super("Wizard",90,90,new Bow(),armor);
|
super("Wizard",90,90,new Bow(),new WizardArmor());
|
||||||
setDefendRate(.6);
|
setDefendRate(.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,4 +81,15 @@ public class Wizard extends Player{
|
|||||||
setSuccessful(false);
|
setSuccessful(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage) {
|
||||||
|
if (!getArmor().checkBrake()) {
|
||||||
|
int finalDamage = ((WizardArmor) armor).absorbDamage(damage, getMP());
|
||||||
|
super.takeDamage(finalDamage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,27 +5,17 @@ import org.project.item.Item;
|
|||||||
public abstract class Armor implements Item {
|
public abstract class Armor implements Item {
|
||||||
private int defense;
|
private int defense;
|
||||||
private int maxDefense;
|
private int maxDefense;
|
||||||
private int durability;
|
|
||||||
private int maxDurability;
|
|
||||||
|
|
||||||
|
|
||||||
public Armor(int defense, int durability) {
|
public Armor(int defense) {
|
||||||
this.defense = defense;
|
this.defense = defense;
|
||||||
this.maxDefense = defense;
|
this.maxDefense = defense;
|
||||||
this.durability = durability;
|
|
||||||
this.maxDurability = durability;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkBreak() {
|
|
||||||
if (durability <= 0) {
|
|
||||||
defense = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
|
||||||
public void repair() {
|
public void repair() {
|
||||||
defense = maxDefense;
|
defense = maxDefense;
|
||||||
durability = maxDurability;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefense() {
|
public int getDefense() {
|
||||||
@@ -36,8 +26,19 @@ public abstract class Armor implements Item {
|
|||||||
this.defense = defense;
|
this.defense = defense;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDurability() {
|
|
||||||
return durability;
|
public boolean checkBrake() {
|
||||||
|
return defense <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use() {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " equipped");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.project.item.armors;
|
||||||
|
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import org.project.item.armors.Armor;
|
||||||
|
|
||||||
|
public class AssassinArmor extends Armor {
|
||||||
|
|
||||||
|
private int HPPercentDamageReduction;
|
||||||
|
|
||||||
|
public AssassinArmor() {
|
||||||
|
super(15);
|
||||||
|
this.HPPercentDamageReduction = 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isLowHP(Player player) {
|
||||||
|
return (player.getHP() * 100 / player.getMaxHP()) < HPPercentDamageReduction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int reduceDamage(int damage, Player player) {
|
||||||
|
if (isLowHP(player)) {
|
||||||
|
return damage / 2;
|
||||||
|
}
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class KnightArmor extends Armor{
|
public class KnightArmor extends Armor{
|
||||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
private int reflectPercent;
|
||||||
public KnightArmor(int defense, int durability) {
|
public KnightArmor() {
|
||||||
super(defense, durability);
|
super(10);
|
||||||
|
this.reflectPercent = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReflectedDamage(int damage) {
|
||||||
|
return (int) (damage * reflectPercent / 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.project.item.armors;
|
||||||
|
|
||||||
|
public class WizardArmor extends Armor {
|
||||||
|
|
||||||
|
public WizardArmor() {
|
||||||
|
super(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int absorbDamage(int damage, int mp) {
|
||||||
|
int reduction = mp / 10; // every 10 MP absorbs 1 damage
|
||||||
|
return Math.max(0, damage - reduction);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user