implement Main
This commit is contained in:
@@ -1,15 +1,286 @@
|
|||||||
package org.project;
|
package org.project;
|
||||||
|
|
||||||
|
import org.project.entity.enemies.*;
|
||||||
|
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.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.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
|
||||||
List<Location> locations = new ArrayList<>();
|
|
||||||
|
|
||||||
// TODO: IMPLEMENT GAMEPLAY
|
private static List<Location> locations = new ArrayList<>();
|
||||||
|
public static Player player;
|
||||||
|
private static Enemy enemy;
|
||||||
|
private static int currentLocationIndex;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
createPlayer();
|
||||||
|
setupLocations();
|
||||||
|
chooseLocation();
|
||||||
|
spawnRandomEnemy();
|
||||||
|
handleLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
fight();
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
chooseLocation();
|
||||||
|
spawnRandomEnemy();
|
||||||
|
handleLocation();
|
||||||
|
fight();
|
||||||
|
return;
|
||||||
|
case 3:
|
||||||
|
if(player.hasGoblinKey() && player.hasVampireKey() && player.hasSkeletonKey()) {
|
||||||
|
enemy = new Dragon();
|
||||||
|
fight();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
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 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() {
|
||||||
|
|
||||||
|
ArrayList<Enemy> CryptEnemies = new ArrayList<>();
|
||||||
|
CryptEnemies.add(new Skeleton());
|
||||||
|
CryptEnemies.add(new Goblin());
|
||||||
|
locations.add(new Location("Crypt", CryptEnemies));
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Enemy> WarrensEnemies = new ArrayList<>();
|
||||||
|
WarrensEnemies.add(new Goblin());
|
||||||
|
WarrensEnemies.add(new Goblin());
|
||||||
|
WarrensEnemies.add(new Skeleton());
|
||||||
|
locations.add(new Location("Warrens️", WarrensEnemies));
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Enemy> ManorEnemies = new ArrayList<>();
|
||||||
|
ManorEnemies.add(new Vampire());
|
||||||
|
ManorEnemies.add(new Skeleton());
|
||||||
|
locations.add(new Location("Manor️", ManorEnemies));
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Enemy> CourtyardEnemies = new ArrayList<>();
|
||||||
|
CourtyardEnemies.add(new Vampire());
|
||||||
|
CourtyardEnemies.add(new Goblin());
|
||||||
|
CourtyardEnemies.add(new Skeleton());
|
||||||
|
locations.add(new Location("Courtyard", CourtyardEnemies));
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Enemy> CatacombsEnemies = new ArrayList<>();
|
||||||
|
CatacombsEnemies.add(new Skeleton());
|
||||||
|
CatacombsEnemies.add(new Goblin());
|
||||||
|
CatacombsEnemies.add(new Vampire());
|
||||||
|
CatacombsEnemies.add(new Goblin());
|
||||||
|
locations.add(new Location("Catacombs", CatacombsEnemies));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void createPlayer() {
|
||||||
|
|
||||||
|
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️");
|
||||||
|
|
||||||
|
|
||||||
|
int choice = in.nextInt();
|
||||||
|
switch (choice) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
player = new Knight(name);
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
player = new Wizard(name);
|
||||||
|
return;
|
||||||
|
case 3:
|
||||||
|
player = new Assassin(name);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid choice❌");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user