final edit
This commit is contained in:
@@ -22,16 +22,25 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
createPlayer();
|
||||
setupLocations();
|
||||
chooseLocation();
|
||||
spawnRandomEnemy();
|
||||
handleLocation();
|
||||
gameLoop();
|
||||
}
|
||||
|
||||
public static void gameLoop() {
|
||||
|
||||
while (player.isAlive()) {
|
||||
|
||||
chooseLocation();
|
||||
spawnRandomEnemy();
|
||||
if(enemy != null) handleLocation();
|
||||
|
||||
}
|
||||
}
|
||||
public static void createPlayer() {
|
||||
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.println("Enter your name: ");
|
||||
System.out.println("Welcome to Java Knight ⚔\uFE0F\nPlease enter your name: ");
|
||||
String name = in.nextLine();
|
||||
System.out.println("Hi " + name + "\uD83C\uDF89\n");
|
||||
|
||||
|
||||
while (true){
|
||||
@@ -47,15 +56,18 @@ public class Main {
|
||||
|
||||
case 1:
|
||||
player = new Knight(name);
|
||||
System.out.println("You are a KNIGHT⚔️\n");
|
||||
return;
|
||||
case 2:
|
||||
player = new Wizard(name);
|
||||
System.out.println("You are a Wizard\uD83E\uDDD9\u200D♂️\n");
|
||||
return;
|
||||
case 3:
|
||||
player = new Assassin(name);
|
||||
System.out.println("You are a Assassin\uD83D\uDDE1\n️️");
|
||||
return;
|
||||
default:
|
||||
System.out.println("Invalid choice❌");
|
||||
System.out.println("\u001B[31m❌Invalid choice❌\u001B[0m");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -113,11 +125,11 @@ public class Main {
|
||||
int choice = in.nextInt();
|
||||
if(choice>0 && choice<=locations.size()) {
|
||||
currentLocationIndex = choice - 1;
|
||||
System.out.println("You're in " + locations.get(currentLocationIndex).getName());
|
||||
System.out.println("\uD83D\uDCCD Location: " + locations.get(currentLocationIndex).getName());
|
||||
return;
|
||||
}
|
||||
else
|
||||
System.out.println("Invalid choice❌\nChoose another option: ");
|
||||
System.out.println("\u001B[31m❌Invalid choice❌\u001B[0m\nChoose another option: ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +137,11 @@ public class Main {
|
||||
|
||||
ArrayList<Enemy> enemies = locations.get(currentLocationIndex).getEnemies();
|
||||
Random random = new Random();
|
||||
if(enemies.isEmpty()) {
|
||||
System.out.println("No enemies found in " + locations.get(currentLocationIndex).getName() + "...\n");
|
||||
enemy = null;
|
||||
return;
|
||||
}
|
||||
int currentEnemyIndex = random.nextInt(enemies.size());
|
||||
enemy = locations.get(currentLocationIndex).getEnemy(currentEnemyIndex);
|
||||
System.out.println("You're facing a " + enemy.getType());
|
||||
@@ -139,9 +156,9 @@ public class Main {
|
||||
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");
|
||||
System.out.println("1. Fight the " + enemy.getType() + "\uD83E\uDD4A" +
|
||||
"\n2. Go to another location\uD83D\uDCCD\n" +
|
||||
"3. Go to the Castle to fight the Dragon\uD83D\uDC09");
|
||||
|
||||
int choice = in.nextInt();
|
||||
|
||||
@@ -150,9 +167,6 @@ public class Main {
|
||||
fight();
|
||||
return;
|
||||
case 2:
|
||||
chooseLocation();
|
||||
spawnRandomEnemy();
|
||||
handleLocation();
|
||||
return;
|
||||
case 3:
|
||||
if(player.hasGoblinKey() && player.hasVampireKey() && player.hasSkeletonKey()) {
|
||||
@@ -161,11 +175,11 @@ public class Main {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
System.out.println("❌You don't have all the keys❌");
|
||||
System.out.println("You don't have all the keys\uD83D\uDD12\n");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
System.out.println("Invalid choice❌\nChoose another option: ");
|
||||
System.out.println("\u001B[31m❌Invalid choice❌\u001B[0m\nChoose another option: ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -175,12 +189,12 @@ public class Main {
|
||||
|
||||
while (player.isAlive() && enemy.isAlive()) {
|
||||
|
||||
System.out.println("\n" + player.getName() + " - "
|
||||
System.out.println("\n[" + player.getName() + " - "
|
||||
+ player.getMp() + "/" + player.getMaxMP() + " MP | "
|
||||
+ player.getHP() + "/" + player.getMaxHP() + " HP");
|
||||
+ player.getHP() + "/" + player.getMaxHP() + " HP]");
|
||||
|
||||
System.out.println(enemy.getType() + " - "
|
||||
+ enemy.getHP() + "/" + enemy.getMaxHP() + " HP");
|
||||
System.out.println('[' + enemy.getType() + " - "
|
||||
+ enemy.getHP() + "/" + enemy.getMaxHP() + " HP]\n");
|
||||
|
||||
playerTurn();
|
||||
|
||||
@@ -190,7 +204,11 @@ public class Main {
|
||||
|
||||
if(!player.isAlive()) {
|
||||
System.out.println("💀 You have been defeated...");
|
||||
System.exit(0);
|
||||
player.setXp(0);
|
||||
player.setGoblinKey(false);
|
||||
player.setVampireKey(false);
|
||||
player.setSkeletonKey(false);
|
||||
setupLocations();
|
||||
}
|
||||
|
||||
else if(!enemy.isAlive()) {
|
||||
@@ -206,10 +224,10 @@ public class Main {
|
||||
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)");
|
||||
"2.heavy attack (\u001B[31m-" + player.getHeavyAttackManaCost() + " Mana\u001B[0m)" +
|
||||
"\n3.defend (\u001B[31m-" + player.getDefendManaCost() + " Mana\u001B[0m)" +
|
||||
"\n4.heal (\u001B[31m-" + player.getHealManaCost()+ " Mana\u001B[0m)" +
|
||||
"\n5.special move (\u001B[31m-" + player.getSpecialAbilityManaCost() + " Mana\u001B[0m)");
|
||||
int choice = in.nextInt();
|
||||
|
||||
int manaCost;
|
||||
@@ -231,7 +249,7 @@ public class Main {
|
||||
manaCost = player.getSpecialAbilityManaCost();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid choice❌\nChoose another option: ");
|
||||
System.out.println("\u001B[31m❌Invalid choice❌\u001B[0m\nChoose another option: ");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -259,18 +277,17 @@ public class Main {
|
||||
fight();
|
||||
}
|
||||
else if(enemy instanceof Dragon) {
|
||||
System.out.println("Congratulations! You defeated the Dragon and won!");
|
||||
System.exit(0);
|
||||
System.out.println("\nCongratulations! You defeated the Dragon and won!\uD83C\uDFC6");
|
||||
}
|
||||
else{
|
||||
System.out.println("You won the battle!");
|
||||
System.out.println("\nYou won the battle!\uD83C\uDF89");
|
||||
player.addXP(enemy.getXpReward());
|
||||
System.out.println("You gained " + enemy.getXpReward() + " XP");
|
||||
player.fillMana(player.getMaxMP());
|
||||
player.heal(player.getMaxHP());
|
||||
System.out.println("\u001B[32mHP and Mana fully restored\u001B[0m\n");
|
||||
tryDropKey();
|
||||
locations.get(currentLocationIndex).getEnemies().remove(enemy);
|
||||
spawnRandomEnemy();
|
||||
handleLocation();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -279,16 +296,16 @@ public class Main {
|
||||
|
||||
if(Math.random()<0.2) {
|
||||
if(enemy instanceof Goblin && !player.hasGoblinKey()) {
|
||||
player.giveGoblinKey();
|
||||
System.out.println("You got Goblin key\uD83C\uDF89");
|
||||
player.setGoblinKey(true);
|
||||
System.out.println("You got Goblin key\uD83D\uDD11\n");
|
||||
}
|
||||
else if(enemy instanceof Skeleton && !player.hasSkeletonKey()) {
|
||||
player.giveSkeletonKey();
|
||||
System.out.println("You got skeleton key\uD83C\uDF89");
|
||||
player.setSkeletonKey(true);
|
||||
System.out.println("You got skeleton key\uD83D\uDD11\n");
|
||||
}
|
||||
else if(enemy instanceof Vampire && !player.hasVampireKey()) {
|
||||
player.giveVampireKey();
|
||||
System.out.println("You got Vampire key\uD83C\uDF89");
|
||||
player.setVampireKey(true);
|
||||
System.out.println("You got Vampire key\uD83D\uDD11\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ public abstract class Enemy extends Entity {
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
super.takeDamage(damage);
|
||||
System.out.println("Your attack dealt " + damage + " damage to the enemy!");
|
||||
System.out.println("\u001B[32mYour attack dealt " + damage + " damage to the enemy!\u001B[0m");
|
||||
}
|
||||
|
||||
public void attack(Player target) {
|
||||
if(!stunned) {
|
||||
System.out.println(getType() + " attacked you!");
|
||||
System.out.println("\u001B[31m" + getType() + " attacked you!\u001B[0m");
|
||||
target.takeDamage(stats.damage);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class Player extends Entity{
|
||||
public void takeDamage(int damage) {
|
||||
if(!isDefending()){
|
||||
super.takeDamage(damage);
|
||||
System.out.println("Enemy's attack dealt " + damage + " damage to you!");
|
||||
System.out.println("\u001B[31mEnemy's attack dealt " + damage + " damage to you!\u001B[0m");
|
||||
}
|
||||
else {
|
||||
System.out.println("You blocked the attack!");
|
||||
@@ -82,13 +82,14 @@ public abstract class Player extends Entity{
|
||||
public boolean hasSkeletonKey() {return skeletonKey;}
|
||||
public boolean hasVampireKey() {return vampireKey;}
|
||||
|
||||
public void giveGoblinKey() { goblinKey = true; }
|
||||
public void giveSkeletonKey() { skeletonKey = true; }
|
||||
public void giveVampireKey() { vampireKey = true; }
|
||||
public void setGoblinKey(boolean value) { goblinKey = value; }
|
||||
public void setSkeletonKey(boolean value) { skeletonKey = value; }
|
||||
public void setVampireKey(boolean value) { vampireKey = value; }
|
||||
|
||||
public boolean isDefending() { return defending; }
|
||||
public void setDefending(boolean value) {this.defending = value; }
|
||||
|
||||
public int getXP() { return XP;}
|
||||
public void setXp(int amount) { XP = amount;}
|
||||
public void addXP(int amount) { XP += amount; }
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user