Complete game
This commit is contained in:
@@ -4,7 +4,9 @@ public interface Entity {
|
||||
|
||||
void specialAbility(Entity target);
|
||||
|
||||
void defend();
|
||||
void defend(boolean value);
|
||||
|
||||
boolean isDefending();
|
||||
|
||||
void heal(int health);
|
||||
|
||||
@@ -14,6 +16,8 @@ public interface Entity {
|
||||
|
||||
void stun(boolean value);
|
||||
|
||||
void dodge(boolean value);
|
||||
String getName();
|
||||
|
||||
boolean isAlive();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,22 +16,16 @@ public class Dragon extends Enemy{
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
System.out.printf("\t%s attacks!\n", getName());
|
||||
target.takeDamage(28);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
System.out.printf("\t%s breathes fire!\n", getName());
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
@@ -41,4 +35,13 @@ public class Dragon extends Enemy{
|
||||
return "Dragon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.printf("\t=============== Victory! ===============\n", getName());
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,28 +6,60 @@ import org.project.item.weapons.Weapon;
|
||||
public abstract class Enemy implements Entity {
|
||||
Weapon weapon;
|
||||
protected int hp;
|
||||
private boolean defending = false;
|
||||
protected boolean lifeStealing = false;
|
||||
protected int maxHP;
|
||||
protected boolean defending = false;
|
||||
private boolean stunned = false;
|
||||
private boolean dodged = false;
|
||||
protected boolean revived = false;
|
||||
protected boolean alive = true;
|
||||
protected boolean key = true;
|
||||
|
||||
public Enemy(int hp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
maxHP = hp; // TODO: fix this from superclasses
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
System.out.printf("\t%s took %d damage\n", getName(), damage);
|
||||
}
|
||||
|
||||
public void attack(Entity target) {
|
||||
System.out.printf("\t%s used Light Attack!\n", getName());
|
||||
if(target.isDefending()){
|
||||
System.out.printf("\t%s is defending. %s lost his attack.\n", target.getName(), getName());
|
||||
return;
|
||||
}
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
defending = true;
|
||||
public void defend(boolean value) {
|
||||
if(value) {
|
||||
System.out.printf("\t%s used Defend, You cannot attack in your next turn!\n", getName());
|
||||
defending = true;
|
||||
return;
|
||||
}
|
||||
defending = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
System.out.printf("\t%s used Heal!\n", getName());
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
}
|
||||
|
||||
public void heal(){
|
||||
hp = maxHP;
|
||||
alive = true;
|
||||
}
|
||||
|
||||
public void fillHP(){
|
||||
hp = maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,31 +67,55 @@ public abstract class Enemy implements Entity {
|
||||
stunned = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dodge(boolean value) {
|
||||
dodged = value;
|
||||
public void dropKey(){
|
||||
key = false;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefending() {
|
||||
return defending;
|
||||
}
|
||||
|
||||
public boolean isLifeStealing() {
|
||||
return lifeStealing;
|
||||
}
|
||||
|
||||
public boolean isStunned() {
|
||||
return stunned;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
public boolean isRevived() {
|
||||
return revived;
|
||||
}
|
||||
|
||||
public boolean hasKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.printf("\t=============== You defeated %s ===============\n\tGoing to the next Location...", getName());
|
||||
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
public boolean getAlive(){
|
||||
if(hp <= 0){
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,15 +17,12 @@ public class Goblin extends Enemy{
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
target.takeDamage(criticalHit_damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
if(target.isDefending()){
|
||||
System.out.printf("\t%s is defending. %s lost his attack.\n", target.getName(), getName());
|
||||
return;
|
||||
}
|
||||
System.out.printf("\t%s used critical hit!\n", getName());
|
||||
target.takeDamage(criticalHit_damage);
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
|
||||
@@ -16,15 +16,9 @@ public class Skeleton extends Enemy{
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
hp = maxHP/2; // revive
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
System.out.printf("\t%s revived itself!\n", getName());
|
||||
hp = maxHP/2; // revive (once per battle)
|
||||
revived = true;
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
|
||||
@@ -16,17 +16,9 @@ public class Vampire extends Enemy{
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
lifeStealing = true;
|
||||
target.takeDamage((8/10)*(weapon.getDamage()));
|
||||
hp += (int)((2/10)*(weapon.getDamage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
System.out.printf("\t%s used life steal ability!\n", getName());
|
||||
target.takeDamage((int)((0.8)*(weapon.getDamage())));
|
||||
hp += (int)((0.2)*(weapon.getDamage()));
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
|
||||
@@ -7,26 +7,28 @@ import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Assassin extends Player {
|
||||
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
private static final int maxHP = 110;
|
||||
private static final int maxMP = 110;
|
||||
|
||||
public Assassin(String name){
|
||||
Weapon AssassinWeapon = new DualDagger();
|
||||
super(name, maxHP, maxMP, AssassinWeapon);
|
||||
specialAbilityMP = 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
super.lightAttack(target);
|
||||
System.out.printf("\t%s used Light Attack! (%d Mana)\n", name, 0);
|
||||
target.takeDamage(18);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
System.out.printf("\t%s used Special Ability! Enemy gets hit critically (%d Mana)\n", name, 30);
|
||||
target.takeDamage(52); // critical attack
|
||||
this.mp -= 30;
|
||||
dodge(true);
|
||||
this.mp -= specialAbilityMP;
|
||||
defending = true; // dodging (becomes invisible), technically does what Defend does.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,26 +7,31 @@ import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Knight extends Player {
|
||||
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
private static final int maxHP = 130;
|
||||
private static final int maxMP = 70;
|
||||
|
||||
public Knight(String name){
|
||||
Weapon knightWeapon = new Sword();
|
||||
super(name, maxHP, maxMP, knightWeapon);
|
||||
specialAbilityMP = 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
super.lightAttack(target);
|
||||
System.out.printf("\t%s used Light Attack! (%d Mana)\n", name, 0);
|
||||
target.takeDamage(22);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
System.out.printf("\t%s used Special Ability! Enemy misses its next turn. (%d Mana)\n", name, 25);
|
||||
target.takeDamage(30);
|
||||
this.mp -= 25;
|
||||
this.mp -= specialAbilityMP;
|
||||
target.stun(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +1,76 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public abstract class Player implements Entity {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
protected int hp;
|
||||
private int maxHP;
|
||||
protected int maxHP;
|
||||
protected int mp;
|
||||
private int maxMP;
|
||||
private int xp;
|
||||
private boolean defending = false;
|
||||
protected int maxMP;
|
||||
protected boolean defending = false;
|
||||
private boolean stunned = false;
|
||||
private boolean dodged = false;
|
||||
protected int keys;
|
||||
protected boolean alive = true;
|
||||
|
||||
protected final int defendMP = 20;
|
||||
protected int specialAbilityMP;
|
||||
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
maxHP = hp;
|
||||
this.mp = mp;
|
||||
maxMP = mp;
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
public void lightAttack(Entity target){
|
||||
if(target.isDefending()){ // check if enemy is defending or not
|
||||
System.out.printf("\t%s is Defending. You missed your attack.\n", target.getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void heavyAttack(Entity target){ // Uses weapons
|
||||
if(target.isDefending()){ // check if enemy is defending or not
|
||||
System.out.printf("\t%s is Defending. You missed your attack.\n", target.getName());
|
||||
return;
|
||||
}
|
||||
System.out.printf("\t%s used Heavy Attack! (%d Mana)\n", name, weapon.getManaCost());
|
||||
target.takeDamage(weapon.getDamage());
|
||||
mp -= weapon.getManaCost();
|
||||
}
|
||||
|
||||
public abstract void lightAttack(Entity target);
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
defending = true;
|
||||
public void defend(boolean value) {
|
||||
if(value){
|
||||
System.out.printf("\t%s used Defend, Enemy cannot attack in his next turn! (%d Mana)\n", name, 20);
|
||||
mp -= 20;
|
||||
defending = true;
|
||||
return;
|
||||
}
|
||||
defending = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
System.out.printf("\t%s took %d damage\n", name, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
System.out.printf("\t%s used Heal! (%d Mana)\n", name, 20);
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
mp -= 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,16 +78,22 @@ public abstract class Player implements Entity {
|
||||
stunned = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dodge(boolean value) {
|
||||
dodged = value;
|
||||
|
||||
public void fillMana() {
|
||||
mp = maxMP;
|
||||
hp = maxHP;
|
||||
}
|
||||
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
public void addKey(Enemy target){
|
||||
keys++;
|
||||
target.dropKey();
|
||||
System.out.printf("\t%s gained %s's key! gained keys: %d\n\n", getName(), target.getName(), keys);
|
||||
}
|
||||
|
||||
public void addXP(int xp){
|
||||
System.out.printf("\t%d XP added.\n", xp);
|
||||
maxMP += xp;
|
||||
maxHP += xp;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,11 +122,29 @@ public abstract class Player implements Entity {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefending() {
|
||||
return defending;
|
||||
}
|
||||
|
||||
public boolean isDodged() {
|
||||
return dodged;
|
||||
public int getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public int getDefendMP() {
|
||||
return defendMP;
|
||||
}
|
||||
|
||||
public int getSpecialAbilityMP() {
|
||||
return specialAbilityMP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.println("\t=============== Game Over ===============");
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,26 +7,28 @@ import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Wizard extends Player {
|
||||
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
private static final int maxHP = 150;
|
||||
private static final int maxMP = 85;
|
||||
|
||||
public Wizard(String name){
|
||||
Weapon WizardWeapon = new MagicStaff();
|
||||
super(name, maxHP, maxMP, WizardWeapon);
|
||||
specialAbilityMP = 28;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
super.lightAttack(target);
|
||||
System.out.printf("\t%s used Light Attack! (%d Mana)\n", name, 0);
|
||||
target.takeDamage(16);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
target.takeDamage(32); // cast spell
|
||||
this.mp -= 28;
|
||||
System.out.printf("\t%s used Special Ability! Casting spell. (%d Mana)\n", name, 28);
|
||||
target.takeDamage(32); // casts spell
|
||||
this.mp -= specialAbilityMP;
|
||||
heal(15);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user