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