edit player and Main
This commit is contained in:
Generated
+5
@@ -16,5 +16,10 @@
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</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>
|
||||
</project>
|
||||
@@ -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 ; i<locations.size() ; i++) {
|
||||
System.out.println((int)(i+1) +". "+ locations.get(i).getName());
|
||||
}
|
||||
|
||||
int choice = in.nextInt();
|
||||
if(choice>0 && 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<Enemy> 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) {
|
||||
|
||||
while (true){
|
||||
|
||||
System.out.println("Choose your character: \n" +
|
||||
"1. Knight⚔️\n" +
|
||||
"2. Wizard\uD83E\uDDD9\u200D♂️\n" +
|
||||
"3. Assassin\uD83D\uDDE1️");
|
||||
|
||||
for(int i=0 ; i<locations.size() ; i++) {
|
||||
System.out.println((i+1) +". "+ locations.get(i).getName());
|
||||
}
|
||||
|
||||
int choice = in.nextInt();
|
||||
switch (choice) {
|
||||
if(choice>0 && 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<Enemy> 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);
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class Goblin extends Enemy {
|
||||
|
||||
if(Math.random()<critChance && !isStunned()) {
|
||||
target.takeDamage((int) (stats.damage * critMultiplier));
|
||||
System.out.println("The goblin landed a critical hit!");
|
||||
if(!target.isDefending()) System.out.println("The goblin landed a critical hit!");
|
||||
}
|
||||
else
|
||||
super.attack(target);
|
||||
|
||||
@@ -20,6 +20,6 @@ public class Assassin extends Player{
|
||||
public void specialAbility(Enemy target) {
|
||||
System.out.println("You turned invisible");
|
||||
target.takeDamage(stats.specialAbilityDamage); // causing damage
|
||||
setDefensing(true); //dodging the next incoming attack
|
||||
setDefending(true); //dodging the next incoming attack
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ public class Knight extends Player {
|
||||
public void specialAbility(Enemy target) {
|
||||
target.takeDamage(stats.specialAbilityDamage); //causing damage
|
||||
target.setStunned(true); //stun the enemy
|
||||
System.out.println(getName() + "You performed a shield bash that stunned the enemy.");
|
||||
System.out.println("You performed a shield bash that stunned the enemy.");
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.entity.enemies.Vampire;
|
||||
|
||||
|
||||
public abstract class Player extends Entity{
|
||||
@@ -10,7 +9,7 @@ public abstract class Player extends Entity{
|
||||
protected final PlayerStats stats;
|
||||
protected String name;
|
||||
private int mp;
|
||||
private boolean defensing;
|
||||
private boolean defending;
|
||||
private int XP;
|
||||
private boolean skeletonKey;
|
||||
private boolean goblinKey;
|
||||
@@ -24,7 +23,7 @@ public abstract class Player extends Entity{
|
||||
this.stats = stats;
|
||||
|
||||
XP = 0;
|
||||
defensing = false;
|
||||
defending = false;
|
||||
goblinKey = false;
|
||||
skeletonKey = false;
|
||||
vampireKey = false;
|
||||
@@ -37,17 +36,17 @@ public abstract class Player extends Entity{
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
if(!isDefensing()){
|
||||
if(!isDefending()){
|
||||
super.takeDamage(damage);
|
||||
System.out.println("Enemy's attack dealt " + damage + " damage to you!");
|
||||
}
|
||||
else {
|
||||
System.out.println("You blocked the attack!");
|
||||
defensing = false;
|
||||
defending = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void defend() { setDefensing(true); }
|
||||
public void defend() { setDefending(true); }
|
||||
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
@@ -65,7 +64,13 @@ public abstract class Player extends Entity{
|
||||
}
|
||||
|
||||
|
||||
public PlayerStats getStats() {return stats;}
|
||||
public int getHeavyAttackManaCost() {return stats.heavyAttackManaCost;}
|
||||
|
||||
public int getDefendManaCost() {return stats.defendManaCost;}
|
||||
|
||||
public int getHealManaCost() {return stats.healManaCost;}
|
||||
|
||||
public int getSpecialAbilityManaCost() {return stats.specialAbilityManaCost;}
|
||||
|
||||
public String getName() { return name; }
|
||||
|
||||
@@ -81,8 +86,8 @@ public abstract class Player extends Entity{
|
||||
public void giveSkeletonKey() { skeletonKey = true; }
|
||||
public void giveVampireKey() { vampireKey = true; }
|
||||
|
||||
public boolean isDefensing() { return defensing; }
|
||||
public void setDefensing(boolean defensing) {this.defensing = defensing; }
|
||||
public boolean isDefending() { return defending; }
|
||||
public void setDefending(boolean value) {this.defending = value; }
|
||||
|
||||
public int getXP() { return XP;}
|
||||
public void addXP(int amount) { XP += amount; }
|
||||
|
||||
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.
Reference in New Issue
Block a user