+ Finished Player & Enemy
+ Implemented specialAbility for every Entity
This commit is contained in:
@@ -1,32 +1,42 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
public abstract class Entity {
|
||||||
// void attack(Entity target);
|
|
||||||
|
|
||||||
|
void takeDamage(int damage){};
|
||||||
|
|
||||||
void defend();
|
void specialAbility(Entity target){};
|
||||||
|
|
||||||
void heal(int health);
|
void stun(){};
|
||||||
|
|
||||||
void fillMana(int mana);
|
public abstract void stun(boolean value);
|
||||||
|
|
||||||
void takeDamage(int damage);
|
void makeCritical(boolean value){};
|
||||||
|
|
||||||
void specialAbility(Entity target);
|
boolean isStunned(){};
|
||||||
|
|
||||||
void stun();
|
public abstract void setHp(int newHp);
|
||||||
|
|
||||||
int getMaxHP();
|
boolean isCritical(){};
|
||||||
|
|
||||||
int getMaxMP();
|
public abstract boolean isCritical();
|
||||||
|
|
||||||
boolean isStunned();
|
public abstract boolean isStunned();
|
||||||
|
|
||||||
void stun(boolean value);
|
boolean isDead(){};
|
||||||
|
|
||||||
|
public abstract void makeCritical(boolean value);
|
||||||
|
|
||||||
|
void makeDie(){};
|
||||||
|
|
||||||
/*
|
public abstract void makeDie();
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
void setHp(int hp){};
|
||||||
|
|
||||||
|
public abstract void takeDamage(int damage);
|
||||||
|
|
||||||
|
void stun(boolean value){};
|
||||||
|
|
||||||
|
public abstract boolean isDead();
|
||||||
|
|
||||||
|
public abstract boolean isDead();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,22 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public class Dragon extends Enemy{
|
public class Dragon extends Enemy{
|
||||||
|
|
||||||
|
public Dragon(int hp, Weapon weapon){
|
||||||
|
super(hp, weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
Player targetPlayer = (Player)target;
|
||||||
|
if (targetPlayer.isDefending()){
|
||||||
|
targetPlayer.breakShield();
|
||||||
|
}
|
||||||
|
|
||||||
|
super.attack(targetPlayer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,30 @@ package org.project.entity.enemies;
|
|||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Enemy implements Entity {
|
public abstract class Enemy implements Entity {
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
private int hp;
|
private int hp;
|
||||||
private int mp;
|
|
||||||
private boolean stunned = false;
|
private boolean stunned = false;
|
||||||
|
private boolean critical = false;
|
||||||
|
private boolean dead = false;
|
||||||
|
|
||||||
public Enemy(int hp, int mp, Weapon weapon) {
|
private static final double DAMAGE_MODIFIER = 1.5; // Used for critical hits
|
||||||
|
|
||||||
|
public Enemy(int hp, Weapon weapon) {
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
this.mp = mp;
|
|
||||||
|
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void attack(Entity target){
|
||||||
|
if (critical){
|
||||||
|
target.takeDamage((int)(weapon.getDamage() * DAMAGE_MODIFIER));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target.takeDamage(weapon.getDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
hp -= damage;
|
hp -= damage;
|
||||||
@@ -27,20 +37,41 @@ public abstract class Enemy implements Entity {
|
|||||||
stunned = value;
|
stunned = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void makeCritical(boolean value) {
|
||||||
|
critical = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void makeDie() {
|
||||||
|
dead = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHp(int newHp) {
|
||||||
|
hp = newHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCritical(){ return critical;}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isStunned() {
|
public boolean isStunned() {
|
||||||
return stunned;
|
return stunned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDead() {
|
||||||
|
return dead;
|
||||||
|
}
|
||||||
|
|
||||||
public int getHp() {
|
public int getHp() {
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
|
||||||
return mp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Weapon getWeapon() {
|
public Weapon getWeapon() {
|
||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void specialAbility(Entity target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,33 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public class Goblin extends Enemy{
|
public class Goblin extends Enemy{
|
||||||
|
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private static final int HEALTH_POINT = 100;
|
||||||
|
|
||||||
|
public Goblin(int mp, Weapon weapon){
|
||||||
|
super(HEALTH_POINT, weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
this.criticality();
|
||||||
|
super.attack(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
// makes the next move critical with a probability of 80
|
||||||
|
private void criticality(){
|
||||||
|
int randNum = random.nextInt(100);
|
||||||
|
if (randNum < 80){
|
||||||
|
this.makeCritical(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,25 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.weapons.Weapon;
|
||||||
public class Skeleton {
|
|
||||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
public class Skeleton extends Enemy {
|
||||||
|
|
||||||
|
private int deathCounter = 0;
|
||||||
|
private int initialHp;
|
||||||
|
|
||||||
|
public Skeleton(int hp, Weapon weapon){
|
||||||
|
super(hp,weapon);
|
||||||
|
initialHp = hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void makeDie() {
|
||||||
|
if (deathCounter == 0){
|
||||||
|
this.setHp(initialHp / 2);
|
||||||
|
deathCounter++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.makeDie();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public class Vampire extends Enemy{
|
public class Vampire extends Enemy{
|
||||||
|
|
||||||
|
private static final int SPECIAL_ABL_DMG = 40;
|
||||||
|
private static final int RANDEMANT_PERCENT = 70; // this constant determines how much of dealt damage should be given to vamp.
|
||||||
|
|
||||||
|
public Vampire(int hp, Weapon weapon){
|
||||||
|
super(hp, weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
System.out.println("Stealing life!...");
|
||||||
|
target.takeDamage(SPECIAL_ABL_DMG);
|
||||||
|
this.heal((SPECIAL_ABL_DMG * RANDEMANT_PERCENT) / 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public class Knight extends Player {
|
|||||||
@Override
|
@Override
|
||||||
public void specialAbility(Entity target) {
|
public void specialAbility(Entity target) {
|
||||||
System.out.println("Performing shield bash...");
|
System.out.println("Performing shield bash...");
|
||||||
|
|
||||||
|
|
||||||
target.stun(true);
|
target.stun(true);
|
||||||
target.takeDamage(50);
|
target.takeDamage(50);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ 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 implements Entity {
|
public abstract class Player implements Entity {
|
||||||
protected String name;
|
protected String name;
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
@@ -14,7 +13,14 @@ public abstract class Player implements Entity {
|
|||||||
private int mp;
|
private int mp;
|
||||||
private int maxMP;
|
private int maxMP;
|
||||||
private boolean isDefending = false;
|
private boolean isDefending = false;
|
||||||
private boolean stunned;
|
private boolean stunned = false;
|
||||||
|
private boolean critical = false;
|
||||||
|
private boolean dead = false;
|
||||||
|
|
||||||
|
private static final double DAMAGE_MODIFIER = 1.5; // Used for critical hits
|
||||||
|
private static final int LIGHT_ATTACK_DAMAGE = 10;
|
||||||
|
private static final int DEFEND_MP_COST = 5;
|
||||||
|
private static final int HEAL_MP_COST = 10;
|
||||||
|
|
||||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor,int maxHP, int maxMP) {
|
public Player(String name, int hp, int mp, Weapon weapon, Armor armor,int maxHP, int maxMP) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -29,21 +35,37 @@ public abstract class Player implements Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void lightAttack(Entity target){
|
public void lightAttack(Entity target){
|
||||||
target.takeDamage(10);
|
if (critical){
|
||||||
|
target.takeDamage((int)(LIGHT_ATTACK_DAMAGE*DAMAGE_MODIFIER));
|
||||||
|
this.makeCritical(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target.takeDamage(LIGHT_ATTACK_DAMAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void heavyAttack(Entity target){
|
public void heavyAttack(Entity target){
|
||||||
target.takeDamage(weapon.getDamage());
|
if (critical){
|
||||||
|
target.takeDamage((int)(weapon.getDamage()*DAMAGE_MODIFIER));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target.takeDamage(weapon.getDamage());
|
||||||
|
}
|
||||||
mp -= weapon.getManaCost();
|
mp -= weapon.getManaCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void defend() {
|
public void defend() {
|
||||||
this.mp -= 5;
|
this.mp -= DEFEND_MP_COST;
|
||||||
isDefending = true;
|
isDefending = true;
|
||||||
System.out.println("Defending...");
|
System.out.println("Defending...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void breakShield(){ // used for dragon ability
|
||||||
|
if (isDefending){
|
||||||
|
isDefending = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
@@ -57,33 +79,34 @@ public abstract class Player implements Entity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void heal(int health) {
|
public void heal(int health) {
|
||||||
mp -= 10;
|
mp -= HEAL_MP_COST;
|
||||||
hp += health;
|
hp += health;
|
||||||
if (hp > maxHP) {
|
if (hp > maxHP) {
|
||||||
hp = maxHP;
|
hp = maxHP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fillMana(int mana) {
|
public void fillMana(int mana) {
|
||||||
mp += mana;
|
mp += mana;
|
||||||
if (mp > maxMP) {
|
if (mp > maxMP) {
|
||||||
mp = maxMP;
|
mp = maxMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stun() {
|
public void makeCritical(boolean value) {
|
||||||
stunned = true;
|
critical = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isStunned() {
|
public void makeDie() {
|
||||||
return stunned;
|
dead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCritical(){ return critical;}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -92,7 +115,15 @@ public abstract class Player implements Entity {
|
|||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDefending() {
|
||||||
|
return isDefending;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public boolean isDead() {
|
||||||
|
return dead;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMaxHP() {
|
public int getMaxHP() {
|
||||||
return maxHP;
|
return maxHP;
|
||||||
}
|
}
|
||||||
@@ -101,11 +132,6 @@ public abstract class Player implements Entity {
|
|||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaxMP() {
|
|
||||||
return maxMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Weapon getWeapon() {
|
public Weapon getWeapon() {
|
||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,12 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
// TODO: UPDATE IMPLEMENTATION
|
||||||
public class Sword extends Weapon {
|
public class Sword extends Weapon {
|
||||||
/*
|
|
||||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int abilityCharge;
|
private static final int DAMAGE = 50;
|
||||||
|
private static final int MANA_COST
|
||||||
|
|
||||||
public Sword() {
|
public Sword(int damage, int manaCost) {
|
||||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
super(damage, manaCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
|
||||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
|
||||||
abilityCharge += 2;
|
|
||||||
for (Entity target : targets) {
|
|
||||||
target.takeDamage(getDamage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,10 @@ package org.project.item.weapons;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Weapon {
|
public abstract class Weapon {
|
||||||
private int damage;
|
private int damage;
|
||||||
private int manaCost;
|
private int manaCost;
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
|
||||||
*/
|
|
||||||
|
|
||||||
public Weapon(int damage, int manaCost) {
|
public Weapon(int damage, int manaCost) {
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
this.manaCost = manaCost;
|
this.manaCost = manaCost;
|
||||||
@@ -28,8 +23,4 @@ public abstract class Weapon {
|
|||||||
public int getManaCost() {
|
public int getManaCost() {
|
||||||
return manaCost;
|
return manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user