20 Commits
Author SHA1 Message Date
HadiSharifi 3ab38fddce implement Flask class 2026-05-10 09:04:13 +03:30
HadiSharifi d509a8b999 fix some bugs 2026-05-10 08:51:02 +03:30
HadiSharifi d675c5421c update enemies 2026-05-10 08:02:05 +03:30
HadiSharifi 8b1da4b522 implement new armors 2026-05-10 00:24:53 +03:30
HadiSharifi 5e023fa6cd update enemies 2026-05-08 13:37:15 +03:30
HadiSharifi ed41752409 update game loop 2026-05-08 10:55:10 +03:30
HadiSharifi add61e75aa implement game loop 2026-05-07 22:00:42 +03:30
HadiSharifi b7c3086fd0 add key logic 2026-05-07 14:42:13 +03:30
HadiSharifi 65a72039bc update 2026-05-07 01:07:15 +03:30
HadiSharifi 29dbb6d7ad update entity 2026-05-07 00:17:11 +03:30
HadiSharifi 0a6c6034a3 update 2026-05-06 23:57:00 +03:30
HadiSharifi d6d2bdc24f update Entity and Location 2026-05-05 09:31:20 +03:30
HadiSharifi 3ea2250388 update enemies project 2026-05-05 09:20:36 +03:30
HadiSharifi b16f3a45a8 update players project 2026-05-05 00:04:45 +03:30
HadiSharifi 4935b9f901 update players project 2026-05-03 19:18:27 +03:30
HadiSharifi 2bfb6a891c add Wizard and Assassin class 2026-05-03 17:11:01 +03:30
HadiSharifi 82037fed3a update Player and Knight class 2026-05-03 16:44:17 +03:30
HadiSharifi be2abcb352 update Player class and Entity interface 2026-05-03 10:22:28 +03:30
HadiSharifi 187e672fe9 implement combatOptions interface 2026-05-03 09:27:59 +03:30
HadiSharifi 576a7553c6 change pom.xml to use JDK21 2026-05-03 09:24:05 +03:30
43 changed files with 1161 additions and 120 deletions
+2 -2
View File
@@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+179 -4
View File
@@ -1,15 +1,190 @@
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 java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME
List<Location> locations = new ArrayList<>();
Weapon wp = new Sword();
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;
import org.project.item.weapons.Weapon;
public interface Entity {
void attack(Entity target);
@@ -7,15 +9,42 @@ public interface Entity {
void heal(int health);
void fillMana(int mana);
void takeDamage(int damage);
void takeDamage(int damage, Entity target);
int getHP();
void setHP(int hp);
int getMaxHP();
int getMP();
void setMP(int mana);
void setMaxHP(int maxHP);
int getMaxMP();
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
void setMaxMP(int maxMP);
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;
import org.project.entity.Entity;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
public abstract class Enemy implements Entity {
Weapon weapon;
private int hp;
private int maxHP;
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) {
this.hp = hp;
this.maxHP = hp;
this.mp = mp;
this.maxMP = mp;
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
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() {
return hp;
@Override
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;
}
@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() {
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;
// TODO: UPDATE IMPLEMENTATION
public class Skeleton {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
import org.project.entity.Entity;
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;
// TODO: UPDATE IMPLEMENTATION
public class Knight {
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
import org.project.entity.Entity;
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;
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.consumables.Consumable;
import org.project.item.consumables.Flask;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player {
public abstract class Player implements Entity, CombatOptions {
protected String name;
Weapon weapon;
Armor armor;
@@ -13,46 +17,85 @@ public abstract class Player {
private int maxHP;
private int mp;
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) {
this.name = name;
this.hp = hp;
this.maxHP = hp;
this.mp = mp;
this.maxMP = mp;
this.weapon = weapon;
this.armor = armor;
}
@Override
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
public void defend() {
// TODO
public void heavyAttack(Entity target) {
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
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
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
}
@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
}
setSuccessfulAction(true);
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
setHP(getHP() + health);
}
@@ -60,24 +103,59 @@ public abstract class Player {
return name;
}
public int getHp() {
@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;
}
public int getMp() {
@Override
public void setMaxHP(int maxHP) {
this.maxHP = maxHP;
}
@Override
public int getMP() {
return mp;
}
@Override
public void setMP(int mana) {
mp = mana;
if (mp > maxMP) {
mp = maxMP;
} else if (mp < 0) {
mp = 0;
}
}
@Override
public int getMaxMP() {
return maxMP;
}
@Override
public void setMaxMP(int maxMP) {
this.maxMP = maxMP;
}
@Override
public Weapon getWeapon() {
return weapon;
}
@@ -86,4 +164,56 @@ public abstract class Player {
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;
public interface Item {
void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
String getName();
void use();
}
@@ -1,42 +1,44 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public abstract class Armor {
import org.project.item.Item;
public abstract class Armor implements Item {
private int defense;
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.durability = durability;
this.maxDefense = defense;
}
public void checkBreak() {
if (durability <= 0) {
isBroke = true;
defense = 0;
}
}
// TODO: (BONUS) UPDATE THE REPAIR METHOD
public void repair() {
isBroke = false;
defense = maxDefense;
durability = maxDurability;
}
public int getDefense() {
return defense;
}
public int getDurability() {
return durability;
public void setDefense(int defense) {
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;
// TODO: UPDATE IMPLEMENTATION
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
public class KnightArmor extends Armor{
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;
// TODO: UPDATE IMPLEMENTATION
public abstract class Consumable {
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
import org.project.entity.Entity;
import org.project.item.Item;
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;
// TODO: UPDATE IMPLEMENTATION
public class Flask {
/*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
public class Flask extends Consumable {
private int healAmount;
private boolean isMana;
public Flask(int healAmount, int quantity, boolean isMana) {
super(isMana ? "Mana Flask" : "Health Flask", quantity);
this.healAmount = healAmount;
}
// TODO: UPDATE USE METHOD
@Override
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;
// 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() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
super("Sword",12,10);
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
public boolean charge() {
abilityCharge++;
if (abilityCharge >= MAX_CHARGE) {
abilityCharge = 0;
System.out.println("Charged Strike!");
return true;
}
return false;
}
}
@@ -1,26 +1,20 @@
package org.project.item.weapons;
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 manaCost;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public Weapon(int damage, int manaCost) {
public Weapon(String name, int damage, int manaCost) {
this.name = name;
this.damage = damage;
this.manaCost = manaCost;
}
@Override
public void use(Entity target) {
target.takeDamage(damage);
}
public int getDamage() {
return damage;
}
@@ -29,7 +23,15 @@ public abstract class Weapon {
return manaCost;
}
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
@Override
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;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
this.locations = locations;
public Location(String name, ArrayList<Enemy> enemies) {
this.enemies = enemies;
this.name = name;
}
public String getName() {
return name;
}
public ArrayList<Location> getLocations() {
return locations;
}
public ArrayList<Enemy> getEnemies() {
return enemies;
}
@Override
public String toString() {
String string = "Location: " + name + "| Enemies: " + enemies;
return string;
}
}
Binary file not shown.