implement all Classes

This commit is contained in:
2026-05-16 10:14:04 +03:30
parent 78d4bedb08
commit 2da5f4dac7
34 changed files with 1032 additions and 396 deletions
+370 -5
View File
@@ -1,15 +1,380 @@
package org.project;
import org.project.entity.enemies.*;
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.location.Location;
import java.util.Scanner;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME
List<Location> locations = new ArrayList<>();
import static org.project.colors.ConsoleColor.*;
// TODO: IMPLEMENT GAMEPLAY
public class Main {
static boolean hasGoblinKey = false;
static boolean hasSkeletonKey = false;
static boolean hasVampireKey = false;
static boolean unlockedCastleL = false;
static int key = 0;
static int currentLocation = 0; // 0 = first location
public static void main(String[] args) {
List<Location> locations = new ArrayList<>();
ArrayList<Player> players = new ArrayList<>();
Player p1 = new Knight("Joan of Arc", 120, 80);
players.add(p1);
Player p2 = new Knight("Galahad", 120, 80);
players.add(p2);
Player p3 = new Wizard("Harry Potter", 90, 70);
players.add(p3);
Player p4 = new Assassin("Creed from Office", 70, 50);
players.add(p4);
ArrayList<Enemy> ghostTownEnemies = new ArrayList<>();
ghostTownEnemies.add(new Goblin(50, 10));
ghostTownEnemies.add(new Skeleton(50, 20));
ArrayList<Enemy> wreckShipEnemies = new ArrayList<>();
wreckShipEnemies.add(new Skeleton(55, 18));
wreckShipEnemies.add(new Vampire(75, 30));
wreckShipEnemies.add(new Vampire(75, 30));
wreckShipEnemies.add(new Vampire(75, 30));
wreckShipEnemies.add(new Vampire(75, 30));
wreckShipEnemies.add(new Vampire(75, 30));
ArrayList<Enemy> darkWoodEnemies = new ArrayList<>();
darkWoodEnemies.add(new Vampire(70, 28));
darkWoodEnemies.add(new Skeleton(60, 22));
darkWoodEnemies.add(new Vampire(70, 30));
darkWoodEnemies.add(new Vampire(75, 30));
darkWoodEnemies.add(new Vampire(55, 25));
darkWoodEnemies.add(new Vampire(60, 30));
darkWoodEnemies.add(new Vampire(75, 10));
darkWoodEnemies.add(new Goblin(45, 12));
Location l1 = new Location("GHOST TOWN", ghostTownEnemies);
locations.add(l1);
Location l2 = new Location("WRACK SHIP", wreckShipEnemies);
locations.add(l2);
Location l3 = new Location("DARK WOOD", darkWoodEnemies);
locations.add(l3);
Scanner scanner = new Scanner(System.in);
Random rand = new Random();
boolean player_isAlive;
boolean enemy_isAlive;
boolean player_isAlive_dragon;
boolean dragon_isAlive;
welcomeP();
System.out.println();
System.out.println(YELLOW + "Pick your player!" + RESET);
System.out.println();
System.out.println("1) " + p1.getName());
System.out.println("2) " + p2.getName());
System.out.println("3) " + p3.getName());
System.out.println("4) " + p4.getName());
System.out.println();
int pnum = scanner.nextInt();
System.out.println();
Player currentPlayer = players.get(pnum - 1);
while (true) {
showMenu();
int choose = scanner.nextInt();
switch (choose) {
case 1:
System.out.println(PURPLE + "You chose to Fight!" + RESET);
System.out.println();
Location selectedLocation = locations.get(currentLocation);
ArrayList<Enemy> locationEnemies = selectedLocation.getEnemies();
if (locationEnemies.isEmpty()) {
System.out.println("No enemies left in " + selectedLocation.getName() + "!");
System.out.println("Move to another location using option 2.");
break;
}
Enemy selectedEnemy = locationEnemies.get(rand.nextInt(locationEnemies.size()));
System.out.println("You as \"" + currentPlayer + "\" (" + currentPlayer.getClass().getSimpleName() + ')' + " and enemy as \"" +
selectedEnemy.getClass().getSimpleName() +
"\" will fight in " + selectedLocation + '!');
System.out.println();
enemy_isAlive = true;
player_isAlive = true;
while (enemy_isAlive && player_isAlive) {
System.out.println();
System.out.println(GREEN + "Your turn:" + RESET);
System.out.println("1) Light Attack | 2) Heavy Attack " + RED + "(-10 Mana) " + RESET + " | 3) Defend " + RED + "(-5 Mana)" + RESET + " | 4) Heal " + RED + "(-10 Mana)" + RESET + " | 5) Special Ability " + RED + "(-15 Mana)" + RESET);
int input = scanner.nextInt();
actions(selectedEnemy, currentPlayer, input);
if (selectedEnemy.getHp() <= 0) {
enemy_isAlive = false;
}
if (enemy_isAlive) {
System.out.println();
System.out.println(RED + selectedEnemy + "'s turn:" + RESET);
int enemyAction = rand.nextInt(4);
enemyAction(selectedEnemy, currentPlayer, enemyAction);
if (currentPlayer.getHp() <= 0) {
player_isAlive = false;
}
}
}
if (!enemy_isAlive) {
// Reset player HP/MP after battle
currentPlayer.setHp(currentPlayer.getMaxHP());
currentPlayer.setMp(currentPlayer.getMaxMP());
boolean dropped = keyDrop(selectedEnemy);
if (dropped) {
System.out.println(GREEN + "✨ A key dropped from the " + selectedEnemy.getClass().getSimpleName() + "! ✨" + RESET);
}
locationEnemies.remove(selectedEnemy);
if (key == 3) {
unlockedCastleL = true;
}
}
break;
case 2:
System.out.println();
System.out.println("Current location: " + locations.get(currentLocation).getName());
System.out.println();
for (int i = 0; i < locations.size(); i++) {
System.out.println((i + 1) + ") " + locations.get(i).getName());
}
System.out.println();
System.out.print("Choose location (1-3): ");
int newLoc = scanner.nextInt() - 1;
if (newLoc >= 0 && newLoc < locations.size()) {
currentLocation = newLoc;
System.out.println();
System.out.println("✨ You traveled to " + locations.get(currentLocation).getName() + "! ✨");
} else {
System.out.println("Invalid choice! You stay where you are.");
}
System.out.println();
break;
case 3:
if (key >= 3) {
System.out.println(GREEN + "You have all 3 keys! The castle gate opens..." + RESET);
System.out.println();
Dragon dragon = new Dragon(150, 50);
System.out.println("You as \"" + currentPlayer.getName() + "\" will fight the " + dragon + "!");
System.out.println();
player_isAlive_dragon = true;
dragon_isAlive = true;
while (dragon_isAlive && player_isAlive_dragon) {
System.out.println();
System.out.println(GREEN + "Your turn:" + RESET);
System.out.println("1) Light Attack | 2) Heavy Attack " + RED + "(-10 Mana) " + RESET + " | 3) Defend " + RED + "(-5 Mana)" + RESET + " | 4) Heal " + RED + "(-10 Mana)" + RESET + " | 5) Special Ability " + RED + "(-15 Mana)" + RESET);
int input = scanner.nextInt();
actions(dragon, currentPlayer, input);
if (dragon.getHp() <= 0) {
dragon_isAlive = false;
}
if (dragon_isAlive) {
System.out.println();
System.out.println(RED + "🐉 Dragon's turn:" + RESET);
int dragonAction = rand.nextInt(4);
enemyAction(dragon, currentPlayer, dragonAction);
System.out.println(currentPlayer.getName() + " HP: " + currentPlayer.getHp() + "/" + currentPlayer.getMaxHP());
if (currentPlayer.getHp() <= 0) {
player_isAlive_dragon = false;
}
}
}
if (!dragon_isAlive) {
System.out.println();
System.out.println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
System.out.println("🎉" + GREEN + " VICTORY! YOU DEFEATED THE DRAGON! " + RESET + "🎉");
System.out.println();
System.out.println(BOLD_GREEN + "" + "GAME COMPLETED" + "" + RESET);
System.out.println();
System.out.println(BOLD_BLUE + "Thanks for playing JAVAKNIGHT!" + RESET);
System.exit(0);
}
if (!player_isAlive_dragon) {
System.out.println();
System.out.println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
System.out.println("💀" + RED + " GAME OVER " + RESET + "💀");
System.out.println();
System.out.println("You were defeated by the Dragon...");
System.out.println("- Press Enter to exit");
scanner.next();
System.exit(0);
}
}
else {
System.out.println(RED + "You need all 3 keys first! (" + key + "/3 collected)" + RESET);
}
break;
default:
System.out.println(RED + "Invalid choice! Try again." + RESET);
break;
}
}
}
public static void showMenu() {
System.out.println(YELLOW + "Choose your next step" + RESET);
System.out.println();
System.out.println("1) Fight the enemy");
System.out.println("2) Move to another location");
System.out.println("3) Go to the castle to Fight the Dragon");
System.out.println();
}
public static void welcomeP() {
System.out.println();
System.out.println(BOLD_BLUE + " WELCOME TO JAVAKNIGHT" + RESET);
System.out.println();
System.out.println("To overcome this game you should first find all three keys by fighting" +
"\n 3 kinds of enemies. As you found them the final game" +
BOLD_RED + "\n \"Fighting the Dragon\"" + RESET +
"\n starts!");
}
public static void showLocations(List<Location> locations) {
System.out.println("Now in which location you would rather fight:");
for (int i = 1; i <= locations.size(); i++) {
System.out.println(i + ") " + locations.get(i - 1));
}
System.out.println();
}
public static void actions(Enemy enemy, Player player, int input) {
if (input == 1) {
System.out.println(YELLOW + "" + RESET + BLUE + " choose:" + RESET + " Light Attack");
System.out.println(player.getName() + " (" + player.getClass().getSimpleName() + ") used Light Attack! (0 Mana)");
player.attack(enemy);
} else if (input == 2) {
System.out.println(YELLOW + "" + RESET + BLUE + " choose:" + RESET + " Heavy Attack");
System.out.println(player.getName() + " (" + player.getClass().getSimpleName() + ") used Heavy Attack! (10 Mana)");
player.heavyAttack(enemy);
System.out.println(player.getName() + " Mana: " + player.getMp() + '/' + player.getMaxMP());
} else if (input == 3) {
System.out.println(YELLOW + "" + RESET + BLUE + " choose:" + RESET + " Defend");
System.out.println(player.getName() + " (" + player.getClass().getSimpleName() + ") used Defend! (5 Mana)");
player.defend();
System.out.println(player.getName() + " Mana: " + player.getMp() + '/' + player.getMaxMP());
} else if (input == 4) {
System.out.println(YELLOW + "" + RESET + BLUE + " choose:" + RESET + " Heal");
System.out.println(player.getName() + " (" + player.getClass().getSimpleName() + ") used Heal! (10 Mana)");
player.heal(15);
System.out.println(player.getName() + " HP: " + player.getHp() + '/' + player.getMaxHP());
System.out.println(player.getName() + " Mana: " + player.getMp() + '/' + player.getMaxMP());
} else if (input == 5) {
System.out.println(YELLOW + "" + RESET + BLUE + " choose:" + RESET + " Special Ability");
System.out.println(player.getName() + " (" + player.getClass().getSimpleName() + ") used Special Ability! (15 Mana)");
player.specialAbility(enemy);
System.out.println(enemy.getClass().getSimpleName() + " has " + enemy.getHp() + '/' + enemy.getMaxHP() + " HP remaining.");
System.out.println(player.getName() + " Mana: " + player.getMp() + '/' + player.getMaxMP());
} else {
System.out.println(RED + "Invalid input!" + RESET);
}
}
public static boolean keyDrop(Enemy enemy) {
String enemyType = enemy.getClass().getSimpleName();
if (enemyType.equals("Goblin")) {
if (!hasGoblinKey) {
int randN = (int)(Math.random() * 100) + 1;
if (randN <= 50) {
hasGoblinKey = true;
key++;
return true;
}
}
} else if (enemyType.equals("Skeleton")) {
if (!hasSkeletonKey) {
int randN = (int)(Math.random() * 100) + 1;
if (randN <= 25) {
hasSkeletonKey = true;
key++;
return true;
}
}
} else if (enemyType.equals("Vampire")) {
if (!hasVampireKey) {
int randN = (int)(Math.random() * 100) + 1;
if (randN <= 20) {
hasVampireKey = true;
key++;
return true;
}
}
}
return false;
}
public static void enemyAction(Enemy enemy, Player currentPlayer, int enemyAction) {
if (enemyAction == 0) {
enemy.resetDefend();
enemy.attack(currentPlayer);
System.out.println(currentPlayer.getName() + " has " + currentPlayer.getHp() + '/' + currentPlayer.getMaxHP() + " HP remaining.");
} else if (enemyAction == 1) {
enemy.defend();
if (enemy.isDefending()) {
System.out.println(enemy + " defended!");
} else {
System.out.println(enemy + " tried to defend but failed!");
}
} else if (enemyAction == 2) {
System.out.println(enemy + " tries to heal!");
enemy.heal(10);
System.out.println(enemy + " HP: " + enemy.getHp() + '/' + enemy.getMaxHP());
} else {
System.out.println(enemy + " uses SPECIAL ABILITY!");
enemy.specialAbility(currentPlayer);
System.out.println(currentPlayer.getName() + " has " + currentPlayer.getHp() + '/' + currentPlayer.getMaxHP() + " HP remaining.");
}
}
}
@@ -0,0 +1,25 @@
package org.project.colors;
public class ConsoleColor {
// RESET
public static final String RESET = "\u001B[0m";
// Regular Colors
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
// Bold Colors
public static final String BOLD_RED = "\u001B[31;1m";
public static final String BOLD_GREEN = "\u001B[32;1m";
public static final String BOLD_BLUE = "\u001B[34;1m";
public static final String BOLD_PURPLE = "\u001B[35;1m";
public static void victory(String message) {
System.out.println(BOLD_GREEN + "" + message + "" + RESET);
}
}
@@ -7,15 +7,17 @@ public interface Entity {
void heal(int health);
void fillMana(int mana);
void takeDamage(int damage);
int getMaxHP();
int getMaxMP();
int getHp();
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -0,0 +1,67 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.entity.players.Player;
public class Dragon extends Enemy {
public Dragon(int hp, int mp) {
super(hp, mp);
}
@Override
public void attack(Entity target) {
if (stunned) {
System.out.println("🐉 Dragon is STUNNED and cannot attack!");
stunned = false;
return;
}
System.out.println("🔥 DRAGON ATTACKS! 🔥");
// Dragon deals high damage (30-45 range)
int damageDealt = 30 + (int)(Math.random() * 16);
System.out.println("💨 The flames IGNORE your defense!");
System.out.println("Dragon deals " + damageDealt + " damage!");
target.takeDamage(damageDealt);
}
@Override
public void defend() {
if (mp >= 8) {
mp -= 8;
isDefending = true;
System.out.println("🐉 Dragon raises its scales! Defense increased!");
} else {
System.out.println("🐉 Dragon is too exhausted to defend!");
isDefending = false;
}
}
@Override
public void specialAbility(Entity target) {
if (mp >= 25) {
mp -= 25;
System.out.println("🌋 DRAGON USES FIRE BREATH! 🌋");
int damageDealt = 45 + (int)(Math.random() * 21);
System.out.println("💨 The flames INCINERATE everything!");
System.out.println("🔥 Your defense is USELESS against dragon fire!");
if (target instanceof Player) {
System.out.println("😵 You are STUNNED by the intense heat!");
}
target.takeDamage(damageDealt);
} else {
System.out.println("🐉 Dragon doesn't have enough MP for Fire Breath!");
System.out.println("Dragon uses normal attack instead!");
attack(target);
}
}
@Override
public String toString() {
return "Dragon (Final Boss) 🐉";
}
}
@@ -1,34 +1,96 @@
package org.project.entity.enemies;
import org.project.item.weapons.Weapon;
import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
Weapon weapon;
private int hp;
private int mp;
public abstract class Enemy implements Entity {
protected int hp;
protected int maxHp;
protected int mp;
protected int maxMp;
protected int damage;
protected boolean isDefending = false;
protected boolean stunned = false;
public Enemy(int hp, int mp, Weapon weapon) {
public Enemy(int hp, int mp) {
this.hp = hp;
this.maxHp = hp;
this.mp = mp;
this.maxMp = mp;
this.damage = 10;
}
this.weapon = weapon;
@Override
public void attack(Entity target) {
if (stunned) {
System.out.println(getClass().getSimpleName() + " is STUNNED and cannot attack!");
stunned = false;
return;
}
target.takeDamage(damage);
System.out.println(getClass().getSimpleName() + " deals " + damage + " damage!");
}
@Override
public void defend() {
if (mp >= 5) {
mp -= 5;
isDefending = true;
} else {
System.out.println(toString() + " doesn't have enough MP to defend!");
isDefending = false;
}
}
@Override
public void heal(int amount) {
if (mp >= 10) {
mp -= 10;
hp = Math.min(hp + amount, maxHp);
System.out.println(toString() + " heals " + amount + " HP!");
} else {
System.out.println(toString() + " doesn't have enough MP to heal!");
}
}
@Override
public void takeDamage(int damage) {
if (isDefending) {
damage = damage / 2;
System.out.println(toString() + " blocks half the damage!");
}
hp -= damage;
if (hp < 0) hp = 0;
}
public int getHp() {
return hp;
}
public abstract void specialAbility(Entity target);
public int getMp() {
return mp;
}
// Getters and Setters
public int getHp() { return hp; }
public Weapon getWeapon() {
return weapon;
public int getMaxHP() { return maxHp; }
public int getMp() { return mp; }
public int getMaxMP() { return maxMp; }
public int getDamage() { return damage; }
public void setDamage(int damage) { this.damage = damage; }
public boolean isDefending() { return isDefending; }
public void setDefending(boolean defending) { isDefending = defending; }
public void resetDefend() { isDefending = false; }
public boolean isStunned() { return stunned; }
public void resetStun() { stunned = false; }
public void stun() { stunned = true; }
@Override
public String toString() {
return getClass().getSimpleName();
}
}
}
@@ -0,0 +1,41 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
public class Goblin extends Enemy {
public Goblin(int hp, int mp) {
super(hp, mp);
}
@Override
public void attack(Entity target) {
if (stunned) {
System.out.println("Goblin is STUNNED and cannot attack!");
stunned = false;
return;
}
// 50% critical hit chance
boolean isCritical = Math.random() < 0.5;
int damageDealt = damage;
if (isCritical) {
damageDealt = damage * 2;
System.out.println("⚡ CRITICAL HIT! ⚡");
}
System.out.println("Goblin attacks for " + damageDealt + " damage!");
target.takeDamage(damageDealt);
}
@Override
public void specialAbility(Entity target) {
if (mp >= 15) {
mp -= 15;
target.takeDamage(10);
}
}
}
@@ -1,6 +1,58 @@
package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION
public class Skeleton {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
}
import org.project.entity.Entity;
public class Skeleton extends Enemy {
private boolean hasResurrected = false;
public Skeleton(int hp, int mp) {
super(hp, mp);
}
@Override
public void attack(Entity target) {
if (stunned) {
System.out.println("💀 Skeleton is STUNNED and cannot attack!");
stunned = false;
return;
}
int damageDealt = damage + (int)(Math.random() * 5);
System.out.println("💀 Skeleton attacks for " + damageDealt + " damage!");
target.takeDamage(damageDealt);
}
@Override
public void takeDamage(int damage) {
super.takeDamage(damage);
// Check for resurrection
if (hp <= 0 && !hasResurrected) {
resurrect();
}
}
private void resurrect() {
hasResurrected = true;
int revivedHp = maxHp / 2;
hp = revivedHp;
System.out.println("⚡💀 The Skeleton rises again with " + revivedHp + " HP! 💀⚡");
System.out.println("⚠️ Watch out! It's not over yet!");
}
@Override
public void specialAbility(Entity target) {
if (mp >= 15) {
mp -= 15;
System.out.println("💀 SKELETON THROWS BONE SHARDS! 💀");
int damageDealt = damage * 2;
System.out.println("Skeleton deals " + damageDealt + " damage from bone shards!");
target.takeDamage(damageDealt);
} else {
System.out.println("💀 Skeleton doesn't have enough MP for Bone Shards!");
attack(target);
}
}
}
@@ -0,0 +1,48 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
public class Vampire extends Enemy {
public Vampire(int hp, int mp) {
super(hp, mp);
}
@Override
public void attack(Entity target) {
if (stunned) {
System.out.println("🧛 Vampire is STUNNED and cannot attack!");
stunned = false;
return;
}
int damageDealt = damage + (int)(Math.random() * 8);
System.out.println("🧛 Vampire attacks for " + damageDealt + " damage!");
target.takeDamage(damageDealt);
// Lifesteal - heal for half damage
int healAmount = damageDealt / 2;
hp = Math.min(hp + healAmount, maxHp);
System.out.println("🩸 Vampire drains life and heals " + healAmount + " HP! (Now: " + hp + "/" + maxHp + ")");
}
@Override
public void specialAbility(Entity target) {
if (mp >= 20) {
mp -= 20;
System.out.println("🩸🧛 VAMPIRE USES BLOOD DRAIN! 🧛🩸");
int damageDealt = damage * 2 + 5;
System.out.println("Vampire deals " + damageDealt + " massive damage!");
target.takeDamage(damageDealt);
// Lifesteal - heal for FULL damage (stronger than normal attack)
int healAmount = damageDealt;
hp = Math.min(hp + healAmount, maxHp);
System.out.println("🩸 Vampire drains your life and heals " + healAmount + " HP! (Now: " + hp + "/" + maxHp + ")");
} else {
System.out.println("🧛 Vampire doesn't have enough MP for Blood Drain!");
attack(target);
}
}
}
@@ -0,0 +1,98 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import static org.project.colors.ConsoleColor.*;
public class Assassin extends Player {
private boolean isInvisible = false;
private boolean nextAttackCritical = false;
public Assassin(String name, int hp, int mp) {
super(name, hp, mp);
}
@Override
public void attack(Entity target) {
int damage = 8;
if (nextAttackCritical) {
damage = 22;
System.out.println(GREEN + "⚡ CRITICAL HIT! ⚡" + RESET);
nextAttackCritical = false;
}
target.takeDamage(damage);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
if (isInvisible) {
isInvisible = false;
System.out.println(YELLOW + "You are no longer invisible." + RESET);
}
}
@Override
public void heavyAttack(Enemy target) {
if (mp >= 10) {
mp -= 10;
int damage = 15;
if (nextAttackCritical) {
damage = 30;
System.out.println(GREEN + "⚡ CRITICAL HEAVY ATTACK! ⚡" + RESET);
nextAttackCritical = false;
}
target.takeDamage(damage);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
if (isInvisible) {
isInvisible = false;
System.out.println(YELLOW + "You are no longer invisible." + RESET);
}
} else {
System.out.println(RED + "Your MP is lower than 10!" + RESET);
}
}
@Override
public void specialAbility(Enemy target) {
if (mp >= 15) {
mp -= 15;
isInvisible = true;
nextAttackCritical = true;
System.out.println(GREEN + "✨ You turn invisible! ✨" + RESET);
System.out.println(CYAN + "Next attack will be a CRITICAL HIT!" + RESET);
} else {
System.out.println(RED + "Your MP is lower than 15!" + RESET);
}
}
@Override
public void takeDamage(int damage) {
if (isInvisible) {
System.out.println(GREEN + "You dodged the attack using invisibility!" + RESET);
isInvisible = false;
return;
}
super.takeDamage(damage);
}
@Override
public void heal(int health) {
super.heal(health);
System.out.println(name + " HP: " + hp + "/" + maxHP);
}
public boolean isInvisible() {
return isInvisible;
}
public boolean hasCriticalReady() {
return nextAttackCritical;
}
}
@@ -1,6 +1,55 @@
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.entity.enemies.Enemy;
import static org.project.colors.ConsoleColor.*;
public class Knight extends Player {
public Knight(String name, int hp, int mp) {
super(name, hp, mp);
}
@Override
public void attack(Entity target) {
int damage = 12;
target.takeDamage(damage);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
}
@Override
public void heavyAttack(Enemy target) {
if (mp >= 10) {
mp -= 10;
int damage = 22;
target.takeDamage(damage);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
} else {
System.out.println(RED + "Your MP is lower than 10!" + RESET);
}
}
@Override
public void specialAbility(Enemy target) {
if (mp >= 15) {
mp -= 15;
int damage = 18;
target.takeDamage(damage);
target.stun();
System.out.println(GREEN + "✨ KNIGHT USES SHIELD BASH! ✨" + RESET);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage and is STUNNED!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
} else {
System.out.println(RED + "Your MP is lower than 15!" + RESET);
}
}
@Override
public void heal(int health) {
super.heal(health);
System.out.println(name + " HP: " + hp + "/" + maxHP);
}
}
@@ -1,42 +1,56 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
import org.project.entity.enemies.Enemy;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player {
import static org.project.colors.ConsoleColor.*;
public abstract class Player implements Entity {
protected String name;
Weapon weapon;
Armor armor;
private int hp;
private int maxHP;
private int mp;
private int maxMP;
protected int hp;
protected int maxHP;
protected int mp;
protected int maxMP;
protected boolean isDefending = false;
protected boolean stunned = false;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
public Player(String name, int hp, int mp) {
this.name = name;
this.hp = hp;
this.maxHP = hp;
this.mp = mp;
this.weapon = weapon;
this.armor = armor;
this.maxMP = mp;
}
@Override
public void attack(Entity target) {
target.takeDamage(weapon.getDamage());
target.takeDamage(5);
}
@Override
public void defend() {
// TODO
if (mp >= 5) {
mp -= 5;
isDefending = true;
System.out.println(name + " is defending!");
} else {
System.out.println(RED + name + " doesn't have enough MP to defend!" + RESET);
}
}
@Override
public void takeDamage(int damage) {
hp -= damage - armor.getDefense();
if (isDefending) {
int reducedDamage = damage / 2;
System.out.println(name + " blocks the attack! Only takes " + reducedDamage + " damage.");
hp -= reducedDamage;
isDefending = false;
} else {
hp -= damage;
}
if (hp < 0) {
hp = 0;
}
}
@Override
@@ -45,45 +59,46 @@ public abstract class Player {
if (hp > maxHP) {
hp = maxHP;
}
System.out.println(name + " heals " + health + " HP!");
}
public void resetDefend() {
isDefending = false;
}
public void stun() {
stunned = true;
}
public boolean isStunned() {
return stunned;
}
public void resetStun() {
stunned = false;
}
public abstract void specialAbility(Enemy target);
public abstract void heavyAttack(Enemy target);
// Getters
public String getName() { return name; }
public int getHp() { return hp; }
public int getMaxHP() { return maxHP; }
public int getMp() { return mp; }
public int getMaxMP() { return maxMP; }
public boolean isDefending() { return isDefending; }
// Setters
public void setHp(int hp) {
this.hp = Math.min(hp, maxHP);
}
public void setMp(int mp) {
this.mp = Math.min(mp, maxMP);
}
@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
}
}
public String getName() {
public String toString() {
return name;
}
public int getHp() {
return hp;
}
@Override
public int getMaxHP() {
return maxHP;
}
public int getMp() {
return mp;
}
@Override
public int getMaxMP() {
return maxMP;
}
public Weapon getWeapon() {
return weapon;
}
public Armor getArmor() {
return armor;
}
}
}
@@ -0,0 +1,57 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import static org.project.colors.ConsoleColor.*;
public class Wizard extends Player {
public Wizard(String name, int hp, int mp) {
super(name, hp, mp);
}
@Override
public void attack(Entity target) {
int damage = 10;
target.takeDamage(damage);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
}
@Override
public void heavyAttack(Enemy target) {
if (mp >= 10) {
mp -= 10;
int damage = 18;
target.takeDamage(damage);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
} else {
System.out.println(RED + "Your MP is lower than 10!" + RESET);
}
}
@Override
public void specialAbility(Enemy target) {
if (mp >= 15) {
mp -= 15;
int damage = 15;
target.takeDamage(damage);
int healAmount = 25;
hp = Math.min(maxHP, hp + healAmount);
System.out.println(PURPLE + "✨ WIZARD USES LIFE DRAIN! ✨" + RESET);
System.out.println(target.getClass().getSimpleName() + " took " + RED + damage + RESET + " damage!");
System.out.println(name + " healed " + GREEN + healAmount + RESET + " HP!");
System.out.println(target.getClass().getSimpleName() + " has " + target.getHp() + '/' + target.getMaxHP() + " HP remaining.");
} else {
System.out.println(RED + "Your MP is lower than 15!" + RESET);
}
}
@Override
public void heal(int health) {
super.heal(health);
System.out.println(name + " HP: " + hp + "/" + maxHP);
}
}
@@ -1,11 +0,0 @@
package org.project.item;
import org.project.entity.Entity;
public interface Item {
void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -1,42 +0,0 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public abstract class Armor {
private int defense;
private int maxDefense;
private int durability;
private int maxDurability;
private boolean isBroke;
public Armor(int defense, int durability) {
this.defense = defense;
this.durability = durability;
}
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 boolean isBroke() {
return isBroke;
}
}
@@ -1,6 +0,0 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
@@ -1,8 +0,0 @@
package org.project.item.consumables;
// TODO: UPDATE IMPLEMENTATION
public abstract class Consumable {
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -1,16 +0,0 @@
package org.project.item.consumables;
import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION
public class Flask {
/*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
// TODO: UPDATE USE METHOD
@Override
public void use(Entity target) {
target.heal(target.getMaxHP() / 10);
}
}
@@ -1,26 +0,0 @@
package org.project.item.weapons;
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 Sword() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
}
}
}
@@ -1,35 +0,0 @@
package org.project.item.weapons;
import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION
public abstract class Weapon {
private int damage;
private int manaCost;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public Weapon(int damage, int manaCost) {
this.damage = damage;
this.manaCost = manaCost;
}
@Override
public void use(Entity target) {
target.takeDamage(damage);
}
public int getDamage() {
return damage;
}
public int getManaCost() {
return manaCost;
}
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -5,24 +5,25 @@ import org.project.entity.enemies.Enemy;
import java.util.ArrayList;
public class Location {
private String name;
private String locationName;
private ArrayList<Enemy> enemies;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
this.locations = locations;
public Location(String locationName, ArrayList<Enemy> enemies) {
this.locationName = locationName;
this.enemies = enemies;
}
public String getName() {
return name;
}
public ArrayList<Location> getLocations() {
return locations;
return locationName;
}
public ArrayList<Enemy> getEnemies() {
return enemies;
}
@Override
public String toString() {
return locationName;
}
}