Compare commits
3
Commits
78d4bedb08
...
d499f00d54
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d499f00d54 | ||
|
|
6f0ef36301 | ||
|
|
08f26044f0 |
Generated
+3
@@ -9,5 +9,8 @@
|
|||||||
<module name="Java-Knight" />
|
<module name="Java-Knight" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="README" target="25" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+2
@@ -3,5 +3,7 @@
|
|||||||
<component name="Encoding">
|
<component name="Encoding">
|
||||||
<file url="file://$PROJECT_DIR$/Java-Knight/src/main/java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/Java-Knight/src/main/java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/Java-Knight/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/Java-Knight/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/README/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/README/src/main/resources" charset="UTF-8" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+6
@@ -5,8 +5,14 @@
|
|||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/Java-Knight/pom.xml" />
|
<option value="$PROJECT_DIR$/Java-Knight/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/README/pom.xml" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="ignoredFiles">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$/README/pom.xml" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
|||||||
@@ -1,15 +1,57 @@
|
|||||||
package org.project;
|
package org.project;
|
||||||
|
|
||||||
|
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.GameDisplay;
|
||||||
|
import org.project.location.GameEngine;
|
||||||
import org.project.location.Location;
|
import org.project.location.Location;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main
|
||||||
public static void main(String[] args) {
|
{
|
||||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
public static void main(String[] args)
|
||||||
List<Location> locations = new ArrayList<>();
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
GameDisplay display = new GameDisplay();
|
||||||
|
String choice = display.mainMenu();
|
||||||
|
|
||||||
// TODO: IMPLEMENT GAMEPLAY
|
Scanner scanner;
|
||||||
|
if (choice.equals("1"))
|
||||||
|
{
|
||||||
|
scanner = new Scanner(System.in);
|
||||||
|
System.out.println(display.BLUE + "Enter your name :" + display.RESET);
|
||||||
|
String n = scanner.nextLine();
|
||||||
|
String c = display.chooseCharacter();
|
||||||
|
Player p = null;
|
||||||
|
|
||||||
|
if (c.equals("1")) p = new Knight(n);
|
||||||
|
else if (c.equals("2")) p = new Assassin(n);
|
||||||
|
else if (c.equals("3")) p = new Wizard(n);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Invalid option");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GameEngine gameEngine = new GameEngine(p);
|
||||||
|
gameEngine.runGame();
|
||||||
|
}
|
||||||
|
else if (choice.equals("2")) display.help();
|
||||||
|
else if (choice.equals("3"))
|
||||||
|
{
|
||||||
|
System.out.println("GOOD BYE!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Invalid option");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
public interface Entity
|
||||||
|
{
|
||||||
void attack(Entity target);
|
void attack(Entity target);
|
||||||
|
|
||||||
void defend();
|
void defend();
|
||||||
|
|
||||||
void heal(int health);
|
void heal();
|
||||||
|
|
||||||
void fillMana(int mana);
|
boolean isAlive();
|
||||||
|
|
||||||
void takeDamage(int damage);
|
void takeDamage(int damage);
|
||||||
|
|
||||||
int getMaxHP();
|
void specialAbility(Entity target);
|
||||||
|
|
||||||
int getMaxMP();
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.location.GameDisplay;
|
||||||
|
|
||||||
|
public class Dragon extends Enemy
|
||||||
|
{
|
||||||
|
public Dragon(int hp, int mp, String name) { super(hp, mp,name); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if(getMp() >= 5)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
System.out.println(GameDisplay.CYAN + "The Dragon threw a huge fire at the player 🔥🔥" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(10);
|
||||||
|
this.setMp(this.getMp() - 5);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Dragon does not have enough MP tp use special ability!" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,79 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.location.GameDisplay;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Enemy implements Entity {
|
||||||
public abstract class Enemy {
|
protected boolean isDefending = false;
|
||||||
Weapon weapon;
|
private String name;
|
||||||
private int hp;
|
private int hp;
|
||||||
private int mp;
|
private int mp;
|
||||||
|
|
||||||
public Enemy(int hp, int mp, Weapon weapon) {
|
public Enemy(int hp, int mp, String name) {
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
this.weapon = weapon;
|
public void resetDefendState() { this.isDefending = false; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attack(Entity target) {
|
||||||
|
System.out.println(GameDisplay.RED + "Enemy attacks! ⚔️" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void defend() {
|
||||||
|
if (getMp() >= 5) {
|
||||||
|
this.mp -= 5;
|
||||||
|
this.isDefending = true;
|
||||||
|
System.out.println(GameDisplay.BLUE + "Enemy defends! 🛡️" + GameDisplay.RESET);
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + "Enemy cannot defend! " + GameDisplay.RESET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
hp -= damage;
|
if (isDefending) {
|
||||||
|
damage = 0;
|
||||||
|
this.isDefending = false;
|
||||||
|
System.out.println(GameDisplay.GREEN + "Enemy blocks damage! 🛡️" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Enemy takes " + damage + " damage 🩸" + GameDisplay.RESET);
|
||||||
|
|
||||||
|
this.hp -= damage;
|
||||||
|
if (this.hp < 0) this.hp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp() {
|
@Override
|
||||||
return hp;
|
public void specialAbility(Entity target) {
|
||||||
|
System.out.println(GameDisplay.MAGENTA + "Enemy uses special ability! " + GameDisplay.RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
@Override
|
||||||
return mp;
|
public void heal() {
|
||||||
|
if (getMp() >= 6) {
|
||||||
|
this.hp += 10;
|
||||||
|
if (this.hp > 100) this.hp = 100;
|
||||||
|
this.mp -= 6;
|
||||||
|
System.out.println(GameDisplay.GREEN + "Enemy heals (+10 HP) 💊" + GameDisplay.RESET);
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + "Enemy cannot heal" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Weapon getWeapon() {
|
@Override
|
||||||
return weapon;
|
public boolean isAlive() { return hp > 0; }
|
||||||
}
|
|
||||||
}
|
public String getName() {return name; }
|
||||||
|
|
||||||
|
public int getHp() { return hp; }
|
||||||
|
|
||||||
|
public void setHp(int newHp) { this.hp = newHp; }
|
||||||
|
|
||||||
|
public int getMp() { return mp; }
|
||||||
|
|
||||||
|
public void setMp(int newMp) { this.mp = newMp; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.location.GameDisplay;
|
||||||
|
|
||||||
|
public class Goblin extends Enemy
|
||||||
|
{
|
||||||
|
public Goblin(int hp, int mp, String name) { super(hp, mp, name); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if(getMp() >= 5)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
this.setMp(this.getMp() - 5);
|
||||||
|
System.out.println(GameDisplay.CYAN + "The Goblin struck a powerful below 👊" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(7);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Goblin does not have enough MP to use Special ability" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,23 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.entity.Entity;
|
||||||
public class Skeleton {
|
import org.project.location.GameDisplay;
|
||||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
|
||||||
}
|
|
||||||
|
public class Skeleton extends Enemy
|
||||||
|
{
|
||||||
|
public Skeleton(int hp, int mp, String name) { super(hp, mp, name); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if(getMp() >= 4)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
System.out.println(GameDisplay.CYAN + "Skeleton is regenerating its bones(+ %50 HP)! 🦴" + GameDisplay.RESET);
|
||||||
|
this.setMp(this.getMp() - 4);
|
||||||
|
this.setHp(this.getHp() / 2);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Skeleton does not have enough MP to use special ability!" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.location.GameDisplay;
|
||||||
|
|
||||||
|
public class Vampire extends Enemy
|
||||||
|
{
|
||||||
|
public Vampire(int hp, int mp, String name) { super(hp, mp, name); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if(getMp() >= 8)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
System.out.println(GameDisplay.CYAN + "The Vampire strikes with a powerful bite! 🦷" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(10);
|
||||||
|
this.setMp(this.getMp() - 8);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Vampire does not have enough MP for special ability." + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.location.GameDisplay;
|
||||||
|
|
||||||
|
|
||||||
|
public class Assassin extends Player
|
||||||
|
{
|
||||||
|
public Assassin (String name) { super(name , 40, 60, 0); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if (this.getMp() >= 9)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
System.out.println(GameDisplay.CYAN + "Assassin picks up the axe and deals a heavy below to the enemy ⚒️" + GameDisplay.RESET);
|
||||||
|
this.setMp(this.getMp() - 9);
|
||||||
|
target.takeDamage(12);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Assassin does not have enough MP to use special ability 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.entity.Entity;
|
||||||
public class Knight {
|
import org.project.location.GameDisplay;
|
||||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
|
||||||
}
|
public class Knight extends Player
|
||||||
|
{
|
||||||
|
public Knight(String name) { super(name, 50, 50, 0); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if (this.getMp() >= 7)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
System.out.println(GameDisplay.CYAN + "The Knight attacks with a sharp sword! 🗡️💪" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(8);
|
||||||
|
this.setMp(this.getMp() - 7);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Knight does not have enough MP to use special ability 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,89 +1,126 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.armors.Armor;
|
import org.project.location.GameDisplay;
|
||||||
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;
|
protected boolean isDefending = false;
|
||||||
Armor armor;
|
|
||||||
private int hp;
|
private int hp;
|
||||||
private int maxHP;
|
private int maxHP = 100;
|
||||||
private int mp;
|
private int mp;
|
||||||
private int maxMP;
|
private int maxMP = 100;
|
||||||
|
private int xp;
|
||||||
|
|
||||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
public Player(String name, int hp, int mp, int xp) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
this.mp = mp;
|
this.mp = mp;
|
||||||
|
this.xp = xp;
|
||||||
|
}
|
||||||
|
|
||||||
this.weapon = weapon;
|
public void gainXp(int newXp) {
|
||||||
this.armor = armor;
|
this.xp += newXp;
|
||||||
|
System.out.println(GameDisplay.YELLOW + getName() + " gained " + newXp + " XP 🪙" + GameDisplay.RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack(Entity target) {
|
public void attack(Entity target) {
|
||||||
target.takeDamage(weapon.getDamage());
|
System.out.println(GameDisplay.CYAN + getName() + " attacks! ⚔️" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
if (getMp() >= 2) {
|
||||||
|
System.out.println(GameDisplay.CYAN + getName() + " uses Heavy Attack! 💣" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(4);
|
||||||
|
this.mp -= 2;
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + getName() + " does not have enough MP for Heavy Attack! 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defend() {
|
public void defend() {
|
||||||
// TODO
|
if (getMp() >= 5) {
|
||||||
|
this.mp -= 5;
|
||||||
|
this.isDefending = true;
|
||||||
|
System.out.println(GameDisplay.BLUE + getName() + " defends ! 🛡️" + GameDisplay.RESET);
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + getName() + "does not have enough MP to defend! 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public void takeDamage(int damage) {
|
||||||
hp -= damage - armor.getDefense();
|
if (isDefending) {
|
||||||
|
damage = 0;
|
||||||
|
this.isDefending = false;
|
||||||
|
System.out.println(GameDisplay.GREEN + getName() + " blocks damage!🛡️" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + getName() + " takes " + damage + " damage 🩸"+ GameDisplay.RESET);
|
||||||
|
|
||||||
|
this.hp -= damage;
|
||||||
|
if (this.hp < 0) this.hp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void heal(int health) {
|
public void heal() {
|
||||||
hp += health;
|
if (getMp() >= 6) {
|
||||||
if (hp > maxHP) {
|
this.hp += 10;
|
||||||
hp = maxHP;
|
if (this.hp > maxHP) this.hp = maxHP;
|
||||||
|
this.mp -= 6;
|
||||||
|
System.out.println(GameDisplay.GREEN + getName() + " heals! 🩹" + GameDisplay.RESET);
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + getName() + " cannot heal due to lack of MP! 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillMana() {
|
||||||
|
if (xp >= 10) {
|
||||||
|
this.mp = getMaxMP();
|
||||||
|
this.xp -= 10;
|
||||||
|
System.out.println(GameDisplay.GREEN + getName() + " restored full Mana 🧪!" + GameDisplay.RESET);
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + getName() + " does not have enough XP to restore Mana! 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillHp() {
|
||||||
|
if (xp >= 50) {
|
||||||
|
this.hp = getMaxHP();
|
||||||
|
this.xp -= 50;
|
||||||
|
System.out.println(GameDisplay.GREEN + getName() + " restored 20 HP using 50 XP! 💪🤩" + GameDisplay.RESET);
|
||||||
|
} else {
|
||||||
|
System.out.println(GameDisplay.RED + getName() + " does not have enough XP to restore HP! 😓" + GameDisplay.RESET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillMana(int mana) {
|
public void specialAbility(Entity target) {
|
||||||
mp += mana;
|
System.out.println(GameDisplay.MAGENTA +getName() + " uses special ability 😎" + GameDisplay.RESET);
|
||||||
if (mp > maxMP) {
|
|
||||||
mp = maxMP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHp() {
|
|
||||||
return hp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxHP() {
|
public boolean isAlive() {
|
||||||
return maxHP;
|
return hp > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp() {
|
public String getName() {return name; }
|
||||||
return mp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public int getHp() { return hp; }
|
||||||
public int getMaxMP() {
|
|
||||||
return maxMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Weapon getWeapon() {
|
public void setHp(int newHp) { this.hp = newHp; }
|
||||||
return weapon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Armor getArmor() {
|
public int getXp() { return xp; }
|
||||||
return armor;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
public void setXp(int newXp) { this.xp = newXp; }
|
||||||
|
|
||||||
|
public int getMaxHP() { return maxHP; }
|
||||||
|
|
||||||
|
public int getMp() { return mp; }
|
||||||
|
|
||||||
|
public void setMp(int newMp) { this.mp = newMp; }
|
||||||
|
|
||||||
|
public int getMaxMP() { return maxMP; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.location.GameDisplay;
|
||||||
|
|
||||||
|
public class Wizard extends Player
|
||||||
|
{
|
||||||
|
public Wizard (String name) { super(name , 60, 40,0); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target)
|
||||||
|
{
|
||||||
|
if (this.getMp() >= 8)
|
||||||
|
{
|
||||||
|
super.specialAbility(target);
|
||||||
|
this.setMp(this.getMp() - 8);
|
||||||
|
System.out.println(GameDisplay.CYAN + "Amazing magic is comingggg, Bibbidi bobbidi boooooooo ⭐🪄" + GameDisplay.RESET);
|
||||||
|
target.takeDamage(10);
|
||||||
|
}
|
||||||
|
else System.out.println(GameDisplay.RED + "Wizard does not have enough MP to use special ability 😓" + GameDisplay.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package org.project.location;
|
||||||
|
|
||||||
|
import org.project.entity.enemies.Enemy;
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class GameDisplay
|
||||||
|
{
|
||||||
|
public static final Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
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 MAGENTA = "\u001B[35m";
|
||||||
|
public static final String CYAN = "\u001B[36m";
|
||||||
|
public static final String PINK = "\u001B[38;5;206m";
|
||||||
|
|
||||||
|
public static final String RESET = "\u001B[0m";
|
||||||
|
|
||||||
|
public void showPlayerTurn (Player player) { System.out.println("\n--- " + player.getName() + "'s Turn ---"); }
|
||||||
|
|
||||||
|
public void showStatus(Player player, Enemy enemy, GameEngine gameEngine)
|
||||||
|
{
|
||||||
|
System.out.println(BLUE + "\n==========================================================" + RESET);
|
||||||
|
System.out.println("[ Name: " + player.getName() + ", HP: " + player.getHp() + "/" + player.getMaxHP()
|
||||||
|
+ ", MP: "+ player.getMp() + "/" + player.getMaxMP() + " XP: " + player.getXp()
|
||||||
|
+", Keys:" + gameEngine.keys + " ]");
|
||||||
|
System.out.println("[ Enemy: " + enemy.getName() + ", HP: " + enemy.getHp() + ", MP: " + enemy.getMp() + "]");
|
||||||
|
System.out.println(BLUE + "==========================================================" + RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String battleChoices()
|
||||||
|
{
|
||||||
|
System.out.println("Your turn :");
|
||||||
|
System.out.println(PINK + "1. Attack (Free) " + RESET + YELLOW + "6. Restore Mana (10 XP) " + RESET);
|
||||||
|
System.out.println(PINK + "2. Heavy Attack (-2 MP) " + RESET + YELLOW +"7. Restore HP (50 XP)" + RESET);
|
||||||
|
System.out.println(PINK + "3. Defend (-5 MP)" );
|
||||||
|
System.out.println("4. Special Ability (Knight -7, Wizard -8, Assassin -9 MP)");
|
||||||
|
System.out.println("5. Heal (-6 MP, +10 HP)" + RESET);
|
||||||
|
return scanner.nextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String mainMenu()
|
||||||
|
{
|
||||||
|
System.out.println(BLUE + "==== Main Menu ====" + RESET);
|
||||||
|
System.out.println("1. New Game");
|
||||||
|
System.out.println("2. help");
|
||||||
|
System.out.println("3. Exit");
|
||||||
|
return scanner.nextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String chooseCharacter()
|
||||||
|
{
|
||||||
|
System.out.println(BLUE + "Choose your character:" + RESET);
|
||||||
|
System.out.println("1. Knight (50 HP, 50 MP)");
|
||||||
|
System.out.println("2. Assassin (40 HP, 60 MP)");
|
||||||
|
System.out.println("3. Wizard (60 HP, 40 MP)");
|
||||||
|
return scanner.nextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void help()
|
||||||
|
{
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("================================================================================");
|
||||||
|
System.out.println(" WELCOME TO THE DARK REALM ");
|
||||||
|
System.out.println("================================================================================");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("You have entered a land shrouded in darkness, where evil creatures roam freely.");
|
||||||
|
System.out.println("Your mission is clear: defeat the forces of darkness and save the world from destruction.");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println(" HOW TO PLAY ");
|
||||||
|
System.out.println("1. CHOOSE YOUR HERO:");
|
||||||
|
System.out.println(" Before your journey begins, select one of the following classes:");
|
||||||
|
System.out.println(" 1.Knight 2.Wizard 3.Assassin");
|
||||||
|
System.out.println(" Each class has unique abilities and strengths. Choose wisely!");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("2. EXPLORE AND COMBAT:");
|
||||||
|
System.out.println(" As you venture into the realm, you will encounter hostile monsters such as Goblins, Vampires, and Skeletons.");
|
||||||
|
System.out.println(" Engage them in battle to gain experience points (XP) and level up your character.");
|
||||||
|
System.out.println(" Higher levels mean stronger stats and better chances of survival.");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("3. COLLECT KEYS:");
|
||||||
|
System.out.println(" Defeating specific types of monsters drops special keys:");
|
||||||
|
System.out.println(" - Killing Goblins drops the Goblin Key.");
|
||||||
|
System.out.println(" - Slaying Vampires yields the Vampire Key.");
|
||||||
|
System.out.println(" - Destroying Skeletons grants the Skeleton Key.");
|
||||||
|
System.out.println(" You must collect all three keys to unlock the final challenge.");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("4. THE FINAL BOSS: THE DRAGON:");
|
||||||
|
System.out.println(" Once you possess all three keys, the path to the Dragon's Lair will open.");
|
||||||
|
System.out.println(" The Dragon is the ultimate ruler of evil and possesses immense power.");
|
||||||
|
System.out.println(" This is the final battle. If you defeat the Dragon, you will restore peace to the world and win the game.");
|
||||||
|
System.out.println(" If you fail, darkness will prevail forever.");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("GOOD LUCK, HERO! MAY YOUR BLADE BE SHARP AND YOUR MAGIC STRONG :) ");
|
||||||
|
System.out.println("================================================================================");
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,236 @@
|
|||||||
|
package org.project.location;
|
||||||
|
|
||||||
|
import org.project.entity.enemies.*;
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class GameEngine
|
||||||
|
{
|
||||||
|
int keys = 0;
|
||||||
|
boolean goblinKey = false;
|
||||||
|
boolean skeletonKey = false;
|
||||||
|
boolean vampireKey = false;
|
||||||
|
|
||||||
|
GameDisplay display = new GameDisplay();
|
||||||
|
Player player;
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
List<Location> locations = new ArrayList<>();
|
||||||
|
|
||||||
|
public GameEngine(Player player)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
createLocations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runGame()
|
||||||
|
{
|
||||||
|
Location dragonLoc = locations.get(locations.size() - 1);
|
||||||
|
|
||||||
|
List<Location> enemyLoc = new ArrayList<>(locations);
|
||||||
|
enemyLoc .remove(enemyLoc .size() - 1);
|
||||||
|
|
||||||
|
Collections.shuffle(enemyLoc , random);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (keys >= 3)
|
||||||
|
{
|
||||||
|
System.out.println(display.YELLOW + "\n>>> You have collected all 3 Keys!🔑" + display.RESET);
|
||||||
|
System.out.println(">>> 🔓 Final battle : ");
|
||||||
|
System.out.println("----------------------------------------\n");
|
||||||
|
|
||||||
|
fightEnemies(dragonLoc.getEnemies(), dragonLoc.getName());
|
||||||
|
|
||||||
|
if(!player.isAlive())
|
||||||
|
{
|
||||||
|
System.out.println(display.RED + "\n ❌ GAME OVER! ❌ " + display.RESET);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println(display.YELLOW + "\n🎉 CONGRATULATIONS! 🎉" + display.RESET);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (Location loc : enemyLoc)
|
||||||
|
{
|
||||||
|
System.out.println(">>> Entering: " + loc.getName());
|
||||||
|
System.out.println("----------------------------------------");
|
||||||
|
|
||||||
|
fightEnemies(loc.getEnemies(), loc.getName());
|
||||||
|
|
||||||
|
if (!player.isAlive())
|
||||||
|
{
|
||||||
|
System.out.println(display.RED + "\n ❌ You died! GAME OVER ❌" + display.RESET);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (keys >= 3) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fightEnemies(List<Enemy> enemies, String locationName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < enemies.size(); i++)
|
||||||
|
{
|
||||||
|
Enemy enemy = enemies.get(i);
|
||||||
|
|
||||||
|
System.out.println("❗An enemy is coming : " + enemy.getName() + "❗");
|
||||||
|
|
||||||
|
while (enemy.isAlive() && player.isAlive())
|
||||||
|
{
|
||||||
|
display.showStatus(player, enemy, this);
|
||||||
|
|
||||||
|
String choice = display.battleChoices();
|
||||||
|
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.attack(enemy);
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.heavyAttack(enemy);
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.defend();
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.specialAbility(enemy);
|
||||||
|
break;
|
||||||
|
case "5":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.heal();
|
||||||
|
break;
|
||||||
|
case "6":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.fillMana();
|
||||||
|
break;
|
||||||
|
case "7":
|
||||||
|
display.showPlayerTurn(player);
|
||||||
|
player.fillHp();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid option. Try again.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enemy.isAlive())
|
||||||
|
{
|
||||||
|
System.out.println(display.BLUE + ">> Enemy died ! ✔️" + display.RESET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
enemyTurn(enemy);
|
||||||
|
|
||||||
|
if (!player.isAlive()) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.isAlive() && !enemy.isAlive())
|
||||||
|
{
|
||||||
|
int xp= 0;
|
||||||
|
boolean isLastEnemyInLocation = (i == enemies.size() - 1);
|
||||||
|
|
||||||
|
if (enemy instanceof Goblin)
|
||||||
|
{
|
||||||
|
xp = 10;
|
||||||
|
if (!goblinKey)
|
||||||
|
{
|
||||||
|
if (isLastEnemyInLocation || random.nextDouble() < 0.4)
|
||||||
|
{
|
||||||
|
goblinKey = true;
|
||||||
|
keys++;
|
||||||
|
System.out.println(display.YELLOW + ">> You found the Goblin Key! 🔑" + display.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (enemy instanceof Skeleton)
|
||||||
|
{
|
||||||
|
xp = 15;
|
||||||
|
if (!skeletonKey)
|
||||||
|
{
|
||||||
|
if (isLastEnemyInLocation || random.nextDouble() < 0.4)
|
||||||
|
{
|
||||||
|
skeletonKey = true;
|
||||||
|
keys++;
|
||||||
|
System.out.println(display.YELLOW + ">> You found the Skeleton Key!🔑" + display.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (enemy instanceof Vampire)
|
||||||
|
{
|
||||||
|
xp = 20;
|
||||||
|
if (!vampireKey)
|
||||||
|
{
|
||||||
|
if (isLastEnemyInLocation || random.nextDouble() < 0.4)
|
||||||
|
{
|
||||||
|
vampireKey = true;
|
||||||
|
keys++;
|
||||||
|
System.out.println(display.YELLOW + ">> You found the Vampire Key!🔑" + display.RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.gainXp(xp);
|
||||||
|
}
|
||||||
|
if (keys >= 3) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enemyTurn(Enemy enemy)
|
||||||
|
{
|
||||||
|
enemy.resetDefendState();
|
||||||
|
System.out.println("\n--- Enemy's Turn ---");
|
||||||
|
int action = random.nextInt(4);
|
||||||
|
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
enemy.attack(player);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
enemy.defend();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
enemy.specialAbility(player);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
enemy.heal();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createLocations()
|
||||||
|
{
|
||||||
|
List<Enemy> goblins = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
goblins.add(new Goblin(10, 10, "Goblin👹"));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Enemy> skeletons = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
skeletons.add(new Skeleton(20, 20, "Skeleton💀"));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Enemy> vampires = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
vampires.add(new Vampire(30, 30, "Vampire🧛♂️"));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Enemy> dragon = new ArrayList<>();
|
||||||
|
dragon.add(new Dragon(100, 100, "Dragon🐉"));
|
||||||
|
|
||||||
|
locations.add(new Location("Goblin Forest", goblins));
|
||||||
|
locations.add(new Location("Skeleton Graveyard", skeletons));
|
||||||
|
locations.add(new Location("Vampire Castle", vampires));
|
||||||
|
locations.add(new Location("Dragon Cave", dragon));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,15 +2,16 @@ package org.project.location;
|
|||||||
|
|
||||||
import org.project.entity.enemies.Enemy;
|
import org.project.entity.enemies.Enemy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
public class Location {
|
public class Location
|
||||||
|
{
|
||||||
private String name;
|
private String name;
|
||||||
|
private List<Enemy> enemies;
|
||||||
|
|
||||||
private ArrayList<Enemy> enemies;
|
public Location(String name,List<Enemy> enemies)
|
||||||
|
{
|
||||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
this.name = name;
|
||||||
this.locations = locations;
|
|
||||||
this.enemies = enemies;
|
this.enemies = enemies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,11 +19,7 @@ public class Location {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getLocations() {
|
public List<Enemy> getEnemies() {
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Enemy> getEnemies() {
|
|
||||||
return enemies;
|
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.
+104
@@ -0,0 +1,104 @@
|
|||||||
|
# Java Knight ⚔️
|
||||||
|
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
||||||
|
|
||||||
|
### 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!
|
||||||
|
|
||||||
|
### Your Mission :
|
||||||
|
1️⃣ Explore dangerous lands inhabited by Goblins, Skeletons, and Vampires.</br>
|
||||||
|
2️⃣ Defeat these enemies to gain experience points (XP) and collect special Keys.</br>
|
||||||
|
3️⃣ Collect all three keys (Goblin Key, Skeleton Key, Vampire Key).</br>
|
||||||
|
4️⃣ Once all keys are collected, the path to the Dragon’s Lair will open.</br>
|
||||||
|
5️⃣ Face the Dragon in a final, epic battle. Victory means saving the world; failure means eternal darkness.</br>
|
||||||
|
|
||||||
|
---
|
||||||
|
## How to play ?
|
||||||
|
#### 1. Character Selection 👤</br>
|
||||||
|
At the start of the game, choose one of the following classes:</br>
|
||||||
|
**💂♀️Knight :** Balanced stats with high defense. Good for players who prefer a tank-like playstyle.</br>
|
||||||
|
**🥷Assassin :** High damage output but lower HP. Requires careful management of MP for critical hits.</br>
|
||||||
|
**🧙♂️ Wizard :** Powerful magic abilities capable of dealing massive area damage, but fragile in close combat.</br>
|
||||||
|
#### 2. Combat System🎮
|
||||||
|
Turn-Based Battles:</br>
|
||||||
|
Engage in turn-based combat against various enemies.
|
||||||
|
|
||||||
|
**Actions:**</br>
|
||||||
|
- Attack: Basic free attack.</br>
|
||||||
|
- Heavy Attack: Costs MP but deals double damage.</br>
|
||||||
|
- Defend: Blocks incoming damage completely (Costs MP).</br>
|
||||||
|
- Special Ability: Each class has a unique powerful move (e.g., Wizard’s fireball, Assassin’s backstab).</br>
|
||||||
|
- Heal: Restore HP using MP.</br>
|
||||||
|
- Restore Mana/HP: Use accumulated XP to refill resources.</br>
|
||||||
|
- Enemy AI: Enemies can attack, defend, use special abilities, or heal themselves.</br>
|
||||||
|
#### 3. Progression & Keys🔑
|
||||||
|
Killing specific types of enemies drops a corresponding key:</br>
|
||||||
|
Kill Goblins → Get Goblin Key.</br>
|
||||||
|
Kill Skeletons → Get Skeleton Key.</br>
|
||||||
|
Kill Vampires → Get Vampire Key.</br>
|
||||||
|
You must collect all 3 Keys to unlock the final stage.</br>
|
||||||
|
XP gained from battles allows you to restore health and mana during fights.
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💻 Object-Oriented Programming Concepts Used
|
||||||
|
This project is built using the main concepts of Object-Oriented Programming (OOP) in Java. Let’s explain each one in a simple way.
|
||||||
|
|
||||||
|
### 1️⃣ Abstraction
|
||||||
|
Abstraction means defining the important structure first, and leaving the details for later.
|
||||||
|
|
||||||
|
**In this project :**</br>
|
||||||
|
The Entity interface defines what every living being in the game must be able to do (like attack, defend, and take damage).</br>
|
||||||
|
The Player and Enemy classes are abstract.</br>
|
||||||
|
They contain shared logic.</br>
|
||||||
|
But they leave some methods (like specialAbility) for subclasses to implement.
|
||||||
|
|
||||||
|
### 2️⃣ Inheritance
|
||||||
|
Inheritance allows one class to reuse properties and behaviors from another class.
|
||||||
|
|
||||||
|
In this project:</br>
|
||||||
|
Knight, Assassin, and Wizard inherit from Player.</br>
|
||||||
|
Goblin, Skeleton, Vampire, and Dragon inherit from Enemy.</br>
|
||||||
|
This means:</br>
|
||||||
|
All players can attack and defend (because they inherit from Player).</br>
|
||||||
|
But each one has its own unique special ability.
|
||||||
|
|
||||||
|
### 3️⃣ Polymorphism
|
||||||
|
Polymorphism means we can treat different objects as the same general type, but they behave differently.
|
||||||
|
|
||||||
|
**Example :**</br>
|
||||||
|
```bash
|
||||||
|
player.specialAbility(target);
|
||||||
|
```
|
||||||
|
Java decides at runtime which version to execute :</br>
|
||||||
|
- Knight’s ability</br>
|
||||||
|
- Wizard’s spell</br>
|
||||||
|
- Assassin’s strike
|
||||||
|
|
||||||
|
|
||||||
|
### 4️⃣ Encapsulation
|
||||||
|
Encapsulation means protecting the internal data of a class.
|
||||||
|
|
||||||
|
In this project:
|
||||||
|
- Private Fields: Attributes like hp, mp, and xp in Player and Enemy classes are marked as private.
|
||||||
|
- Getters/Setters: Access to these variables is controlled via public methods like getHp(), setHp(), etc.
|
||||||
|
|
||||||
|
|
||||||
|
### 5️⃣ Interface
|
||||||
|
An interface works like a contract.
|
||||||
|
|
||||||
|
The Entity interface says that every entity in the game must implement:
|
||||||
|
```bash
|
||||||
|
attack()
|
||||||
|
takeDamage()
|
||||||
|
isAlive()
|
||||||
|
```
|
||||||
|
It doesn’t matter if it’s a Player or an Enemy — they must follow these rules.
|
||||||
|
|
||||||
|
---
|
||||||
|
## How to Run 🚀
|
||||||
|
- Clone the repository.</br>
|
||||||
|
- Open the project in your preferred Java IDE.</br>
|
||||||
|
- Ensure all packages (org.project.entity, org.project.location, etc.) are correctly structured.</br>
|
||||||
|
- Run the Main class.</br>
|
||||||
|
|
||||||
|
**Follow the on-screen instructions to begin your adventure and enjoy the game :)**
|
||||||
|
|
||||||
Reference in New Issue
Block a user