apply the item hierarchy
This commit is contained in:
@@ -1,6 +1,30 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
import org.project.item.Accessory.Custom;
|
||||||
|
import org.project.item.Accessory.Shield;
|
||||||
|
import org.project.item.Accessory.Weapon;
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public abstract class Entity {
|
||||||
|
|
||||||
|
public int MaxHealth;
|
||||||
|
public long Money;
|
||||||
|
private int BaseDamage;
|
||||||
|
public Weapon Weapon;
|
||||||
|
public Shield Shield;
|
||||||
|
public Costume Costume;
|
||||||
|
public ArrayList<Item> Inventory;
|
||||||
|
|
||||||
|
public int getBaseDamage() {
|
||||||
|
return BaseDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBaseDamage(int baseDamage) {
|
||||||
|
BaseDamage = baseDamage;
|
||||||
|
}
|
||||||
|
|
||||||
void attack(Entity target);
|
void attack(Entity target);
|
||||||
|
|
||||||
void defend();
|
void defend();
|
||||||
@@ -15,6 +39,10 @@ public interface Entity {
|
|||||||
|
|
||||||
int getMaxMP();
|
int getMaxMP();
|
||||||
|
|
||||||
|
public void She() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.project.item.Accessory;
|
||||||
|
|
||||||
|
import org.project.Interface.IAttachable;
|
||||||
|
import org.project.Interface.IDamageable;
|
||||||
|
import org.project.constants.gameConstant.AttackPowerUp;
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.SellableItem;
|
||||||
|
|
||||||
|
public abstract class Accessory extends SellableItem implements IDamageable, IAttachable {
|
||||||
|
private int Health;
|
||||||
|
private final int MaxHealth;
|
||||||
|
|
||||||
|
public Accessory (String name, Entity owner, int price, int health, int maxHealth) {
|
||||||
|
super(name, owner, price);
|
||||||
|
this.Health = health;
|
||||||
|
this.MaxHealth = maxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHealth() {
|
||||||
|
return Health;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetMaxHealth() { return MaxHealth; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetPrice() {
|
||||||
|
int basePrice = super.GetPrice();
|
||||||
|
|
||||||
|
return basePrice * (Health/MaxHealth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void TakeDamage(int amount, AttackPowerUp[] powerUps) {
|
||||||
|
Health -= amount;
|
||||||
|
|
||||||
|
if (IsDestroyed()) {
|
||||||
|
HandleZeroHealth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean IsDestroyed() {
|
||||||
|
return Health < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void HandleZeroHealth() {
|
||||||
|
this.DeattachFrom(this.Owner);
|
||||||
|
this.Owner.Inventory.remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void AttachTo(Entity entity);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void DeattachFrom(Entity entity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.project.item.Accessory;
|
||||||
|
|
||||||
|
import org.project.Interface.IDefender;
|
||||||
|
import org.project.constants.gameConstant.AttackPowerUp;
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Costume extends Accessory implements IDefender {
|
||||||
|
private final int Defense;
|
||||||
|
|
||||||
|
public Costume(String name, Entity owner, int price, int health, int maxHealth, int defense) {
|
||||||
|
super(name, owner, price, health, maxHealth);
|
||||||
|
this.Defense = defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetDefense() {
|
||||||
|
return Defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int Apply(int damage, AttackPowerUp[] powerUps) {
|
||||||
|
if (Arrays.binarySearch(powerUps, AttackPowerUp.ANTI_CUSTOM) < 0) {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damage <= Defense) {
|
||||||
|
this.TakeDamage(damage, null);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.TakeDamage(Defense, null);
|
||||||
|
return damage - Defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void AttachTo(Entity entity) {
|
||||||
|
entity.Inventory.remove(this);
|
||||||
|
entity.Costume = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DeattachFrom(Entity entity) {
|
||||||
|
entity.Costume = null;
|
||||||
|
entity.Inventory.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.project.item.Accessory;
|
||||||
|
|
||||||
|
import org.project.Interface.IDefender;
|
||||||
|
import org.project.constants.gameConstant.AttackPowerUp;
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Shield extends Accessory implements IDefender {
|
||||||
|
private final int Defense;
|
||||||
|
|
||||||
|
public Shield (String name, Entity owner, int price, int health, int maxHealth, int defense) {
|
||||||
|
super(name, owner, price, health, maxHealth);
|
||||||
|
this.Defense = defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetDefense() {
|
||||||
|
return Defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int Apply(int damage, AttackPowerUp[] powerUps) {
|
||||||
|
if (Arrays.binarySearch(powerUps, AttackPowerUp.ANTI_SHIELD) < 0) {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damage <= Defense) {
|
||||||
|
this.TakeDamage(damage, null);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.TakeDamage(Defense, null);
|
||||||
|
return damage - Defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void AttachTo(Entity entity) {
|
||||||
|
entity.Inventory.remove(this);
|
||||||
|
entity.Shield = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DeattachFrom(Entity entity) {
|
||||||
|
entity.Shield = null;
|
||||||
|
entity.Inventory.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.project.item.Accessory;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public class Weapon extends Accessory {
|
||||||
|
private final int Damage;
|
||||||
|
|
||||||
|
public Weapon (String name, Entity owner, int price, int health, int maxHealth, int damage) {
|
||||||
|
super(name, owner, price, health, maxHealth);
|
||||||
|
this.Damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetDamage() {
|
||||||
|
return Damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void AttachTo(Entity entity) {
|
||||||
|
entity.Inventory.remove(this);
|
||||||
|
entity.Weapon = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DeattachFrom(Entity entity) {
|
||||||
|
entity.Weapon = null;
|
||||||
|
entity.Inventory.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,16 @@ package org.project.item;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
public interface Item {
|
public abstract class Item {
|
||||||
void use(Entity target);
|
private final String Name;
|
||||||
|
public Entity Owner;
|
||||||
|
|
||||||
/*
|
public Item (String name, Entity owner) {
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
this.Name = name;
|
||||||
*/
|
this.Owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.project.item;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public class KeyItem extends Item {
|
||||||
|
public KeyItem (String name, Entity owner) {
|
||||||
|
super(name, owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.project.item;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public class SellableItem extends Item{
|
||||||
|
private final int Price;
|
||||||
|
|
||||||
|
public SellableItem (String name, Entity owner, int price) {
|
||||||
|
super(name, owner);
|
||||||
|
this.Price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetPrice() {
|
||||||
|
return Price;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package org.project.item.armors;
|
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Armor {
|
|
||||||
private int defense;
|
|
||||||
private int maxDefense;
|
|
||||||
private int durability;
|
|
||||||
private int maxDurability;
|
|
||||||
|
|
||||||
private boolean isBroke;
|
|
||||||
|
|
||||||
public Armor(int defense, int durability) {
|
|
||||||
this.defense = defense;
|
|
||||||
this.durability = durability;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkBreak() {
|
|
||||||
if (durability <= 0) {
|
|
||||||
isBroke = true;
|
|
||||||
defense = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
|
||||||
public void repair() {
|
|
||||||
isBroke = false;
|
|
||||||
defense = maxDefense;
|
|
||||||
durability = maxDurability;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDefense() {
|
|
||||||
return defense;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDurability() {
|
|
||||||
return durability;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBroke() {
|
|
||||||
return isBroke;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package org.project.item.armors;
|
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class KnightArmor {
|
|
||||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package org.project.item.consumables;
|
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Consumable {
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package org.project.item.consumables;
|
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class Flask {
|
|
||||||
/*
|
|
||||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: UPDATE USE METHOD
|
|
||||||
@Override
|
|
||||||
public void use(Entity target) {
|
|
||||||
target.heal(target.getMaxHP() / 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package org.project.item.weapons;
|
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class Sword {
|
|
||||||
/*
|
|
||||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int abilityCharge;
|
|
||||||
|
|
||||||
public Sword() {
|
|
||||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
|
||||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
|
||||||
abilityCharge += 2;
|
|
||||||
for (Entity target : targets) {
|
|
||||||
target.takeDamage(getDamage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package org.project.item.weapons;
|
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Weapon {
|
|
||||||
private int damage;
|
|
||||||
private int manaCost;
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
|
||||||
*/
|
|
||||||
|
|
||||||
public Weapon(int damage, int manaCost) {
|
|
||||||
this.damage = damage;
|
|
||||||
this.manaCost = manaCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void use(Entity target) {
|
|
||||||
target.takeDamage(damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDamage() {
|
|
||||||
return damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getManaCost() {
|
|
||||||
return manaCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user