diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 4158879..4e0bf3c 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -16,5 +16,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Java-Knight/src/main/java/org/project/Main.java b/Java-Knight/src/main/java/org/project/Main.java
index 4241f87..f66ea16 100644
--- a/Java-Knight/src/main/java/org/project/Main.java
+++ b/Java-Knight/src/main/java/org/project/Main.java
@@ -27,190 +27,39 @@ public class Main {
handleLocation();
}
- public static void handleLocation() {
-
- System.out.println("What next?");
+ public static void createPlayer() {
Scanner in = new Scanner(System.in);
- while (true) {
+ System.out.println("Enter your name: ");
+ String name = in.nextLine();
+
+
+ while (true){
+
+ System.out.println("Choose your character: \n" +
+ "1. Knight⚔️\n" +
+ "2. Wizard\uD83E\uDDD9\u200D♂️\n" +
+ "3. Assassin\uD83D\uDDE1️");
- System.out.println("1. Fight the " + enemy.getType() +
- "\n2. Go to another location\n" +
- "3. Go to the Castle to fight the Dragon");
int choice = in.nextInt();
-
switch (choice) {
+
case 1:
- fight();
+ player = new Knight(name);
return;
case 2:
- chooseLocation();
- spawnRandomEnemy();
- handleLocation();
- fight();
+ player = new Wizard(name);
return;
case 3:
- if(player.hasGoblinKey() && player.hasVampireKey() && player.hasSkeletonKey()) {
- enemy = new Dragon();
- fight();
- }
+ player = new Assassin(name);
return;
default:
- System.out.println("Invalid choice❌\nChoose another option: ");
+ System.out.println("Invalid choice❌");
break;
}
}
}
- public static void fight() {
-
- while (player.isAlive() && enemy.isAlive()) {
-
- System.out.println("\n" + player.getName() + " - "
- + player.getMp() + "/" + player.getMaxMP() + " MP | "
- + player.getHP() + "/" + player.getMaxHP() + " HP");
-
- System.out.println(enemy.getType() + " - "
- + enemy.getHP() + "/" + enemy.getMaxHP() + " HP");
-
- playerTurn();
-
- if(enemy.isAlive())
- enemyTurn();
- }
-
- if(!player.isAlive()) {
- System.out.println("💀 You have been defeated...");
- System.exit(0);
- }
-
- else if(!enemy.isAlive()) {
- handleEnemyDeath();
- }
- }
-
- public static void handleEnemyDeath() {
-
- if(enemy instanceof Skeleton && ((Skeleton) enemy).getReviveEnabled()) {
- ((Skeleton) enemy).revive();
- fight();
- }
- else if(enemy instanceof Dragon) {
- System.out.println("Congratulations! You defeated the Dragon and won!");
- System.exit(0);
- }
- else{
- System.out.println("You won the battle!");
- player.addXP(enemy.getXpReward());
- player.fillMana(player.getMaxMP());
- player.heal(player.getMaxHP());
- tryDropKey();
- locations.get(currentLocationIndex).getEnemies().remove(enemy);
- spawnRandomEnemy();
- handleLocation();
- }
-
- }
- public static String getEnemyKeyName() {
- return "player.has"+enemy.getType()+"Key";
- }
-
- public static void tryDropKey() {
-
- if(Math.random()<0.2) {
- if(enemy instanceof Goblin && !player.hasGoblinKey()) player.giveGoblinKey();
- else if(enemy instanceof Skeleton && !player.hasSkeletonKey()) player.giveSkeletonKey();
- else if(enemy instanceof Vampire && !player.hasVampireKey()) player.giveVampireKey();
- }
- }
-
-
-
- public static void enemyTurn() {
- enemy.attack(player);
- }
-
- public static void playerTurn() {
-
- System.out.println("Your turn: ");
- Scanner in = new Scanner(System.in);
-
- while (true) {
-
- System.out.println("1.light attack\n2.heavy attack\n3.defend\n4.heal\n5.special move");
- int choice = in.nextInt();
-
- int manaCost;
-
- switch (choice) {
- case 1:
- player.lightAttack(enemy);
- return;
- case 2:
- manaCost = player.getStats().heavyAttackManaCost;
- break;
- case 3:
- manaCost = player.getStats().defendManaCost;
- break;
- case 4:
- manaCost = player.getStats().healManaCost;
- break;
- case 5:
- manaCost = player.getStats().specialAbilityManaCost;
- break;
- default:
- System.out.println("Invalid choice❌\nChoose another option: ");
- continue;
- }
-
- if(player.reduceMana(manaCost)) {
-
- if(choice == 2) player.heavyAttack(enemy);
- else if (choice == 3 && !(enemy instanceof Dragon)) player.defend();
- else if (choice == 4) player.heal(20);
- else if(choice == 5) player.specialAbility(enemy);
-
- return;
- }
- else
- System.out.println("You don't have enough Mana\nChoose another...");
-
- }
- }
- public static void chooseLocation() {
-
- System.out.println("Select your destination \uD83C\uDFAF");
-
- Scanner in = new Scanner(System.in);
-
- while (true) {
-
- for(int i=0 ; i0 && choice<=locations.size()) {
- currentLocationIndex = choice - 1;
- System.out.println("You're in " + locations.get(currentLocationIndex).getName());
- return;
- }
- else
- System.out.println("Invalid choice❌\nChoose another option: ");
- }
- }
-
-
- public static void spawnRandomEnemy() {
-
- ArrayList enemies = locations.get(currentLocationIndex).getEnemies();
- Random random = new Random();
- int currentEnemyIndex = random.nextInt(enemies.size());
- enemy = locations.get(currentLocationIndex).getEnemy(currentEnemyIndex);
- System.out.println("You're facing a " + enemy.getType());
-
- }
-
public static void setupLocations() {
@@ -249,38 +98,198 @@ public class Main {
}
+ public static void chooseLocation() {
- public static void createPlayer() {
+ System.out.println("Select your destination \uD83C\uDFAF");
Scanner in = new Scanner(System.in);
- System.out.println("Enter your name: ");
- String name = in.nextLine();
-
- while (true){
-
- System.out.println("Choose your character: \n" +
- "1. Knight⚔️\n" +
- "2. Wizard\uD83E\uDDD9\u200D♂️\n" +
- "3. Assassin\uD83D\uDDE1️");
+ while (true) {
+
+ for(int i=0 ; i0 && choice<=locations.size()) {
+ currentLocationIndex = choice - 1;
+ System.out.println("You're in " + locations.get(currentLocationIndex).getName());
+ return;
+ }
+ else
+ System.out.println("Invalid choice❌\nChoose another option: ");
+ }
+ }
+ public static void spawnRandomEnemy() {
+
+ ArrayList enemies = locations.get(currentLocationIndex).getEnemies();
+ Random random = new Random();
+ int currentEnemyIndex = random.nextInt(enemies.size());
+ enemy = locations.get(currentLocationIndex).getEnemy(currentEnemyIndex);
+ System.out.println("You're facing a " + enemy.getType());
+
+ }
+
+
+ public static void handleLocation() {
+
+ System.out.println("What next?");
+
+ Scanner in = new Scanner(System.in);
+ while (true) {
+
+ System.out.println("1. Fight the " + enemy.getType() +
+ "\n2. Go to another location\n" +
+ "3. Go to the Castle to fight the Dragon");
+
+ int choice = in.nextInt();
+
+ switch (choice) {
case 1:
- player = new Knight(name);
+ fight();
return;
case 2:
- player = new Wizard(name);
+ chooseLocation();
+ spawnRandomEnemy();
+ handleLocation();
return;
case 3:
- player = new Assassin(name);
- return;
+ if(player.hasGoblinKey() && player.hasVampireKey() && player.hasSkeletonKey()) {
+ enemy = new Dragon();
+ fight();
+ return;
+ }
+ else {
+ System.out.println("❌You don't have all the keys❌");
+ break;
+ }
default:
- System.out.println("Invalid choice❌");
+ System.out.println("Invalid choice❌\nChoose another option: ");
break;
}
}
}
+
+ public static void fight() {
+
+ while (player.isAlive() && enemy.isAlive()) {
+
+ System.out.println("\n" + player.getName() + " - "
+ + player.getMp() + "/" + player.getMaxMP() + " MP | "
+ + player.getHP() + "/" + player.getMaxHP() + " HP");
+
+ System.out.println(enemy.getType() + " - "
+ + enemy.getHP() + "/" + enemy.getMaxHP() + " HP");
+
+ playerTurn();
+
+ if(enemy.isAlive())
+ enemyTurn();
+ }
+
+ if(!player.isAlive()) {
+ System.out.println("💀 You have been defeated...");
+ System.exit(0);
+ }
+
+ else if(!enemy.isAlive()) {
+ handleEnemyDeath();
+ }
+ }
+
+ public static void playerTurn() {
+
+ System.out.println("Your turn: ");
+ Scanner in = new Scanner(System.in);
+
+ while (true) {
+
+ System.out.println("1.light attack\n" +
+ "2.heavy attack (-" + player.getHeavyAttackManaCost() + " Mana)" +
+ "\n3.defend (-" + player.getDefendManaCost() + " Mana)" +
+ "\n4.heal (-" + player.getHealManaCost()+ " Mana)" +
+ "\n5.special move (-" + player.getSpecialAbilityManaCost() + " Mana)");
+ int choice = in.nextInt();
+
+ int manaCost;
+
+ switch (choice) {
+ case 1:
+ player.lightAttack(enemy);
+ return;
+ case 2:
+ manaCost = player.getHeavyAttackManaCost();
+ break;
+ case 3:
+ manaCost = player.getDefendManaCost();
+ break;
+ case 4:
+ manaCost = player.getHealManaCost();
+ break;
+ case 5:
+ manaCost = player.getSpecialAbilityManaCost();
+ break;
+ default:
+ System.out.println("Invalid choice❌\nChoose another option: ");
+ continue;
+ }
+
+ if(player.reduceMana(manaCost)) {
+
+ if(choice == 2) player.heavyAttack(enemy);
+ else if (choice == 3 && !(enemy instanceof Dragon)) player.defend();
+ else if (choice == 4) player.heal(20);
+ else if(choice == 5) player.specialAbility(enemy);
+
+ return;
+ }
+ else
+ System.out.println("You don't have enough Mana\nChoose another...");
+
+ }
+ }
+
+ public static void enemyTurn() { enemy.attack(player);}
+
+ public static void handleEnemyDeath() {
+
+ if(enemy instanceof Skeleton && ((Skeleton) enemy).getReviveEnabled()) {
+ ((Skeleton) enemy).revive();
+ fight();
+ }
+ else if(enemy instanceof Dragon) {
+ System.out.println("Congratulations! You defeated the Dragon and won!");
+ System.exit(0);
+ }
+ else{
+ System.out.println("You won the battle!");
+ player.addXP(enemy.getXpReward());
+ player.fillMana(player.getMaxMP());
+ player.heal(player.getMaxHP());
+ tryDropKey();
+ locations.get(currentLocationIndex).getEnemies().remove(enemy);
+ spawnRandomEnemy();
+ handleLocation();
+ }
+
+ }
+
+ public static void tryDropKey() {
+
+ if(Math.random()<0.2) {
+ if(enemy instanceof Goblin && !player.hasGoblinKey()) {
+ player.giveGoblinKey();
+ System.out.println("You got Goblin key\uD83C\uDF89");
+ }
+ else if(enemy instanceof Skeleton && !player.hasSkeletonKey()) {
+ player.giveSkeletonKey();
+ System.out.println("You got skeleton key\uD83C\uDF89");
+ }
+ else if(enemy instanceof Vampire && !player.hasVampireKey()) {
+ player.giveVampireKey();
+ System.out.println("You got Vampire key\uD83C\uDF89");
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java b/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java
index 18423c9..1f91deb 100644
--- a/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java
+++ b/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java
@@ -19,7 +19,7 @@ public class Goblin extends Enemy {
if(Math.random()