Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d25378c453 | ||
|
|
2fd072057a | ||
|
|
2ec3641f00 |
Generated
+5
@@ -10,4 +10,9 @@
|
|||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="JavacSettings">
|
||||||
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="Java-Knight" options="--add-exports java.desktop/sun.swing=ALL-UNNAMED" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+5
@@ -16,5 +16,10 @@
|
|||||||
<option name="name" value="JBoss Community repository" />
|
<option name="name" value="JBoss Community repository" />
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
</remote-repository>
|
</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>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,15 +1,185 @@
|
|||||||
package org.project;
|
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.item.armors.Armor;
|
||||||
|
import org.project.item.armors.KnightArmor;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
import org.project.location.Location;
|
import org.project.location.Location;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Scanner;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
|
||||||
List<Location> locations = new ArrayList<>();
|
|
||||||
|
|
||||||
// TODO: IMPLEMENT GAMEPLAY
|
public static void printBorder() {
|
||||||
|
for (int i = 0; i < 40; i++)
|
||||||
|
System.out.print("-");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printBorder(int x) {
|
||||||
|
for (int i = 0; i < 15; i++)
|
||||||
|
System.out.println();
|
||||||
|
for (int i = 0; i < x; i++)
|
||||||
|
System.out.print("-");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int moveSelector() {
|
||||||
|
System.out.println("Choose your move:");
|
||||||
|
System.out.println("1. Light attack (Mana: 0) | 2. Normal attack (mana: 2) | 3. Heavy attack (mana: 3)");
|
||||||
|
System.out.println("4. Heal (5 mana) | 5. Skip");
|
||||||
|
Scanner in = new Scanner(System.in);
|
||||||
|
while (true) {
|
||||||
|
int answer = in.nextInt();
|
||||||
|
if (answer == 1 || answer == 2 || answer == 3 || answer == 4 || answer == 5)
|
||||||
|
return answer;
|
||||||
|
System.out.println("Invalid input try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fightEnemy(Player player, Location location, String enemyName, String locationDesc) {
|
||||||
|
String RED = "\u001B[31m";
|
||||||
|
String YELLOW = "\u001B[33m";
|
||||||
|
String RESET = "\u001B[0m";
|
||||||
|
|
||||||
|
System.out.printf("You're in the %s fighting a %s%s%s!\n", locationDesc, RED, enemyName, RESET);
|
||||||
|
|
||||||
|
while (player.isAlive() && location.getEnemy().getHP() > 0) {
|
||||||
|
// Player's turn: up to 5 actions
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
System.out.printf("%s | %sHP%s: %d, %sMP%s: %d\n",
|
||||||
|
player.getName(), RED, RESET, player.getHP(), YELLOW, RESET, player.getMP());
|
||||||
|
printBorder();
|
||||||
|
System.out.printf("%s | %sHP%s: %d, %sMP%s: %d\n",
|
||||||
|
enemyName, RED, RESET, location.getEnemy().getHP(), YELLOW, RESET, location.getEnemy().getMP());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
switch (moveSelector()) {
|
||||||
|
case 1: // Base Attack
|
||||||
|
location.getEnemy().takeDamage(player.getBaseDamage());
|
||||||
|
break;
|
||||||
|
case 2: // Normal Attack (2 mana)
|
||||||
|
if (player.useMana(2)) {
|
||||||
|
player.attack(location.getEnemy());
|
||||||
|
} else {
|
||||||
|
System.out.println("Not enough mana for Normal Attack!");
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3: // Heavy Attack (3 mana)
|
||||||
|
if (player.useMana(3)) {
|
||||||
|
player.heavyAttack(location.getEnemy());
|
||||||
|
} else {
|
||||||
|
System.out.println("Not enough mana for Heavy Attack!");
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4: // Heal (5 mana)
|
||||||
|
if (player.useMana(5)) {
|
||||||
|
player.heal(20);
|
||||||
|
} else {
|
||||||
|
System.out.println("Not enough mana to Heal!");
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printBorder();
|
||||||
|
|
||||||
|
// If enemy died or player died, end the player's turn early
|
||||||
|
if (location.getEnemy().getHP() <= 0 || !player.isAlive()) {
|
||||||
|
location.getEnemy().getKilled();
|
||||||
|
i = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enemy's turn
|
||||||
|
if (location.getEnemy().getHP() > 0) {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
location.getEnemy().attack(player);
|
||||||
|
printBorder();
|
||||||
|
if (!player.isAlive())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore mana after each full round
|
||||||
|
player.fillMana(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String RED = "\u001B[31m";
|
||||||
|
String YELLOW = "\u001B[33m";
|
||||||
|
String RESET = "\u001B[0m";
|
||||||
|
String GREEN = "\u001B[32m";
|
||||||
|
|
||||||
|
printBorder();
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
System.out.println("Enter your name:");
|
||||||
|
String name = input.next();
|
||||||
|
printBorder();
|
||||||
|
|
||||||
|
Weapon sword = new Sword();
|
||||||
|
Armor armor = new KnightArmor();
|
||||||
|
Player player = null;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Chose your character:");
|
||||||
|
System.out.printf("1. Knight | %sHP%s: 100, %sMP%s: 10\n", RED, RESET, YELLOW, RESET);
|
||||||
|
System.out.printf("2. Wizard | %sHP%s: 150, %sMP%s: 10\n", RED, RESET, YELLOW, RESET);
|
||||||
|
System.out.printf("3. Assassin | %sHP%s: 80 , %sMP%s: 20\n", RED, RESET, YELLOW, RESET);
|
||||||
|
player = switch (input.nextInt()) {
|
||||||
|
case 1 -> new Knight(name, sword, armor);
|
||||||
|
case 2 -> new Wizard(name, sword, armor);
|
||||||
|
case 3 -> new Assassin(name, sword, armor);
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (player == null) {
|
||||||
|
System.out.println("Invalid input try again.");
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location overworld = new Location("Overworld", new Vampire(sword));
|
||||||
|
Location village = new Location("Village", new Goblin(sword));
|
||||||
|
Location nether = new Location("Nether", new Skeleton(sword));
|
||||||
|
Location end = new Location("End", new Dragon());
|
||||||
|
|
||||||
|
// Fight each enemy
|
||||||
|
fightEnemy(player, overworld, "Vampire", "Overworld");
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
System.out.println("You lost!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fightEnemy(player, village, "Goblin", "Village");
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
System.out.println("You lost!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fightEnemy(player, nether, "Skeleton", "Nether");
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
System.out.println("You lost!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fightEnemy(player, end, "Dragon","End");
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
System.out.println("You lost!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printBorder();
|
||||||
|
System.out.println(GREEN + " " + RESET);
|
||||||
|
System.out.println(RED + " VICTORY! " + RESET);
|
||||||
|
System.out.println(GREEN + " You have conquered all enemies! " + RESET);
|
||||||
|
System.out.println(GREEN + " The realm is safe, brave warrior. " + RESET);
|
||||||
|
System.out.println();
|
||||||
|
printBorder();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
public interface Entity {
|
||||||
void attack(Entity target);
|
|
||||||
|
|
||||||
void defend();
|
void attack(Entity target);
|
||||||
|
|
||||||
void heal(int health);
|
void heal(int health);
|
||||||
|
|
||||||
@@ -14,8 +13,4 @@ public interface Entity {
|
|||||||
int getMaxHP();
|
int getMaxHP();
|
||||||
|
|
||||||
int getMaxMP();
|
int getMaxMP();
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.DragonBreath;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
|
public class Dragon extends Enemy{
|
||||||
|
public Dragon() {
|
||||||
|
int baseDamage = 2;
|
||||||
|
int hp = 500;
|
||||||
|
int mp = 1000;
|
||||||
|
Weapon weapon1 = new DragonBreath();
|
||||||
|
super(hp, mp, weapon1, baseDamage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage) {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
if(!isAlive)
|
||||||
|
getKilled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getKilled() {
|
||||||
|
isAlive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
target.takeDamage((weapon.getDamage() + getBaseDamage()));
|
||||||
|
System.out.println("\u001B[31mDragon breathes a raging fire!\u001B[0m");
|
||||||
|
System.out.printf("\u001B[31mYou took %d damage.\u001B[0m\n", weapon.getDamage() + getBaseDamage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getHP() + health > getMaxHP())
|
||||||
|
setHP(getMaxHP());
|
||||||
|
else
|
||||||
|
setHP(getHP()+ health);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillMana(int mana) {
|
||||||
|
if (getMP() + mana > getMaxMP())
|
||||||
|
setMP(getMaxMP());
|
||||||
|
else
|
||||||
|
setMP(getMP()+ mana);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHP() {
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMP() {
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,33 +1,57 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Enemy implements Entity {
|
||||||
public abstract class Enemy {
|
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
|
boolean isAlive;
|
||||||
private int hp;
|
private int hp;
|
||||||
private int mp;
|
private int mp;
|
||||||
|
private int baseDamage;
|
||||||
|
|
||||||
public Enemy(int hp, int mp, Weapon weapon) {
|
public Enemy(int hp, int mp, Weapon weapon, int baseDamage) {
|
||||||
|
this.baseDamage = baseDamage;
|
||||||
|
isAlive = true;
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
|
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHP(int hp) {
|
||||||
|
this.hp = hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMP(int mp) {
|
||||||
|
this.mp = mp;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
|
if (0 >= (hp - damage)) {
|
||||||
|
isAlive = false;
|
||||||
|
hp = 0;
|
||||||
|
System.out.println("\u001B[32myou killed your enemy\u001B[0m");
|
||||||
|
return;
|
||||||
|
}
|
||||||
hp -= damage;
|
hp -= damage;
|
||||||
|
System.out.printf("\u001B[31mEnemy took %d damage.\u001B[0m\n", damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp() {
|
public abstract void getKilled();
|
||||||
|
|
||||||
|
public int getHP() {
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
public int getMP() {
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBaseDamage() {
|
||||||
|
return baseDamage;
|
||||||
|
}
|
||||||
|
|
||||||
public Weapon getWeapon() {
|
public Weapon getWeapon() {
|
||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Goblin extends Enemy {
|
||||||
|
public Goblin(Weapon weapon) {
|
||||||
|
int hp = 30;
|
||||||
|
int mp = 50;
|
||||||
|
super(hp, mp, weapon, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getKilled() {
|
||||||
|
isAlive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
Random rand = new Random();
|
||||||
|
if (rand.nextBoolean()) {
|
||||||
|
target.takeDamage((weapon.getDamage() + getBaseDamage()) * 2);
|
||||||
|
System.out.println("\u001B[33mGoblin did critical Hit!!!!!\u001B[0m");
|
||||||
|
System.out.printf("\u001B[31mYou took %d damage.\u001B[0m\n", (weapon.getDamage() + getBaseDamage()) * 2);
|
||||||
|
} else {
|
||||||
|
target.takeDamage(weapon.getDamage() + getBaseDamage());
|
||||||
|
System.out.printf("\u001B[31mYou took %d damage.\u001B[0m\n", weapon.getDamage() + getBaseDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getHP() + health > getMaxHP())
|
||||||
|
setHP(getMaxHP());
|
||||||
|
else
|
||||||
|
setHP(getHP() + health);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillMana(int mana) {
|
||||||
|
if (getMP() + mana > getMaxMP())
|
||||||
|
setMP(getMaxMP());
|
||||||
|
else
|
||||||
|
setMP(getMP() + mana);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHP() {
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMP() {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,65 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.entity.Entity;
|
||||||
public class Skeleton {
|
import org.project.item.weapons.Weapon;
|
||||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
|
||||||
|
public class Skeleton extends Enemy {
|
||||||
|
int timesDied;
|
||||||
|
|
||||||
|
public Skeleton(Weapon weapon) {
|
||||||
|
int hp = 50;
|
||||||
|
int mp = 50;
|
||||||
|
timesDied = 0;
|
||||||
|
super(hp, mp, weapon, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeDamage(int damage) {
|
||||||
|
super.takeDamage(damage);
|
||||||
|
if (!isAlive)
|
||||||
|
getKilled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getKilled() {
|
||||||
|
if (timesDied == 0) {
|
||||||
|
timesDied += 1;
|
||||||
|
setHP(getMaxHP() / 2);
|
||||||
|
System.out.println("\u001B[33myour enemy revived itself!!!\u001B[0m");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isAlive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
target.takeDamage((weapon.getDamage() + getBaseDamage()));
|
||||||
|
System.out.printf("\u001B[31mYou took %d damage.\u001B[0m\n", weapon.getDamage() + getBaseDamage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getHP() + health > getMaxHP())
|
||||||
|
setHP(getMaxHP());
|
||||||
|
else
|
||||||
|
setHP(getHP() + health);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillMana(int mana) {
|
||||||
|
if (getMP() + mana > getMaxMP())
|
||||||
|
setMP(getMaxMP());
|
||||||
|
else
|
||||||
|
setMP(getMP() + mana);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHP() {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMP() {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
|
public class Vampire extends Enemy {
|
||||||
|
public Vampire(Weapon weapon) {
|
||||||
|
int maxHP = 50;
|
||||||
|
int maxMP = 50;
|
||||||
|
super(maxHP, maxMP, weapon, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getKilled() {
|
||||||
|
isAlive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
target.takeDamage((weapon.getDamage() + getBaseDamage()));
|
||||||
|
System.out.println("\u001B[35mVampire stole your HP\u001B[0m");
|
||||||
|
System.out.printf("\u001B[32mVampire: +%d hp\u001B[0m\n", (int) ((weapon.getDamage() + getBaseDamage()) * 0.5));
|
||||||
|
this.heal((int) ((weapon.getDamage() + getBaseDamage()) * 0.5));
|
||||||
|
System.out.printf("\u001B[31mYou took %d damage.\u001B[0m\n", (int) (weapon.getDamage() + getBaseDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int health) {
|
||||||
|
if (getHP() + health > getMaxHP())
|
||||||
|
setHP(getMaxHP());
|
||||||
|
else
|
||||||
|
setHP(getHP() + health);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillMana(int mana) {
|
||||||
|
if (getMP() + mana > getMaxMP())
|
||||||
|
setMP(getMaxMP());
|
||||||
|
else
|
||||||
|
setMP(getMP() + mana);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHP() {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMP() {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.item.armors.Armor;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
|
public class Assassin extends Player{
|
||||||
|
|
||||||
|
public Assassin(String name, Weapon weapon, Armor armor) {
|
||||||
|
int hp = 80;
|
||||||
|
int mp = 20;
|
||||||
|
int baseDamage = 5;
|
||||||
|
super(name, hp, mp, baseDamage, weapon, armor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.armors.Armor;
|
||||||
public class Knight {
|
import org.project.item.weapons.Weapon;
|
||||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
|
||||||
|
public class Knight extends Player {
|
||||||
|
|
||||||
|
public Knight(String name, Weapon weapon, Armor armor) {
|
||||||
|
int hp = 100;
|
||||||
|
int mp = 10;
|
||||||
|
int baseDamage = 10;
|
||||||
|
super(name, hp, mp, baseDamage, weapon, armor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import org.project.entity.Entity;
|
|||||||
import org.project.item.armors.Armor;
|
import org.project.item.armors.Armor;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Player implements Entity {
|
||||||
public abstract class Player {
|
|
||||||
protected String name;
|
protected String name;
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
Armor armor;
|
Armor armor;
|
||||||
@@ -13,30 +12,42 @@ public abstract class Player {
|
|||||||
private int maxHP;
|
private int maxHP;
|
||||||
private int mp;
|
private int mp;
|
||||||
private int maxMP;
|
private int maxMP;
|
||||||
|
private int baseDamage;
|
||||||
|
private boolean isAlive;
|
||||||
|
|
||||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
public int getBaseDamage() {
|
||||||
|
return baseDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(String name, int hp, int mp, int baseDamage, Weapon weapon, Armor armor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
|
this.maxHP = hp;
|
||||||
|
this.maxMP = mp;
|
||||||
|
this.baseDamage = baseDamage;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
|
this.isAlive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack(Entity target) {
|
public void attack(Entity target) {
|
||||||
target.takeDamage(weapon.getDamage());
|
target.takeDamage(weapon.getDamage() + this.baseDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void heavyAttack(Entity target) {
|
||||||
public void defend() {
|
target.takeDamage(weapon.getDamage() + this.baseDamage + 7);
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
|
if (damage - armor.getDefense() > 0) {
|
||||||
hp -= damage - armor.getDefense();
|
hp -= damage - armor.getDefense();
|
||||||
|
if (hp <= 0) {
|
||||||
|
getKilled();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,6 +56,7 @@ public abstract class Player {
|
|||||||
if (hp > maxHP) {
|
if (hp > maxHP) {
|
||||||
hp = maxHP;
|
hp = maxHP;
|
||||||
}
|
}
|
||||||
|
System.out.println("\u001B[32myou Healed yourself!\u001B[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,15 +64,16 @@ public abstract class Player {
|
|||||||
mp += mana;
|
mp += mana;
|
||||||
if (mp > maxMP) {
|
if (mp > maxMP) {
|
||||||
mp = maxMP;
|
mp = maxMP;
|
||||||
|
System.out.println("\u001B[33myour Mana got spilled.\u001B[0m");
|
||||||
|
} else
|
||||||
|
System.out.printf("\u001B[36m+%d Mana\u001B[0m\n", mana);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp() {
|
public int getHP() {
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +82,7 @@ public abstract class Player {
|
|||||||
return maxHP;
|
return maxHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
public int getMP() {
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,4 +99,21 @@ public abstract class Player {
|
|||||||
return armor;
|
return armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAlive() {
|
||||||
|
return isAlive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getKilled() {
|
||||||
|
isAlive = false;
|
||||||
|
System.out.println("\u001B[31mYou died!\u001B[0m");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean useMana(int mana) {
|
||||||
|
if (mp - mana < 0)
|
||||||
|
return false;
|
||||||
|
else {
|
||||||
|
mp -= mana;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.item.armors.Armor;
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
|
public class Wizard extends Player{
|
||||||
|
public Wizard(String name, Weapon weapon, Armor armor) {
|
||||||
|
int hp = 150;
|
||||||
|
int mp = 10;
|
||||||
|
int baseDamage = 4;
|
||||||
|
super(name, hp, mp, baseDamage, weapon, armor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,4 @@ import org.project.entity.Entity;
|
|||||||
|
|
||||||
public interface Item {
|
public interface Item {
|
||||||
void use(Entity target);
|
void use(Entity target);
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Armor {
|
public abstract class Armor {
|
||||||
private int defense;
|
private int defense;
|
||||||
private int maxDefense;
|
private int maxDefense;
|
||||||
@@ -21,7 +20,6 @@ public abstract class Armor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
|
||||||
public void repair() {
|
public void repair() {
|
||||||
isBroke = false;
|
isBroke = false;
|
||||||
defense = maxDefense;
|
defense = maxDefense;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public class KnightArmor extends Armor{
|
||||||
public class KnightArmor {
|
public KnightArmor() {
|
||||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
int defense = 6;
|
||||||
|
int durability = 20;
|
||||||
|
super(defense, durability);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package org.project.item.consumables;
|
package org.project.item.consumables;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.Item;
|
||||||
public abstract class Consumable {
|
|
||||||
/*
|
public abstract class Consumable implements Item {
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,8 @@ package org.project.item.consumables;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public class Flask extends Consumable{
|
||||||
public class Flask {
|
|
||||||
/*
|
|
||||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: UPDATE USE METHOD
|
|
||||||
@Override
|
@Override
|
||||||
public void use(Entity target) {
|
public void use(Entity target) {
|
||||||
target.heal(target.getMaxHP() / 10);
|
target.heal(target.getMaxHP() / 10);
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.project.item.weapons;
|
||||||
|
|
||||||
|
public class DragonBreath extends Weapon{
|
||||||
|
public DragonBreath() {
|
||||||
|
super(8, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,7 @@ import org.project.entity.Entity;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public class Sword extends Weapon{
|
||||||
public class Sword {
|
|
||||||
/*
|
/*
|
||||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
||||||
*/
|
*/
|
||||||
@@ -13,10 +12,11 @@ public class Sword {
|
|||||||
int abilityCharge;
|
int abilityCharge;
|
||||||
|
|
||||||
public Sword() {
|
public Sword() {
|
||||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
int damage = 2;
|
||||||
|
int manaCost = 10;
|
||||||
|
super(damage, manaCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
|
||||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
public void uniqueAbility(ArrayList<Entity> targets) {
|
||||||
abilityCharge += 2;
|
abilityCharge += 2;
|
||||||
for (Entity target : targets) {
|
for (Entity target : targets) {
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
package org.project.item.weapons;
|
package org.project.item.weapons;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Weapon implements Item {
|
||||||
public abstract class Weapon {
|
|
||||||
private int damage;
|
private int damage;
|
||||||
private int manaCost;
|
private int manaCost;
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
|
||||||
*/
|
|
||||||
|
|
||||||
public Weapon(int damage, int manaCost) {
|
public Weapon(int damage, int manaCost) {
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
this.manaCost = manaCost;
|
this.manaCost = manaCost;
|
||||||
@@ -29,7 +25,4 @@ public abstract class Weapon {
|
|||||||
return manaCost;
|
return manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,27 +2,20 @@ package org.project.location;
|
|||||||
|
|
||||||
import org.project.entity.enemies.Enemy;
|
import org.project.entity.enemies.Enemy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Location {
|
public class Location {
|
||||||
private String name;
|
private String name;
|
||||||
|
private Enemy enemy;
|
||||||
|
|
||||||
private ArrayList<Enemy> enemies;
|
public Location(String name,Enemy enemy) {
|
||||||
|
this.enemy = enemy;
|
||||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
this.name = name;
|
||||||
this.locations = locations;
|
|
||||||
this.enemies = enemies;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getLocations() {
|
public Enemy getEnemy() {
|
||||||
return locations;
|
return enemy;
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Enemy> getEnemies() {
|
|
||||||
return enemies;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,175 +1,181 @@
|
|||||||
# Fourth Assignment - Java Knight ⚔️
|
# Java RPG Project
|
||||||
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
|
||||||
|
|
||||||
### **Prologue: The Legend of Javanest**
|
A small console-based Java RPG where the player selects a character class and fights a fixed sequence of enemies: Vampire, Goblin, Skeleton, and Dragon.
|
||||||
*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!*
|
|
||||||
|
|
||||||
### **Introduction**
|
## Gameplay
|
||||||
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**.
|
|
||||||
|
|
||||||
⚠️ **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.
|
The game flow is handled in `Main.java`:
|
||||||
|
|
||||||
🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!**
|
1. The player enters a name.
|
||||||
|
2. The player chooses a class:
|
||||||
|
- Knight
|
||||||
|
- Wizard
|
||||||
|
- Assassin
|
||||||
|
3. The game creates four locations and enemies:
|
||||||
|
- Overworld -> Vampire
|
||||||
|
- Village -> Goblin
|
||||||
|
- Nether -> Skeleton
|
||||||
|
- End -> Dragon
|
||||||
|
4. The player fights each enemy in sequence.
|
||||||
|
5. If the player dies, the game ends.
|
||||||
|
6. If all enemies are defeated, the player wins.
|
||||||
|
|
||||||
### **What is a Turn-Based Game?**
|
## Combat System
|
||||||
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:**
|
Each battle is turn-based.
|
||||||
- **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.
|
|
||||||
|
|
||||||
---
|
### Player actions
|
||||||
|
|
||||||
## Tasks 📝
|
The player can choose from:
|
||||||
|
|
||||||
### 1️⃣ Step 1: Fork & Setup 🍴
|
- light attack
|
||||||
1. **Fork** this repository and clone it to your local machine.
|
- normal attack
|
||||||
```bash
|
- heavy attack
|
||||||
git clone https://git.meshcomp.ir/AdvancedProgramming1404/HW-04-JAVA-KNIGHT.git
|
- heal
|
||||||
```
|
- skip
|
||||||
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.
|
### Enemy actions
|
||||||
|
|
||||||
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`.
|
Enemies attack after the player’s turn. Some enemies have special behavior:
|
||||||
- **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
|
|
||||||
|
|
||||||

|
- Vampire can restore health while attacking
|
||||||
|
- Goblin can land critical hits
|
||||||
|
- Skeleton revives once after being defeated
|
||||||
|
- Dragon acts as a boss enemy with high HP
|
||||||
|
|
||||||
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
|
## Core Interfaces and Classes
|
||||||
|
|
||||||
**Player Actions (The Rule of Five):**
|
### `Entity`
|
||||||
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.
|
Common contract for all combatants.
|
||||||
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:**
|
It defines shared behavior such as:
|
||||||
- **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) :
|
- `attack(Entity target)`
|
||||||
|
- `heal(int health)`
|
||||||
|
- `fillMana(int mana)`
|
||||||
|
- `takeDamage(int damage)`
|
||||||
|
- `getMaxHP()`
|
||||||
|
- `getMaxMP()`
|
||||||
|
|
||||||
```bash
|
### `Player`
|
||||||
You chose to FIGHT!
|
Abstract base class for all player characters.
|
||||||
|
|
||||||
[Ser Duncan - 45/45 HP | 40/40 Mana]
|
It stores:
|
||||||
[Goblin - 30/30 HP]
|
|
||||||
|
|
||||||
---
|
- name
|
||||||
|
- weapon
|
||||||
|
- armor
|
||||||
|
- current and maximum HP/MP
|
||||||
|
- base damage
|
||||||
|
- alive status
|
||||||
|
|
||||||
Your Turn:
|
It also provides:
|
||||||
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
- normal attack
|
||||||
→ Chose: Light Attack
|
- heavy attack
|
||||||
⚔️ Ser Duncan (Knight) used Light Attack! (0 Mana)
|
- damage handling with armor defense
|
||||||
Goblin took 10 damage!
|
- healing
|
||||||
Goblin has 20/30 HP remaining.
|
- mana restoration
|
||||||
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).
|
|
||||||
|
|
||||||
|
### `Enemy`
|
||||||
|
Abstract base class for enemies.
|
||||||
|
|
||||||
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
|
It stores:
|
||||||
|
|
||||||
1. **The Core Loop:** The game starts with the player entering a location. A random standard enemy (`Goblin`, `Skeleton`, or `Vampire`) spawns immediately.
|
- weapon
|
||||||
2. **Player Choices:** Before engaging, the player is presented with the following options:
|
- HP/MP
|
||||||
- **1. Fight the enemy:** Enter the turn-based combat sequence.
|
- base damage
|
||||||
- **2. Move to another location:** Skip the current enemy and spawn a new random one.
|
- alive status
|
||||||
- **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**.
|
|
||||||
|
|
||||||
🔹 Example game loop structure:
|
It handles damage directly and leaves defeat behavior to subclasses through `getKilled()`.
|
||||||
|
|
||||||
```java
|
## Player Classes
|
||||||
while (player.isAlive() && enemy.isAlive())
|
|
||||||
player.attack(enemy);
|
|
||||||
if (enemy.isAlive()) {
|
|
||||||
enemy.attack(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
### `Knight`
|
||||||
|
- HP: 100
|
||||||
|
- MP: 10
|
||||||
|
- Base damage: 10
|
||||||
|
|
||||||
### 5️⃣ Step 5: Extra Features & Bonus Tasks ⭐
|
A durable melee fighter with strong base damage.
|
||||||
*(Optional for extra credit)*
|
|
||||||
|
|
||||||
✅ **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.
|
### `Wizard`
|
||||||
✅ **Multiple Weapons & Inventory:** Players can buy, store, and swap between multiple weapons or use consumables mid-combat.
|
- HP: 150
|
||||||
✅ **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.
|
- MP: 10
|
||||||
✅ **PvP Mode:** Implement a **Player vs. Player** combat system.
|
- Base damage: 4
|
||||||
|
|
||||||
### 6️⃣ Step 6: Write a Comprehensive README 📄
|
A high-HP character using the shared `Player` behavior.
|
||||||
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).
|
|
||||||
|
|
||||||
---
|
### `Assassin`
|
||||||
|
- HP: 80
|
||||||
|
- MP: 20
|
||||||
|
- Base damage: 5
|
||||||
|
|
||||||
## Evaluation Criteria ⚖
|
A lighter character with more mana than the Knight.
|
||||||
|
|
||||||
| **Criteria** | **Points** |
|
## Enemy Classes
|
||||||
|-------------------------------------------------------------|------------|
|
|
||||||
| 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** |
|
|
||||||
|
|
||||||
## Tips 🚀
|
### `Vampire`
|
||||||
- **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.
|
- HP: 50
|
||||||
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected.
|
- MP: 50
|
||||||
- **Ask for help**: If you're stuck, reach out to your classmates or mentors.
|
|
||||||
|
|
||||||
## Submission ⌛
|
Attacks and restores part of the damage dealt as health.
|
||||||
- **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.
|
|
||||||
|
|
||||||

|
### `Goblin`
|
||||||
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.
|
- HP: 30
|
||||||
|
- MP: 50
|
||||||
|
|
||||||
|
Randomly performs either a normal or critical attack.
|
||||||
|
|
||||||
|
### `Skeleton`
|
||||||
|
- HP: 50
|
||||||
|
- MP: 50
|
||||||
|
- Base damage: 10
|
||||||
|
|
||||||
|
Revives once after death, then dies permanently the second time.
|
||||||
|
|
||||||
|
### `Dragon`
|
||||||
|
- HP: 500
|
||||||
|
- Base damage: 2
|
||||||
|
|
||||||
|
A boss-style enemy with a fire-breath themed attack and custom death handling.
|
||||||
|
|
||||||
|
## Items
|
||||||
|
|
||||||
|
### `Weapon`
|
||||||
|
Abstract item type for damage-dealing equipment.
|
||||||
|
|
||||||
|
It includes:
|
||||||
|
|
||||||
|
- damage
|
||||||
|
- mana cost
|
||||||
|
|
||||||
|
### `Sword`
|
||||||
|
A weapon with low damage and a mana cost.
|
||||||
|
|
||||||
|
It also includes a unique ability that can damage multiple targets.
|
||||||
|
|
||||||
|
### `DragonBreath`
|
||||||
|
A stronger weapon used for dragon-related combat behavior.
|
||||||
|
|
||||||
|
## Armor
|
||||||
|
|
||||||
|
### `Armor`
|
||||||
|
Abstract armor type with:
|
||||||
|
|
||||||
|
- defense
|
||||||
|
- maximum defense
|
||||||
|
- durability
|
||||||
|
- maximum durability
|
||||||
|
- broken state
|
||||||
|
|
||||||
|
Armor can be repaired, and when durability reaches zero, its defense drops to zero.
|
||||||
|
|
||||||
|
### `KnightArmor`
|
||||||
|
A concrete armor type used by the player in the main game flow.
|
||||||
|
|
||||||
|
#### `Flask`
|
||||||
|
A healing item that restores a fraction of the target’s maximum HP.
|
||||||
|
|
||||||
|
## Location
|
||||||
|
|
||||||
|
`Location` is a simple class that stores a location name and one enemy.
|
||||||
Reference in New Issue
Block a user