+ Finished Player & Enemy
+ Implemented specialAbility for every Entity
This commit is contained in:
@@ -1,32 +1,42 @@
|
||||
package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
// void attack(Entity target);
|
||||
public abstract class Entity {
|
||||
|
||||
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(){};
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public abstract void makeDie();
|
||||
|
||||
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;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
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.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy implements Entity {
|
||||
Weapon weapon;
|
||||
private int hp;
|
||||
private int mp;
|
||||
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.mp = mp;
|
||||
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
public void attack(Entity target){
|
||||
if (critical){
|
||||
target.takeDamage((int)(weapon.getDamage() * DAMAGE_MODIFIER));
|
||||
}
|
||||
else {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
@@ -27,20 +37,41 @@ public abstract class Enemy implements Entity {
|
||||
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
|
||||
public boolean isStunned() {
|
||||
return stunned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead() {
|
||||
return dead;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public abstract void specialAbility(Entity target);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,33 @@
|
||||
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{
|
||||
|
||||
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;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
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;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
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
|
||||
public void specialAbility(Entity target) {
|
||||
System.out.println("Performing shield bash...");
|
||||
|
||||
|
||||
target.stun(true);
|
||||
target.takeDamage(50);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player implements Entity {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
@@ -14,7 +13,14 @@ public abstract class Player implements Entity {
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
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) {
|
||||
this.name = name;
|
||||
@@ -29,21 +35,37 @@ public abstract class Player implements Entity {
|
||||
}
|
||||
|
||||
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){
|
||||
if (critical){
|
||||
target.takeDamage((int)(weapon.getDamage()*DAMAGE_MODIFIER));
|
||||
}
|
||||
else {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
mp -= weapon.getManaCost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
this.mp -= 5;
|
||||
this.mp -= DEFEND_MP_COST;
|
||||
isDefending = true;
|
||||
System.out.println("Defending...");
|
||||
}
|
||||
|
||||
public void breakShield(){ // used for dragon ability
|
||||
if (isDefending){
|
||||
isDefending = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
@@ -57,16 +79,14 @@ public abstract class Player implements Entity {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
mp -= 10;
|
||||
mp -= HEAL_MP_COST;
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
@@ -75,15 +95,18 @@ public abstract class Player implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stun() {
|
||||
stunned = true;
|
||||
public void makeCritical(boolean value) {
|
||||
critical = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStunned() {
|
||||
return stunned;
|
||||
public void makeDie() {
|
||||
dead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCritical(){ return critical;}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -92,7 +115,15 @@ public abstract class Player implements Entity {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public boolean isDefending() {
|
||||
return isDefending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead() {
|
||||
return dead;
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
@@ -101,11 +132,6 @@ public abstract class Player implements Entity {
|
||||
return mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@@ -6,21 +6,12 @@ import java.util.ArrayList;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
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() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
public Sword(int damage, int manaCost) {
|
||||
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;
|
||||
|
||||
// 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;
|
||||
@@ -28,8 +23,4 @@ public abstract class Weapon {
|
||||
public int getManaCost() {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user