add players and enemies
This commit is contained in:
Generated
+5
@@ -16,5 +16,10 @@
|
|||||||
<option name="name" value="JBoss Community repository" />
|
<option name="name" value="JBoss Community repository" />
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://mirror-maven.runflare.com/maven2" />
|
||||||
|
</remote-repository>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,21 +1,70 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
public abstract class Entity {
|
||||||
void attack(Entity target);
|
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
public void fillMana(int amount){
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
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;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Enemy extends Entity {
|
||||||
public abstract class Enemy {
|
|
||||||
Weapon weapon;
|
|
||||||
private int hp;
|
|
||||||
private int mp;
|
|
||||||
|
|
||||||
public Enemy(int hp, int mp, Weapon weapon) {
|
protected Weapon weapon;
|
||||||
this.hp = hp;
|
protected boolean isDefending;
|
||||||
this.mp = mp;
|
|
||||||
|
public Enemy(String name, int maxHP, int maxMP, Weapon weapon) {
|
||||||
|
super(name, maxHP, maxMP);
|
||||||
|
|
||||||
this.weapon = weapon;
|
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
|
@Override
|
||||||
public void takeDamage(int damage) {
|
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;
|
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() {
|
public Weapon getWeapon() {
|
||||||
return weapon;
|
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;
|
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 {
|
||||||
|
|
||||||
|
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;
|
package org.project.entity.players;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.armors.Armor;
|
||||||
public class Knight {
|
import org.project.item.weapons.Weapon;
|
||||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
|
||||||
|
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;
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.Main;
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.armors.Armor;
|
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
import org.project.item.armors.Armor;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Player extends Entity {
|
||||||
public abstract class Player {
|
|
||||||
protected String name;
|
|
||||||
Weapon weapon;
|
|
||||||
Armor armor;
|
|
||||||
private int hp;
|
|
||||||
private int maxHP;
|
|
||||||
private int mp;
|
|
||||||
private int maxMP;
|
|
||||||
|
|
||||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
protected Weapon weapon;
|
||||||
this.name = name;
|
protected Armor armor;
|
||||||
this.hp = hp;
|
boolean isDefending = false;
|
||||||
this.mp = mp;
|
|
||||||
|
|
||||||
|
public Player(String name, int maxHP, int maxMP, Weapon weapon, Armor armor) {
|
||||||
|
super(name, maxHP, maxMP);
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack(Entity target) {
|
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
|
@Override
|
||||||
public void defend() {
|
public void defend() {
|
||||||
// TODO
|
isDefending = true;
|
||||||
|
System.out.println(name + " is defending! ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (armor != null) {
|
||||||
public void fillMana(int mana) {
|
damage -= armor.getDefense();
|
||||||
mp += mana;
|
System.out.println(name + "'s armor reduced damage by " + armor.getDefense());
|
||||||
if (mp > maxMP) {
|
|
||||||
mp = maxMP;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
if (isDefending) {
|
||||||
return name;
|
damage /= 2;
|
||||||
|
isDefending = false;
|
||||||
|
System.out.println(name + " defended and reduced damage!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp() {
|
|
||||||
return hp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
damage = Math.max(0, damage);
|
||||||
public int getMaxHP() {
|
|
||||||
return maxHP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMp() {
|
hp -= damage;
|
||||||
return mp;
|
if (hp < 0) hp = 0;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
System.out.println(name + " took " + damage + " damage. (" + hp + "/" + maxHP + ")");
|
||||||
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) {
|
public Armor(int defense, int durability) {
|
||||||
this.defense = defense;
|
this.defense = defense;
|
||||||
this.durability = durability;
|
this.durability = durability;
|
||||||
|
this.maxDefense = defense;
|
||||||
|
this.maxDurability = durability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkBreak() {
|
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;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Weapon {
|
public abstract class Weapon {
|
||||||
private int damage;
|
protected int damage;
|
||||||
private int manaCost;
|
protected 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public abstract void use(Entity target);
|
||||||
public void use(Entity target) {
|
|
||||||
target.takeDamage(damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDamage() {
|
public int getDamage() {
|
||||||
return damage;
|
return damage;
|
||||||
@@ -29,7 +22,5 @@ public abstract class Weapon {
|
|||||||
return manaCost;
|
return manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user