add players and enemies
This commit is contained in:
@@ -1,21 +1,70 @@
|
||||
package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
void attack(Entity target);
|
||||
public abstract class Entity {
|
||||
|
||||
void defend();
|
||||
protected String name;
|
||||
protected int hp;
|
||||
protected int maxHP;
|
||||
protected int mp;
|
||||
protected int maxMP;
|
||||
protected boolean alive = true;
|
||||
|
||||
void heal(int health);
|
||||
public Entity(String name , int maxHP , int maxMP){
|
||||
this.name = name;
|
||||
this.maxHP = maxHP;
|
||||
this.hp = maxHP;
|
||||
this.maxMP = maxMP;
|
||||
this.mp = maxMP;
|
||||
}
|
||||
|
||||
void fillMana(int mana);
|
||||
public abstract void attack(Entity target);
|
||||
|
||||
void takeDamage(int damage);
|
||||
public abstract void defend();
|
||||
|
||||
int getMaxHP();
|
||||
public void heal(int amount){
|
||||
hp += amount;
|
||||
if(hp > maxHP) hp=maxHP;
|
||||
}
|
||||
|
||||
int getMaxMP();
|
||||
public void consumeMana(int amount){
|
||||
mp -= amount;
|
||||
if(mp < 0 ) mp=0;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public void fillMana(int amount){
|
||||
mp += amount;
|
||||
if(mp > maxMP) mp=maxMP;
|
||||
}
|
||||
|
||||
public void takeDamage(int damage){
|
||||
hp -= damage;
|
||||
if(hp <= 0 ){
|
||||
hp=0;
|
||||
alive = false;
|
||||
System.out.println(name + " failed! ");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAlive(){
|
||||
return alive;
|
||||
}
|
||||
|
||||
public int getHp(){
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMp(){
|
||||
return mp;
|
||||
}
|
||||
public int getMaxHP(){
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public int getMaxMP(){
|
||||
return maxMP;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Dragon extends Enemy {
|
||||
|
||||
public Dragon(Weapon weapon) {
|
||||
super("Dragon", 100, 50, weapon);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,69 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
Weapon weapon;
|
||||
private int hp;
|
||||
private int mp;
|
||||
public abstract class Enemy extends Entity {
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
protected Weapon weapon;
|
||||
protected boolean isDefending;
|
||||
|
||||
public Enemy(String name, int maxHP, int maxMP, Weapon weapon) {
|
||||
super(name, maxHP, maxMP);
|
||||
|
||||
this.weapon = weapon;
|
||||
this.isDefending = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
|
||||
|
||||
int manaCost = weapon.getManaCost();
|
||||
|
||||
if (mp < manaCost) {
|
||||
System.out.println(name + " tried to attack but does not have enough MP!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
mp -= manaCost;
|
||||
|
||||
System.out.println(
|
||||
name + " attacks " + target.getName() +
|
||||
" with " + weapon.getClass().getSimpleName() + "!"
|
||||
);
|
||||
|
||||
|
||||
weapon.use(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
isDefending = true;
|
||||
System.out.println(name + " is defending!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
|
||||
if (damage <= 0) return;
|
||||
|
||||
|
||||
if (isDefending) {
|
||||
damage /= 2;
|
||||
isDefending = false;
|
||||
System.out.println(name + " defended and reduced the damage!");
|
||||
}
|
||||
|
||||
hp -= damage;
|
||||
if (hp < 0) hp = 0;
|
||||
|
||||
System.out.println(
|
||||
name + " took " + damage + " damage. (" + hp + "/" + maxHP + ")"
|
||||
);
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Goblin extends Enemy {
|
||||
|
||||
public Goblin(Weapon weapon) {
|
||||
super("Goblin", 30, 10, weapon);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
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 {
|
||||
|
||||
public Skeleton(Weapon weapon) {
|
||||
super("Skeleton", 35, 10, weapon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Vampire extends Enemy {
|
||||
|
||||
public Vampire(Weapon weapon) {
|
||||
super("Vampire", 45, 20, weapon);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Assassin extends Player{
|
||||
public Assassin(String name , Weapon weapon , Armor armor){
|
||||
super(name , 75 , 50 , weapon , armor);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Knight extends Player {
|
||||
|
||||
public Knight(String name, Weapon weapon , Armor armor) {
|
||||
super(name, 100, 30, weapon , armor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Mage extends Player{
|
||||
public Mage(String name , Weapon weapon , Armor armor){
|
||||
super(name , 60 , 100 , weapon , armor);
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,70 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.Main;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.item.armors.Armor;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
public abstract class Player extends Entity {
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
protected Weapon weapon;
|
||||
protected Armor armor;
|
||||
boolean isDefending = false;
|
||||
|
||||
public Player(String name, int maxHP, int maxMP, Weapon weapon, Armor armor) {
|
||||
super(name, maxHP, maxMP);
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
if (weapon == null) {
|
||||
System.out.println(name + " has no weapon!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mp < weapon.getManaCost()) {
|
||||
System.out.println(name + " doesn't have enough mana!");
|
||||
return;
|
||||
}
|
||||
|
||||
mp -= weapon.getManaCost();
|
||||
weapon.use(target);
|
||||
|
||||
System.out.println(name + " attacked " + target.getName() +
|
||||
" with " + weapon.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
// TODO
|
||||
isDefending = true;
|
||||
System.out.println(name + " is defending! ");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
}
|
||||
if (damage <= 0) return;
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
|
||||
if (armor != null) {
|
||||
damage -= armor.getDefense();
|
||||
System.out.println(name + "'s armor reduced damage by " + armor.getDefense());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
|
||||
if (isDefending) {
|
||||
damage /= 2;
|
||||
isDefending = false;
|
||||
System.out.println(name + " defended and reduced damage!");
|
||||
}
|
||||
|
||||
|
||||
damage = Math.max(0, damage);
|
||||
|
||||
hp -= damage;
|
||||
if (hp < 0) hp = 0;
|
||||
|
||||
System.out.println(name + " took " + damage + " damage. (" + hp + "/" + maxHP + ")");
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public Armor getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ public abstract class Armor {
|
||||
public Armor(int defense, int durability) {
|
||||
this.defense = defense;
|
||||
this.durability = durability;
|
||||
this.maxDefense = defense;
|
||||
this.maxDurability = durability;
|
||||
}
|
||||
|
||||
public void checkBreak() {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class BasicWeapon extends Weapon {
|
||||
|
||||
public BasicWeapon() {
|
||||
super(5, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,17 @@ package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
protected int damage;
|
||||
protected 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 abstract void use(Entity target);
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
@@ -29,7 +22,5 @@ public abstract class Weapon {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user