Compare commits
20
Commits
main
...
3ab38fddce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ab38fddce | ||
|
|
d509a8b999 | ||
|
|
d675c5421c | ||
|
|
8b1da4b522 | ||
|
|
5e023fa6cd | ||
|
|
ed41752409 | ||
|
|
add61e75aa | ||
|
|
b7c3086fd0 | ||
|
|
65a72039bc | ||
|
|
29dbb6d7ad | ||
|
|
0a6c6034a3 | ||
|
|
d6d2bdc24f | ||
|
|
3ea2250388 | ||
|
|
b16f3a45a8 | ||
|
|
4935b9f901 | ||
|
|
2bfb6a891c | ||
|
|
82037fed3a | ||
|
|
be2abcb352 | ||
|
|
187e672fe9 | ||
|
|
576a7553c6 |
+2
-2
@@ -9,8 +9,8 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>25</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>25</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,190 @@
|
|||||||
package org.project;
|
package org.project;
|
||||||
|
|
||||||
|
import org.project.entity.enemies.Enemy;
|
||||||
|
import org.project.entity.enemies.Goblin;
|
||||||
|
import org.project.entity.enemies.Skeleton;
|
||||||
|
import org.project.entity.enemies.Vampire;
|
||||||
|
import org.project.entity.players.Assassin;
|
||||||
|
import org.project.entity.players.Knight;
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import org.project.entity.players.Wizard;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
import org.project.location.Location;
|
import org.project.location.Location;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
Weapon wp = new Sword();
|
||||||
List<Location> locations = new ArrayList<>();
|
ArrayList<Player> players = new ArrayList<>();
|
||||||
|
players.add(new Assassin());
|
||||||
|
players.add(new Knight());
|
||||||
|
players.add(new Wizard());
|
||||||
|
ArrayList<Enemy> enemies = new ArrayList<>();
|
||||||
|
enemies.add(new Goblin());
|
||||||
|
enemies.add(new Skeleton());
|
||||||
|
enemies.add(new Vampire());
|
||||||
|
ArrayList<Location> locations = new ArrayList<>();
|
||||||
|
locations.add(new Location("Jungle", enemies));
|
||||||
|
locations.add(new Location("China", new ArrayList<>(enemies.subList(0, 2))));
|
||||||
|
locations.add(new Location("Iran", new ArrayList<>(enemies.subList(1, 3))));
|
||||||
|
Player player;
|
||||||
|
Enemy enemy;
|
||||||
|
Location location;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
player = choosePlayer(players,sc);
|
||||||
|
while (true) {
|
||||||
|
location = chooseLocation(locations,sc);
|
||||||
|
enemy = chooseEnemy(location);
|
||||||
|
System.out.println("wanna fight?\n1.Yes\n2.No");
|
||||||
|
int choice = sc.nextInt();
|
||||||
|
if (choice == 1) {
|
||||||
|
combat(player,enemy,sc);
|
||||||
|
System.out.println("player AHP: " + player.getHP());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: IMPLEMENT GAMEPLAY
|
|
||||||
}
|
}
|
||||||
}
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
public static void displayLocations(List<Location> locations) {
|
||||||
|
for (Location location : locations) {
|
||||||
|
System.out.println(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Player choosePlayer(ArrayList<Player> players, Scanner sc) {
|
||||||
|
System.out.print("1.Assassin\n2.Knight\n3.Wizard\nChoose your Character: ");
|
||||||
|
int choice = sc.nextInt();
|
||||||
|
Player player;
|
||||||
|
switch (choice) {
|
||||||
|
case 1 -> player = players.get(0);
|
||||||
|
case 2 -> player = players.get(1);
|
||||||
|
default -> player = players.get(2);
|
||||||
|
}
|
||||||
|
System.out.println("You chose " + player.getName() + "(" + player.getClass().getSimpleName() + ")");
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location chooseLocation(ArrayList<Location> locations, Scanner sc) {
|
||||||
|
|
||||||
|
displayLocations(locations);
|
||||||
|
System.out.print("1.Jungle\n2.China\n3.Iran\nChoose Location: ");
|
||||||
|
int choice = sc.nextInt();
|
||||||
|
Location location = null;
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1 -> location = locations.get(0);
|
||||||
|
case 2 -> location = locations.get(1);
|
||||||
|
case 3 -> location = locations.get(2);
|
||||||
|
}
|
||||||
|
System.out.println("You chose " + location.getName() );
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Enemy chooseEnemy(Location location) {
|
||||||
|
int random = new Random().nextInt(location.getEnemies().size());
|
||||||
|
Enemy enemy = location.getEnemies().get(random);
|
||||||
|
System.out.println("The Enemy is: " + enemy.getClass().getSimpleName());
|
||||||
|
return enemy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void combat(Player player, Enemy enemy, Scanner sc) {
|
||||||
|
int turn = 0;
|
||||||
|
int choice;
|
||||||
|
while (player.isAlive() && enemy.isAlive()) {
|
||||||
|
if (turn == 0) {
|
||||||
|
turn = 1;
|
||||||
|
System.out.println("choose your action:\n1.light attack 2.heavy attack 3.defend 4.heal 5.special ability");
|
||||||
|
choice = sc.nextInt();
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
player.lightAttack(enemy);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
player.heavyAttack(enemy);
|
||||||
|
if (player.isSuccessfulAction()) break;
|
||||||
|
else {turn = 0; continue;}
|
||||||
|
case 3:
|
||||||
|
player.defend();
|
||||||
|
if (player.isSuccessfulAction()) break;
|
||||||
|
else {turn = 0; continue;}
|
||||||
|
case 4:
|
||||||
|
player.heal(10);
|
||||||
|
if (player.isSuccessfulAction()) break;
|
||||||
|
else {turn = 0; continue;}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
player.specialAbility(enemy);
|
||||||
|
if (player.isSuccessfulAction()) break;
|
||||||
|
else {turn = 0; continue;}
|
||||||
|
default:
|
||||||
|
System.out.println("invalid choice");
|
||||||
|
}
|
||||||
|
System.out.println("[" + player.getClass().getSimpleName() + " - " + player.getHP() + "/" + player.getMaxHP()
|
||||||
|
+ " HP | " + player.getMP() + "/" + player.getMaxMP() + " Mana" + "]");
|
||||||
|
System.out.println("[" + enemy.getClass().getSimpleName() + " - " + enemy.getHP() + "/" + enemy.getMaxHP()
|
||||||
|
+ " HP | " + enemy.getMP() + "/" + enemy.getMaxMP() + " Mana" + "]");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (turn == 1) {
|
||||||
|
System.out.println("-".repeat(30));
|
||||||
|
if (player instanceof Assassin) {
|
||||||
|
if (player.getUsingSpecialAbility()){
|
||||||
|
player.setUsingSpecialAbility(false);
|
||||||
|
turn = 0;
|
||||||
|
System.out.println(enemy.getClass().getSimpleName() + " skipped it's turn!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(enemy.getClass().getSimpleName() + "'s turn: ");
|
||||||
|
turn = 0;
|
||||||
|
choice = new Random().nextInt(3);
|
||||||
|
switch (choice) {
|
||||||
|
case 0:
|
||||||
|
enemy.attack(player);
|
||||||
|
if (enemy.isSuccessfulAction()) break;
|
||||||
|
else {turn = 1; continue;}
|
||||||
|
case 1:
|
||||||
|
enemy.defend();
|
||||||
|
if (enemy.isSuccessfulAction()) break;
|
||||||
|
else {turn = 1; continue;}
|
||||||
|
case 2:
|
||||||
|
enemy.heal(10);
|
||||||
|
if (enemy.isSuccessfulAction()) break;
|
||||||
|
else {turn = 1; continue;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("[" + player.getClass().getSimpleName() + " - " + player.getHP() + "/" + player.getMaxHP()
|
||||||
|
+ " HP | " + player.getMP() + "/" + player.getMaxMP() +" Mana" + "]");
|
||||||
|
System.out.println("[" + enemy.getClass().getSimpleName() + " - " + enemy.getHP() + "/" + enemy.getMaxHP()
|
||||||
|
+ " HP | " + enemy.getMP() + "/" + enemy.getMaxMP() + " Mana" + "]");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
System.out.println("You lost!");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("You Won!");
|
||||||
|
if (enemy.dropKey()) {
|
||||||
|
System.out.println(enemy.getClass().getSimpleName() + "'s key dropped!");
|
||||||
|
player.achieveKey(enemy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public interface Entity {
|
public interface Entity {
|
||||||
void attack(Entity target);
|
void attack(Entity target);
|
||||||
|
|
||||||
@@ -7,15 +9,42 @@ public interface Entity {
|
|||||||
|
|
||||||
void heal(int health);
|
void heal(int health);
|
||||||
|
|
||||||
void fillMana(int mana);
|
|
||||||
|
|
||||||
void takeDamage(int damage);
|
void takeDamage(int damage);
|
||||||
|
|
||||||
|
void takeDamage(int damage, Entity target);
|
||||||
|
|
||||||
|
int getHP();
|
||||||
|
|
||||||
|
void setHP(int hp);
|
||||||
|
|
||||||
int getMaxHP();
|
int getMaxHP();
|
||||||
|
|
||||||
|
int getMP();
|
||||||
|
|
||||||
|
void setMP(int mana);
|
||||||
|
|
||||||
|
void setMaxHP(int maxHP);
|
||||||
|
|
||||||
int getMaxMP();
|
int getMaxMP();
|
||||||
|
|
||||||
/*
|
void setMaxMP(int maxMP);
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
boolean isDefending();
|
||||||
|
|
||||||
|
void setDefending(boolean defending);
|
||||||
|
|
||||||
|
double getDefendRate();
|
||||||
|
|
||||||
|
void setDefendRate(double defendRate);
|
||||||
|
|
||||||
|
Weapon getWeapon();
|
||||||
|
|
||||||
|
double getAttackMultiplier();
|
||||||
|
|
||||||
|
void setAttackMultiplier(double multiplier);
|
||||||
|
|
||||||
|
default boolean isAlive() {
|
||||||
|
int hp = getHP();
|
||||||
|
return hp > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,186 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Enemy {
|
public abstract class Enemy implements Entity {
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
private int hp;
|
private int hp;
|
||||||
|
private int maxHP;
|
||||||
private int mp;
|
private int mp;
|
||||||
|
private int maxMP;
|
||||||
|
private boolean defending = false;
|
||||||
|
private double defendRate;
|
||||||
|
private double attackMultiplier = 1;
|
||||||
|
private boolean hasKey = false;
|
||||||
|
private static boolean keyFound = false;
|
||||||
|
private boolean successfulAction = true;
|
||||||
|
|
||||||
public Enemy(int hp, int mp, Weapon weapon) {
|
public Enemy(int hp, int mp, Weapon weapon) {
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
|
this.maxHP = hp;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
|
this.maxMP = mp;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
|
if (!keyFound) { hasKey = Math.random() < .2;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
setSuccessfulAction(true);
|
||||||
|
if (getMP() >= weapon.getManaCost()) {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + ": attacking " + target.getClass().getSimpleName());
|
||||||
|
double damage = getAttackMultiplier() * weapon.getDamage();
|
||||||
|
if(((Sword)(weapon)).charge()) damage *= 1.4;
|
||||||
|
if (target.isDefending()) {
|
||||||
|
target.takeDamage((int) (damage * (1 - target.getDefendRate())),this);
|
||||||
|
target.setDefending(false);
|
||||||
|
} else {
|
||||||
|
target.takeDamage((int) damage,this);
|
||||||
|
}
|
||||||
|
setMP(getMP() - weapon.getManaCost());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("not enough mana");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend(){
|
||||||
|
setSuccessfulAction(true);
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " is defending");
|
||||||
|
setDefending(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
setSuccessfulAction(true);
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
|
||||||
|
setHP(getHP() + health);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
hp -= damage;
|
if (isDefending()) {
|
||||||
|
setHP(getHP() - (int) ((1 - getDefendRate()) * damage));
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " took " + (int) ((1 - getDefendRate()) * damage) + " damages!");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " took " + damage + " damages!");
|
||||||
|
setHP(getHP() - damage);
|
||||||
|
if (getHP() <= 0) {
|
||||||
|
setHP(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp() {
|
@Override
|
||||||
return hp;
|
public void takeDamage(int damage, Entity target) {
|
||||||
|
this.takeDamage(damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
@Override
|
||||||
|
public int getHP() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHP(int hp) {
|
||||||
|
this.hp = hp;
|
||||||
|
if (this.hp > maxHP) {
|
||||||
|
this.hp = maxHP;
|
||||||
|
} else if (this.hp < 0) {
|
||||||
|
this.hp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHP() {
|
||||||
|
return maxHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxHP(int maxHP) {
|
||||||
|
this.maxHP = maxHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMP() {
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMP(int mp) {
|
||||||
|
this.mp = mp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMP() {
|
||||||
|
return maxMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxMP(int maxMP) {
|
||||||
|
this.maxMP = maxMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefending() {
|
||||||
|
return defending;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefending(boolean defending) {
|
||||||
|
this.defending = defending;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDefendRate() {
|
||||||
|
return defendRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefendRate(double defendRate) {
|
||||||
|
this.defendRate = defendRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Weapon getWeapon() {
|
public Weapon getWeapon() {
|
||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getAttackMultiplier() {
|
||||||
|
return attackMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAttackMultiplier(double multiplier) {
|
||||||
|
attackMultiplier = multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean dropKey() {
|
||||||
|
if (hp <= 0 && hasKey) {
|
||||||
|
keyFound = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccessfulAction(boolean successfulAction) {
|
||||||
|
this.successfulAction = successfulAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccessfulAction() {
|
||||||
|
return successfulAction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
|
||||||
|
public class Goblin extends Enemy{
|
||||||
|
public Goblin() {
|
||||||
|
super(80,100,new Sword());
|
||||||
|
setDefendRate(.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
setAttackMultiplier(1.8);
|
||||||
|
super.attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMP() >= 20) {
|
||||||
|
super.defend();
|
||||||
|
setMP(getMP() - 20);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getMP() >= 15) {
|
||||||
|
super.heal(health);
|
||||||
|
setMP(getMP() - 15);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,55 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class Skeleton {
|
import org.project.entity.Entity;
|
||||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
import org.project.item.weapons.Sword;
|
||||||
|
|
||||||
|
public class Skeleton extends Enemy{
|
||||||
|
|
||||||
|
private boolean incarnation = false;
|
||||||
|
public Skeleton() {
|
||||||
|
super(70,100,new Sword());
|
||||||
|
setDefendRate(.3);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
super.attack(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMP() >= 8) {
|
||||||
|
super.defend();
|
||||||
|
setMP(getMP() - 8);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getMP() >= 18) {
|
||||||
|
super.heal(health);
|
||||||
|
setMP(getMP() - 18);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage) {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
if (getHP() <= 0 && !incarnation) {
|
||||||
|
setHP(getMaxHP() / 2);
|
||||||
|
incarnation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
|
||||||
|
public class Vampire extends Enemy{
|
||||||
|
|
||||||
|
public Vampire() {
|
||||||
|
super(90,90,new Sword());
|
||||||
|
setDefendRate(.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
setAttackMultiplier(1.5);
|
||||||
|
super.attack(target);
|
||||||
|
double damage = weapon.getDamage() * getAttackMultiplier();
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
if (target.isDefending()) {
|
||||||
|
super.heal( (int) (.3 * (damage * (1 - target.getDefendRate()))));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
super.heal( (int) (.3 * damage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMP() >= 15) {
|
||||||
|
super.defend();
|
||||||
|
setMP(getMP() - 15);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getMP() >= 12) {
|
||||||
|
super.heal(health);
|
||||||
|
setMP(getMP() - 12);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.armors.AssassinArmor;
|
||||||
|
import org.project.item.weapons.Dagger;
|
||||||
|
|
||||||
|
public class Assassin extends Player {
|
||||||
|
|
||||||
|
public Assassin() {
|
||||||
|
super("ASSASSIN",100,100, new Dagger(), new AssassinArmor());
|
||||||
|
setDefendRate(.7);
|
||||||
|
setFlask(10,3,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lightAttack(Entity target) {
|
||||||
|
super.lightAttack(target);
|
||||||
|
if (((Dagger) weapon).critical()){
|
||||||
|
setAttackMultiplier(1.5);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
} else {
|
||||||
|
attack(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
super.heavyAttack(target);
|
||||||
|
if (getUsingSpecialAbility()) {
|
||||||
|
setAttackMultiplier(1.8);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
setUsingSpecialAbility(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (getMP() >= weapon.getManaCost()) {
|
||||||
|
setAttackMultiplier(1.4);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
setMP(getMP() - weapon.getManaCost());
|
||||||
|
} else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMP() >= 12) {
|
||||||
|
super.defend();
|
||||||
|
setMP(getMP() - 12);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
if (getMP() >= 25) {
|
||||||
|
setUsingSpecialAbility(true);
|
||||||
|
System.out.println("Assasin using SpecialAbility");
|
||||||
|
setMP(getMP() - 25);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getMP() >= 12) {
|
||||||
|
super.heal(health);
|
||||||
|
setMP(getMP() - 12);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage) {
|
||||||
|
if (getUsingSpecialAbility()) {
|
||||||
|
System.out.println("player using special ability");
|
||||||
|
} else {
|
||||||
|
damage = ((AssassinArmor) (getArmor())).reduceDamage(damage, this);
|
||||||
|
super.takeDamage(damage);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public interface CombatOptions {
|
||||||
|
|
||||||
|
void lightAttack(Entity target);
|
||||||
|
void heavyAttack(Entity target);
|
||||||
|
void defend();
|
||||||
|
void heal(int health);
|
||||||
|
void specialAbility(Entity target);
|
||||||
|
}
|
||||||
@@ -1,6 +1,92 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class Knight {
|
import org.project.entity.Entity;
|
||||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
import org.project.item.armors.KnightArmor;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
|
||||||
|
public class Knight extends Player {
|
||||||
|
|
||||||
|
public Knight() {
|
||||||
|
super("Knight",100,90, new Sword(), new KnightArmor());
|
||||||
|
setDefendRate(.9);
|
||||||
|
setFlask(20,3,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lightAttack(Entity target) {
|
||||||
|
super.lightAttack(target);
|
||||||
|
if (((Sword) weapon).charge()){
|
||||||
|
setAttackMultiplier(1.4);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
} else {
|
||||||
|
attack(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
super.heavyAttack(target);
|
||||||
|
if (getMP() >= weapon.getManaCost()) {
|
||||||
|
setAttackMultiplier(1.5);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
setMP(getMP() - weapon.getManaCost());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMP() >= 16) {
|
||||||
|
super.defend();
|
||||||
|
setMP(getMP() - 16);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
if (getMP() >= 30) {
|
||||||
|
setUsingSpecialAbility(true);
|
||||||
|
setAttackMultiplier(2);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
setMP(getMP() - 30);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setUsingSpecialAbility(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getMP() >= 10) {
|
||||||
|
super.heal(health);
|
||||||
|
setMP(getMP() - 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage, Entity attacker) {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
if (!getArmor().checkBrake()) {
|
||||||
|
int reflected = ((KnightArmor) armor).getReflectedDamage(damage);
|
||||||
|
attacker.takeDamage(reflected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.entity.enemies.Goblin;
|
||||||
|
import org.project.entity.enemies.Skeleton;
|
||||||
import org.project.item.armors.Armor;
|
import org.project.item.armors.Armor;
|
||||||
|
import org.project.item.consumables.Consumable;
|
||||||
|
import org.project.item.consumables.Flask;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Player {
|
public abstract class Player implements Entity, CombatOptions {
|
||||||
protected String name;
|
protected String name;
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
Armor armor;
|
Armor armor;
|
||||||
@@ -13,46 +17,85 @@ public abstract class Player {
|
|||||||
private int maxHP;
|
private int maxHP;
|
||||||
private int mp;
|
private int mp;
|
||||||
private int maxMP;
|
private int maxMP;
|
||||||
|
private boolean defending = false;
|
||||||
|
private double defendRate;
|
||||||
|
private boolean isUsingSpecialAbility = false;
|
||||||
|
private double attackMultiplier = 1;
|
||||||
|
private boolean hasGoblinKey = false;
|
||||||
|
private boolean hasSkeletonKey = false;
|
||||||
|
private boolean hasVampireKey = false;
|
||||||
|
private boolean successfulAction = true;
|
||||||
|
private Consumable flask;
|
||||||
|
|
||||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
|
this.maxHP = hp;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
|
this.maxMP = mp;
|
||||||
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());
|
setSuccessfulAction(true);
|
||||||
|
double damage = getAttackMultiplier() * weapon.getDamage();
|
||||||
|
if (target.isDefending()) {
|
||||||
|
target.takeDamage( (int) (damage * (1 - target.getDefendRate())));
|
||||||
|
target.setDefending(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target.takeDamage((int) damage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lightAttack(Entity target) {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " light attacking");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defend() {
|
public void heavyAttack(Entity target) {
|
||||||
// TODO
|
System.out.println(this.getClass().getSimpleName() + " heavy attacking");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend(){
|
||||||
|
setSuccessfulAction(true);
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " is defending");
|
||||||
|
setDefending(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target){setSuccessfulAction(true);}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
hp -= damage - armor.getDefense();
|
|
||||||
|
int finalDamage = armor.getDefense() - damage;
|
||||||
|
if (finalDamage < 0) {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " took " + -finalDamage + " damages!");
|
||||||
|
setHP(getHP() + finalDamage);
|
||||||
|
armor.setDefense(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " took " + damage + " damages!");
|
||||||
|
armor.setDefense(finalDamage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage, Entity target) {
|
||||||
|
this.takeDamage(damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void heal(int health) {
|
public void heal(int health) {
|
||||||
hp += health;
|
setSuccessfulAction(true);
|
||||||
if (hp > maxHP) {
|
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
|
||||||
hp = maxHP;
|
setHP(getHP() + health);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fillMana(int mana) {
|
|
||||||
mp += mana;
|
|
||||||
if (mp > maxMP) {
|
|
||||||
mp = maxMP;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,24 +103,59 @@ public abstract class Player {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp() {
|
@Override
|
||||||
|
public int getHP() {
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHP(int hp) {
|
||||||
|
this.hp = hp;
|
||||||
|
if (this.hp > maxHP) {
|
||||||
|
this.hp = maxHP;
|
||||||
|
} else if (this.hp < 0) {
|
||||||
|
this.hp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxHP() {
|
public int getMaxHP() {
|
||||||
return maxHP;
|
return maxHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
@Override
|
||||||
|
public void setMaxHP(int maxHP) {
|
||||||
|
this.maxHP = maxHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMP() {
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMP(int mana) {
|
||||||
|
mp = mana;
|
||||||
|
if (mp > maxMP) {
|
||||||
|
mp = maxMP;
|
||||||
|
} else if (mp < 0) {
|
||||||
|
mp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMP() {
|
public int getMaxMP() {
|
||||||
return maxMP;
|
return maxMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxMP(int maxMP) {
|
||||||
|
this.maxMP = maxMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Weapon getWeapon() {
|
public Weapon getWeapon() {
|
||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
@@ -86,4 +164,56 @@ public abstract class Player {
|
|||||||
return armor;
|
return armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefending() { return defending; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefending(boolean defending) { this.defending = defending; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDefendRate() { return defendRate; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefendRate(double defendRate) { this.defendRate = defendRate; }
|
||||||
|
|
||||||
|
public boolean getUsingSpecialAbility() { return isUsingSpecialAbility; }
|
||||||
|
|
||||||
|
public void setUsingSpecialAbility(boolean isUsingSpecialAbility) { this.isUsingSpecialAbility = isUsingSpecialAbility; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getAttackMultiplier() {
|
||||||
|
return attackMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAttackMultiplier(double multiplier) {
|
||||||
|
attackMultiplier = multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasGoblinKey() { return hasGoblinKey; }
|
||||||
|
public boolean hasSkeletonKey() { return hasSkeletonKey; }
|
||||||
|
public boolean hasVampireKey() { return hasVampireKey; }
|
||||||
|
|
||||||
|
public void achieveKey(Entity target) {
|
||||||
|
if ( target instanceof Goblin) { hasGoblinKey = true; }
|
||||||
|
else if (target instanceof Skeleton) { hasSkeletonKey = true; }
|
||||||
|
else { hasVampireKey = true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccessfulAction(boolean successfulAction) {
|
||||||
|
this.successfulAction = successfulAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccessfulAction() {
|
||||||
|
return successfulAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlask(int healAmount, int quantity, boolean isMana) {
|
||||||
|
flask = new Flask(healAmount, quantity, isMana);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Consumable getFlask() {
|
||||||
|
return flask;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.armors.WizardArmor;
|
||||||
|
import org.project.item.weapons.Bow;
|
||||||
|
|
||||||
|
public class Wizard extends Player{
|
||||||
|
|
||||||
|
public Wizard() {
|
||||||
|
super("Wizard",90,90,new Bow(),new WizardArmor());
|
||||||
|
setDefendRate(.6);
|
||||||
|
setFlask(30,3,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lightAttack(Entity target) {
|
||||||
|
super.lightAttack(target);
|
||||||
|
if (((Bow) weapon).charge()){
|
||||||
|
setAttackMultiplier(1.4);
|
||||||
|
attack(target);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
} else {
|
||||||
|
attack(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
super.heavyAttack(target);
|
||||||
|
if (getMP() >= weapon.getManaCost()) {
|
||||||
|
setAttackMultiplier(1.3);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
setMP(getMP() - weapon.getManaCost());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMP() >= 15) {
|
||||||
|
super.defend();
|
||||||
|
setMP(getMP() - 15);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
if (getMP() >= 20) {
|
||||||
|
setAttackMultiplier(1.6);
|
||||||
|
attack(target);
|
||||||
|
setAttackMultiplier(1);
|
||||||
|
setMP(getMP() - 20);
|
||||||
|
setHP(getHP() + 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getMP() >= 10) {
|
||||||
|
super.heal(health);
|
||||||
|
setMP(getMP() - 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Not enough MP");
|
||||||
|
setSuccessfulAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage) {
|
||||||
|
if (!getArmor().checkBrake()) {
|
||||||
|
int finalDamage = ((WizardArmor) armor).absorbDamage(damage, getMP());
|
||||||
|
super.takeDamage(finalDamage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,8 @@ package org.project.item;
|
|||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
public interface Item {
|
public interface Item {
|
||||||
void use(Entity target);
|
|
||||||
|
|
||||||
/*
|
String getName();
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
void use();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,44 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.Item;
|
||||||
public abstract class Armor {
|
|
||||||
|
public abstract class Armor implements Item {
|
||||||
private int defense;
|
private int defense;
|
||||||
private int maxDefense;
|
private int maxDefense;
|
||||||
private int durability;
|
|
||||||
private int maxDurability;
|
|
||||||
|
|
||||||
private boolean isBroke;
|
|
||||||
|
|
||||||
public Armor(int defense, int durability) {
|
public Armor(int defense) {
|
||||||
this.defense = defense;
|
this.defense = defense;
|
||||||
this.durability = durability;
|
this.maxDefense = defense;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkBreak() {
|
|
||||||
if (durability <= 0) {
|
|
||||||
isBroke = true;
|
|
||||||
defense = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
|
||||||
public void repair() {
|
public void repair() {
|
||||||
isBroke = false;
|
|
||||||
defense = maxDefense;
|
defense = maxDefense;
|
||||||
durability = maxDurability;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefense() {
|
public int getDefense() {
|
||||||
return defense;
|
return defense;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDurability() {
|
public void setDefense(int defense) {
|
||||||
return durability;
|
this.defense = defense;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBroke() {
|
|
||||||
return isBroke;
|
public boolean checkBrake() {
|
||||||
|
return defense <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use() {
|
||||||
|
System.out.println(this.getClass().getSimpleName() + " equipped");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.project.item.armors;
|
||||||
|
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import org.project.item.armors.Armor;
|
||||||
|
|
||||||
|
public class AssassinArmor extends Armor {
|
||||||
|
|
||||||
|
private int HPPercentDamageReduction;
|
||||||
|
|
||||||
|
public AssassinArmor() {
|
||||||
|
super(15);
|
||||||
|
this.HPPercentDamageReduction = 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isLowHP(Player player) {
|
||||||
|
return (player.getHP() * 100 / player.getMaxHP()) < HPPercentDamageReduction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int reduceDamage(int damage, Player player) {
|
||||||
|
if (isLowHP(player)) {
|
||||||
|
return damage / 2;
|
||||||
|
}
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class KnightArmor {
|
public class KnightArmor extends Armor{
|
||||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
private int reflectPercent;
|
||||||
|
public KnightArmor() {
|
||||||
|
super(10);
|
||||||
|
this.reflectPercent = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReflectedDamage(int damage) {
|
||||||
|
return (int) (damage * reflectPercent / 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.project.item.armors;
|
||||||
|
|
||||||
|
public class WizardArmor extends Armor {
|
||||||
|
|
||||||
|
public WizardArmor() {
|
||||||
|
super(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int absorbDamage(int damage, int mp) {
|
||||||
|
int reduction = mp / 10; // every 10 MP absorbs 1 damage
|
||||||
|
return Math.max(0, damage - reduction);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,28 @@
|
|||||||
package org.project.item.consumables;
|
package org.project.item.consumables;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.entity.Entity;
|
||||||
public abstract class Consumable {
|
import org.project.item.Item;
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
public abstract class Consumable implements Item {
|
||||||
*/
|
private String name;
|
||||||
}
|
private int quantity;
|
||||||
|
|
||||||
|
public Consumable(String name, int quantity) {
|
||||||
|
this.name = name;
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void use(Entity target); // distinct from Item.use()
|
||||||
|
|
||||||
|
public boolean hasCharges() { return quantity > 0; }
|
||||||
|
|
||||||
|
protected void consume() { if (quantity > 0) quantity--; }
|
||||||
|
|
||||||
|
public int getQuantity() { return quantity; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() { return name; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use() { System.out.println("Use " + name + " on a target."); }
|
||||||
|
}
|
||||||
@@ -2,15 +2,28 @@ package org.project.item.consumables;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public class Flask extends Consumable {
|
||||||
public class Flask {
|
private int healAmount;
|
||||||
/*
|
private boolean isMana;
|
||||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
|
||||||
*/
|
public Flask(int healAmount, int quantity, boolean isMana) {
|
||||||
|
super(isMana ? "Mana Flask" : "Health Flask", quantity);
|
||||||
|
this.healAmount = healAmount;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: UPDATE USE METHOD
|
|
||||||
@Override
|
@Override
|
||||||
public void use(Entity target) {
|
public void use(Entity target) {
|
||||||
target.heal(target.getMaxHP() / 10);
|
if (!hasCharges()) {
|
||||||
|
System.out.println("Flask is empty!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isMana) {
|
||||||
|
target.setMP(target.getMP() + healAmount);
|
||||||
|
System.out.println(target.getClass().getSimpleName()
|
||||||
|
+ " restored " + healAmount + " MP!");
|
||||||
|
} else {
|
||||||
|
target.heal(healAmount);
|
||||||
|
}
|
||||||
|
consume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.project.item.weapons;
|
||||||
|
|
||||||
|
public class Bow extends Weapon{
|
||||||
|
|
||||||
|
private int abilityCharge;
|
||||||
|
private static int MAX_CHARGE = 4;
|
||||||
|
|
||||||
|
public Bow() {
|
||||||
|
super("Bow",15,25);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean charge() {
|
||||||
|
abilityCharge++;
|
||||||
|
if (abilityCharge >= MAX_CHARGE) {
|
||||||
|
abilityCharge = 0;
|
||||||
|
System.out.println("Charged Strike!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.project.item.weapons;
|
||||||
|
|
||||||
|
public class Dagger extends Weapon{
|
||||||
|
|
||||||
|
private static final int CRIT_CHANCE = 30;
|
||||||
|
|
||||||
|
|
||||||
|
public Dagger() {super("Dagger",8,15);}
|
||||||
|
|
||||||
|
public boolean critical() {
|
||||||
|
boolean isCrit = (int)(Math.random() * 100) < CRIT_CHANCE;
|
||||||
|
if (isCrit) System.out.println("Critical Hit");
|
||||||
|
return isCrit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,23 +4,24 @@ import org.project.entity.Entity;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public class Sword {
|
|
||||||
/*
|
|
||||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int abilityCharge;
|
public class Sword extends Weapon{
|
||||||
|
|
||||||
|
private int abilityCharge;
|
||||||
|
private static int MAX_CHARGE = 3;
|
||||||
|
|
||||||
public Sword() {
|
public Sword() {
|
||||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
super("Sword",12,10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
public boolean charge() {
|
||||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
abilityCharge++;
|
||||||
abilityCharge += 2;
|
if (abilityCharge >= MAX_CHARGE) {
|
||||||
for (Entity target : targets) {
|
abilityCharge = 0;
|
||||||
target.takeDamage(getDamage());
|
System.out.println("Charged Strike!");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,20 @@
|
|||||||
package org.project.item.weapons;
|
package org.project.item.weapons;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Weapon {
|
public abstract class Weapon implements Item {
|
||||||
|
private String name;
|
||||||
private int damage;
|
private int damage;
|
||||||
private int manaCost;
|
private int manaCost;
|
||||||
|
|
||||||
/*
|
public Weapon(String name, int damage, int manaCost) {
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
this.name = name;
|
||||||
*/
|
|
||||||
|
|
||||||
public Weapon(int damage, int manaCost) {
|
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
this.manaCost = manaCost;
|
this.manaCost = manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void use(Entity target) {
|
|
||||||
target.takeDamage(damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDamage() {
|
public int getDamage() {
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
@@ -29,7 +23,15 @@ public abstract class Weapon {
|
|||||||
return manaCost;
|
return manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@Override
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
public String getName() {
|
||||||
*/
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use() {
|
||||||
|
System.out.println(getName() + " equipped!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,22 @@ public class Location {
|
|||||||
|
|
||||||
private ArrayList<Enemy> enemies;
|
private ArrayList<Enemy> enemies;
|
||||||
|
|
||||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
public Location(String name, ArrayList<Enemy> enemies) {
|
||||||
this.locations = locations;
|
|
||||||
this.enemies = enemies;
|
this.enemies = enemies;
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getLocations() {
|
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Enemy> getEnemies() {
|
public ArrayList<Enemy> getEnemies() {
|
||||||
return enemies;
|
return enemies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String string = "Location: " + name + "| Enemies: " + enemies;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user