implement all Classes
This commit is contained in:
Generated
+5
@@ -16,5 +16,10 @@
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://mirror-maven.runflare.com/maven2" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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.
@@ -1,175 +1,68 @@
|
||||
# Fourth Assignment - Java Knight ⚔️
|
||||
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
||||
# ⚔️ Java Knight A Turn-Based PRG
|
||||
___
|
||||
## 📜 A Little About the Game
|
||||
Java Knight is a text-based role-playing game where you battle creatures to collect keys so you can unlock final game and save the old castle!
|
||||
|
||||
### **Prologue: The Legend of Javanest**
|
||||
*For centuries, the land of Javanest lived in peace, until a magical Dragon attacked, plunging the realm into absolute darkness. With a wicked curse, the Dragon transformed the innocent people into horrific monsters: Goblins, Skeletons, and Vampires. Retreating to its impenetrable Castle, the Dragon divided the three keys to its lair and hid them among these cursed creatures. Now, it is your duty to step up and save the land. You must battle these monsters, recover the unique key from each monster type, and finally slay the Dragon to break the curse and restore peace to Javanest!*
|
||||
## 🎮 How to Play
|
||||
**select your hero** - choose from 4 players : Joan of Arc (the Knight), Galahad (the knight), Harry Potter (the Wizard), Creed from Office (the Assassin)
|
||||
|
||||
### **Introduction**
|
||||
Welcome to **Java knight**, a turn-based RPG inspired by Roguelike games! In this assignment, you will develop a **text-based role-playing game (RPG)**. This project is designed to rigorously test your understanding of **Object-Oriented Programming (OOP) principles**.
|
||||
**fight enemies** - choose any location and then their specific enemies will appear to fight !
|
||||
|
||||
⚠️ **REQUIREMENT:** You **must** utilize all the OOP concepts you have learned so far—including *Inheritance, Interfaces, Abstract Classes, Encapsulation, Polymorphism, Overloading, and Overriding*. It is extremely important that you use everything in its right place. Your design and architecture will be graded based on how well you apply these principles to avoid code duplication and maintain a clean structure.
|
||||
**defeat the final boss** - once you collect all 3 keys you can face the Dragon
|
||||
|
||||
🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!**
|
||||
|
||||
### **What is a Turn-Based Game?**
|
||||
In this combat system, two sides - which are usually the player's side and the enemy's side - attack each other in turns. The side which is not attacking can perform actions to avoid or deflect the enemy's attack.
|
||||
|
||||
### **Core Mechanics:**
|
||||
- **Turn-based combat** – Players and monsters take turns attacking each other.
|
||||
- **Character classes with Unique Traits** – Players can choose from archetypes like **Knight, Assassin, or Wizard**, each starting with distinctly different base stats.
|
||||
- **Unified Mana/Stamina System** – All player classes use a unified resource (Mana/Stamina) to perform actions.
|
||||
- **Standardized Action Set** – Every player character has exactly 5 specific actions available during their turn.
|
||||
- **Experience & Leveling System** – Earn XP based on enemy strength to automatically level up and increase your base stats.
|
||||
- **Progression System** – You cannot fight the Dragon immediately. You must farm enemies for a chance to drop their specific key, collect all three, and grow stronger first.
|
||||
|
||||
---
|
||||
|
||||
## Tasks 📝
|
||||
|
||||
### 1️⃣ Step 1: Fork & Setup 🍴
|
||||
1. **Fork** this repository and clone it to your local machine.
|
||||
```bash
|
||||
git clone https://git.meshcomp.ir/AdvancedProgramming1404/HW-04-JAVA-KNIGHT.git
|
||||
```
|
||||
2. Create a new branch named `develop` and switch to it.
|
||||
```bash
|
||||
git checkout -b develop
|
||||
```
|
||||
### 2️⃣ Step 2: Implement the Class Hierarchy 🌲
|
||||
|
||||
A well-structured OOP hierarchy is crucial. Avoid duplicating code by placing shared logic in abstract classes.
|
||||
|
||||
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`.
|
||||
- **Players:** `Player` is an abstract class implementing `Entity`. Subclasses: `Wizard`, `Knight`, `Assassin`.
|
||||
- **Base Stat Differences:** Each class must have distinct starting stats. For example:
|
||||
- **Knight:** Highest Base Damage.
|
||||
- **Wizard:** Highest Max Health (HP).
|
||||
- **Assassin:** Highest Max Stamina/Mana.
|
||||
- **Enemies:** `Enemy` is an abstract class implementing `Entity`. Subclasses: `Skeleton`, `Goblin`, `Vampire`, and **`Dragon`**.
|
||||
- **The Boss:** Even though `Dragon` is the final boss, it **must** be a subclass of `Enemy` to inherit common combat properties, while possessing extremely high stats and unique mechanics.
|
||||
- **Item (Bonus):** `Consumable`, `Armor`, `Weapon` are abstract classes implementing `Item`. example :
|
||||
- KnightArmor extends Armor - you can add more subclasses of Armor for extra score
|
||||
- Sword extends Weapon - you can add more subclasses of Weapon for extra score
|
||||
- Flask extends Consumable - you can add more subclasses of Consumable for extra score
|
||||
|
||||

|
||||
|
||||
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
|
||||
|
||||
**Player Actions (The Rule of Five):**
|
||||
Every player class **must** implement exactly the following 5 actions (You can use an interface like `ICombatActions`). Every action (except Light Attack) consumes a specific amount of Mana/Stamina. The **Special Ability** must consume the *highest* amount of Mana compared to the others.
|
||||
1. **Light Attack:** Deals moderate damage and costs **NO Mana**. (Note: If the player runs out of Mana/Stamina, this is the ONLY action they can perform.)
|
||||
2. **Heavy Attack:** Deals high damage, medium Mana cost.
|
||||
3. **Defend:** Completely blocks or significantly reduces the damage of the enemy's *next* strike. Medium Mana cost.
|
||||
4. **Heal:** Restores a portion of the player's HP. Medium-high Mana cost.
|
||||
5. **Special Ability:** A unique class-based ultimate move (Highest Mana cost):
|
||||
- **Wizard** 🧙♂️: Casts a devastating spell that damages the enemy while simultaneously replenishing some HP.
|
||||
- **Assassin** 🗡️: Turns invisible, dodging the next incoming attack completely and guaranteeing a *Critical Hit* on their next turn.
|
||||
- **Knight** ⚔️: Performs a shield bash that stuns the enemy, forcing them to skip their next turn while dealing heavy damage.
|
||||
|
||||
**Monster Abilities:**
|
||||
- **Goblin** 👹: High critical hit chance but low health.
|
||||
- **Skeleton** ☠️: Can resurrect once per battle with 50% HP.
|
||||
- **Vampire** 🦇: Lifesteal ability – a portion of the damage it deals to the player is added back to its own health.
|
||||
- **Dragon (Final Boss)** 🐉: Immune to normal defense. Its fiery breath bypasses shields and deals massive damage.
|
||||
|
||||
🔹 Make sure each entity **prints messages** when performing actions. example output (while in combat) :
|
||||
|
||||
```bash
|
||||
You chose to FIGHT!
|
||||
|
||||
[Ser Duncan - 45/45 HP | 40/40 Mana]
|
||||
[Goblin - 30/30 HP]
|
||||
|
||||
---
|
||||
|
||||
Your Turn:
|
||||
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
|
||||
```
|
||||
|
||||
```bash
|
||||
→ Chose: Light Attack
|
||||
⚔️ Ser Duncan (Knight) used Light Attack! (0 Mana)
|
||||
Goblin took 10 damage!
|
||||
Goblin has 20/30 HP remaining.
|
||||
Ser Duncan Mana: 40/40
|
||||
```
|
||||
```
|
||||
Goblin's Turn :
|
||||
👹 Goblin used Critical Strike!
|
||||
💥 Critical hit! Ser Duncan took 20 damage!
|
||||
Ser Duncan has 25/45 HP remaining.
|
||||
```
|
||||
🔹 *Narrative Console:* Use ANSI escape codes to print colorful narrative logs (e.g., Red for damage, Blue for Mana usage, Green for healing).
|
||||
## 🌲 Class Hierarchy
|
||||
Entity (Interface)
|
||||
|
||||
|
||||
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
|
||||
├── Player (Abstract Class)
|
||||
|
||||
1. **The Core Loop:** The game starts with the player entering a location. A random standard enemy (`Goblin`, `Skeleton`, or `Vampire`) spawns immediately.
|
||||
2. **Player Choices:** Before engaging, the player is presented with the following options:
|
||||
- **1. Fight the enemy:** Enter the turn-based combat sequence.
|
||||
- **2. Move to another location:** Skip the current enemy and spawn a new random one.
|
||||
- **3. Go to the Castle to fight the Dragon:** *(Note: This option must remain strictly hidden or locked until the player has successfully collected all 3 keys).*
|
||||
3. **The Key Drop Logic (RNG Gatekeeping):**
|
||||
- When the player defeats an enemy, there is a **specific percentage chance (e.g., 20%)** that it will drop the unique key associated with its species (Goblin Key, Skeleton Key, Vampire Key).
|
||||
- **One Key Per Species:** Once a player obtains a specific key (e.g., Goblin Key), subsequent enemies of that same type (other Goblins) will **never** drop a key again.
|
||||
- The player **must collect all 3 distinct keys** to unlock Option 3 and enter the Castle.
|
||||
4. **Post-Combat Recovery:** After each successful battle, the player's HP and Mana bars must automatically replenish (either fully or partially) to their base amounts so they are ready for the next encounter.
|
||||
5. **Experience & Leveling System:**
|
||||
- Defeating an enemy grants **XP**. The amount of XP must scale proportionally to the enemy's power level.
|
||||
- Upon reaching an XP threshold, the player levels up. **Leveling up must automatically increase the player's Max HP and Max Stamina/Mana**, making them strong enough to eventually face the Dragon.
|
||||
6. **Final Boss Fight:** Once the 3 Keys are obtained and the player chooses to go to the Castle, they will face the Dragon. Defeating the Dragon breaks the curse, resulting in **Victory**. Dying at any point results in **Game Over**.
|
||||
│ ├── Knight
|
||||
|
||||
🔹 Example game loop structure:
|
||||
│ ├── Wizard
|
||||
|
||||
```java
|
||||
while (player.isAlive() && enemy.isAlive())
|
||||
player.attack(enemy);
|
||||
if (enemy.isAlive()) {
|
||||
enemy.attack(player);
|
||||
}
|
||||
}
|
||||
```
|
||||
│ └── Assassin
|
||||
|
||||
│
|
||||
|
||||
└── Enemy (Abstract Class)
|
||||
|
||||
├── Goblin
|
||||
|
||||
├── Skeleton
|
||||
|
||||
├── Vampire
|
||||
|
||||
└── Dragon
|
||||
|
||||
## ✔ Where & How OOP Concepts Are Used
|
||||
|
||||
### 1. Encapsulation
|
||||
|
||||
Where | How
|
||||
----- |-----
|
||||
***Player Class*** | `hp`, `mp`, `isDefending` are `protected` - accessed via getters/setters
|
||||
***Enemy Class*** | `damage`, `stunned`, `isDefending` are `protected` - accessed via methods
|
||||
|
||||
|
||||
### 5️⃣ Step 5: Extra Features & Bonus Tasks ⭐
|
||||
*(Optional for extra credit)*
|
||||
### 2. Inheritance
|
||||
|
||||
✅ **Dynamic Economy & Merchant System:** Implement coins that drop from enemies. Add a "Visit Merchant" option to the main loop where players can spend coins to buy specific weapons, armors, or consumables.
|
||||
✅ **Multiple Weapons & Inventory:** Players can buy, store, and swap between multiple weapons or use consumables mid-combat.
|
||||
✅ **Multiplayer/Party Mode:** Allow multiple players to team up and fight multiple enemies together. The Dragon's breath attack will damage the entire party simultaneously.
|
||||
✅ **PvP Mode:** Implement a **Player vs. Player** combat system.
|
||||
Parent Class | Child Classes | What Children Inherit
|
||||
------------------ |-------------------------------------------| ----------
|
||||
***Player*** | `Knight`, `Wizard`, `Assassin` | `hp`, `mp`, `defend`, etc.
|
||||
***Enemy*** | `Goblin`, `Skeleton`, `Vampire`, `Dragon` | `hp`, `mp`, `stunned`, `defend`, etc.
|
||||
|
||||
### 6️⃣ Step 6: Write a Comprehensive README 📄
|
||||
As the final mandatory step of your development, you must replace the default `README.md` with your own comprehensive documentation. Your README should include:
|
||||
- A brief introduction to the game.
|
||||
- How to compile and run your project from the terminal.
|
||||
- An explanation of the classes, design patterns, and OOP principles you used.
|
||||
- A brief guide on how to play (controls, stats, classes).
|
||||
|
||||
---
|
||||
### 3. Polymorphism
|
||||
|
||||
## Evaluation Criteria ⚖
|
||||
***Method Overriding***
|
||||
|
||||
| **Criteria** | **Points** |
|
||||
|-------------------------------------------------------------|------------|
|
||||
| Proper use of OOP principles | **50** |
|
||||
| Working combat mechanics, Leveling System & Enemy abilities | **20** |
|
||||
| Clear and Comprehensive `README.md` | **20** |
|
||||
| Code readability, documentation, and comments | **10** |
|
||||
| Meaningful, interactive, & colored console outputs | **10** |
|
||||
| Inventory (item) and Merchant System (bonus) | **20** |
|
||||
| Other Extra features (bonus tasks) | **20** |
|
||||
| **Total Score** | **150** |
|
||||
Method | Parent Behavior | Child Behavior
|
||||
------ | --------------- | --------------
|
||||
`attack()` | Deals 5 Damage | Knight: 12 d, Wizard: 10 d, Assassin: 8 d
|
||||
`specialAbility()` | Abstract | Knight: Sheild Bash + Stun, Wizard: Life Drain + Heal, Assassin: Invisibility
|
||||
`heavyAttack()` | Abstract | Knight: 22 d, Wizard: 18 d, Assassin: 15 d
|
||||
|
||||
## Tips 🚀
|
||||
- **Follow OOP principles**: Avoid redundant code by using inheritance properly. Think carefully about what belongs in an abstract class vs. a specific subclass. Make sure you use overriding and overloading correctly.
|
||||
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected.
|
||||
- **Ask for help**: If you're stuck, reach out to your classmates or mentors.
|
||||
### 4. Abstraction & Interface
|
||||
Player and Enemy Classes are Abstract Which Implement Entity as Interface.
|
||||
|
||||
## Submission ⌛
|
||||
- **Deadline**: Submit your assignment before **21 Ordibehesht (May 11th, 2026)**.
|
||||
- **Submission Format**: Push your code to your forked repository, create a PR, and ensure your comprehensive `README.md` is included in the root directory.
|
||||
|
||||

|
||||
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.
|
||||
Methods like `specialAbility()` (In Player and Enemy Classes) and `heavyAttack()` (Just Player Class) are abstract.
|
||||
Reference in New Issue
Block a user