enhance engines
This commit is contained in:
@@ -2,13 +2,17 @@ package org.project.engine;
|
||||
|
||||
import org.project.constants.appConstants.ConsoleColor;
|
||||
import org.project.constants.appConstants.TextColor;
|
||||
import org.project.constants.gameConstant.ItemClass;
|
||||
import org.project.entity.players.Assassin;
|
||||
import org.project.entity.players.Knight;
|
||||
import org.project.constants.gameConstant.*;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.entity.players.Wizard;
|
||||
import org.project.item.Accessory.Accessory;
|
||||
import org.project.item.Accessory.Shield;
|
||||
import org.project.item.Item;
|
||||
import org.project.location.*;
|
||||
import org.project.util.DisplayItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SinglePlayerEngine extends MainEngine {
|
||||
@@ -28,55 +32,75 @@ public class SinglePlayerEngine extends MainEngine {
|
||||
System.out.println("How should me call you, hero? ");
|
||||
String name = scanner.nextLine();
|
||||
|
||||
boolean InValidInput = false;
|
||||
do {
|
||||
System.out.println("Greetings, " + name + ". May we know your role? \n" +
|
||||
"0 > Wizard" +
|
||||
"1 > Assassin" +
|
||||
"2 > Knight");
|
||||
System.out.println("Greetings, " + name + ". May we know your role? \n");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
player = RoleMenu(name);
|
||||
|
||||
switch (choice) {
|
||||
case 0 -> player = new Wizard(name);
|
||||
case 1 -> player = new Assassin(name);
|
||||
case 2 -> player = new Knight(name);
|
||||
default -> InValidInput = true;
|
||||
}
|
||||
} while (InValidInput);
|
||||
|
||||
System.out.println("Very well, " + TextColor.Cyan + GetIntro() + ConsoleColor.Reset + " your journey begins!");
|
||||
System.out.println("Very well, " + TextColor.Cyan + player.Name + ConsoleColor.Reset + " your journey begins!");
|
||||
System.out.println();
|
||||
|
||||
while (true) {
|
||||
boolean canFightDragon = false;
|
||||
if (player.GetInventoryByClass(ItemClass.KEY).size() == 3) {
|
||||
canFightDragon = true;
|
||||
}
|
||||
boolean canFightDragon = player.GetInventoryByClass(ItemClass.KEY).size() == 3;
|
||||
|
||||
Location location = Location.RandomLocation();
|
||||
System.out.println(GetLocationIntro(location));
|
||||
|
||||
while (true) {
|
||||
boolean continueLoop = false;
|
||||
do {
|
||||
System.out.println(GetLocationIntro(location));
|
||||
System.out.println("What do you do, " + player.Name + "?");
|
||||
System.out.println(
|
||||
"0 > FIGHT!\n" +
|
||||
"1 > Go to the next location\n" +
|
||||
"2 > Visit the market place in the town"
|
||||
"""
|
||||
0 > FIGHT!
|
||||
1 > Go to the next location
|
||||
2 > Visit the market place in the town
|
||||
3 > Check inventory"""
|
||||
);
|
||||
if (canFightDragon) {
|
||||
System.out.println("3 > Go to the castle to face the dragon");
|
||||
System.out.println("4 > Go to the castle to face the dragon");
|
||||
}
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 0 -> {
|
||||
|
||||
System.out.println(TextColor.Red + "You choice to FIGHT!" + TextColor.Reset);
|
||||
BattleEngine engine = new SinglePlayerBattleEngine(player, location.enemy);
|
||||
engine.StartBattle();
|
||||
continueLoop = false;
|
||||
}
|
||||
case 1 -> {
|
||||
continueLoop = false;
|
||||
}
|
||||
case 2 -> {
|
||||
MarketPlace();
|
||||
continueLoop = false;
|
||||
}
|
||||
case 3 -> {
|
||||
InventoryView();
|
||||
continueLoop = true;
|
||||
}
|
||||
case 4 -> {
|
||||
if (canFightDragon) {
|
||||
location = new Castle();
|
||||
continueLoop = false;
|
||||
}
|
||||
else {
|
||||
continueLoop = true;
|
||||
}
|
||||
}
|
||||
default -> continueLoop = true;
|
||||
}
|
||||
} while (continueLoop);
|
||||
|
||||
if (player.GetState() == EntityState.DEAD) {
|
||||
System.out.println(TextColor.Red + "Game Over!" + TextColor.Reset);
|
||||
break;
|
||||
}
|
||||
|
||||
if (player.GetInventoryByClass(ItemClass.KEY).size() == 4) {
|
||||
System.out.println(TextColor.Blue + "You WON! You saved Javanest!" + TextColor.Reset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,20 +109,221 @@ public class SinglePlayerEngine extends MainEngine {
|
||||
}
|
||||
|
||||
public String GetLocationIntro(Location location) {
|
||||
if (location instanceof Jungle) {
|
||||
return player.Name + " enters the woods, after a few steps, they see a green goblin searching for food a few steps away";
|
||||
return switch (location) {
|
||||
case Jungle jungle ->
|
||||
player.Name + " enters the woods, after a few steps, they see a green goblin searching for food a few steps away";
|
||||
case GraveYard graveYard ->
|
||||
player.Name + " goes inside the grave ward, they cannot see a more than 10 steps ahead because of the fog in the air. After lurking through out the graves, the shadow appears... It's a skeleton!";
|
||||
case DarkCaves darkCaves ->
|
||||
player.Name + " dives into the darkness. As our hero was going deeper, a black smoke appears, a vampire is nearby...";
|
||||
case Castle castle ->
|
||||
player.Name + " Goes through the gates, the dragon looks at " + player.Name + "... It knows that an epic battle awaits both it them";
|
||||
case null, default -> "";
|
||||
};
|
||||
}
|
||||
|
||||
public void MarketPlace() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("You've entered the marketplace, what would you like to do?");
|
||||
boolean wantsToStay = true;
|
||||
while (wantsToStay) {
|
||||
System.out.println("Money = " + player.GetMoney() + "\n");
|
||||
System.out.println("""
|
||||
0 > Show Inventory
|
||||
1 > Sell Unnecessary goods
|
||||
2 > Sell the accessories
|
||||
3 > Sell the shields
|
||||
4 > Sell the costumes
|
||||
5 > Sell the Weapons
|
||||
6 > Buy shields
|
||||
7 > Buy shields
|
||||
8 > Buy shields
|
||||
9 > Exit
|
||||
""");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 0 -> DisplayItem.DisplayItems(player.GetInventory());
|
||||
case 1 -> {
|
||||
player.SellByClass(ItemClass.UNNECESSARY);
|
||||
System.out.println(TextColor.Green + "Unnecessary goods sold" + TextColor.Reset);
|
||||
}
|
||||
case 2 -> {
|
||||
player.SellByClass(ItemClass.ACCESSORY);
|
||||
System.out.println(TextColor.Green + "accessories sold" + TextColor.Reset);
|
||||
}
|
||||
case 3 -> {
|
||||
player.SellByClass(ItemClass.SHIELD);
|
||||
System.out.println(TextColor.Green + "shields sold" + TextColor.Reset);
|
||||
}
|
||||
case 4 -> {
|
||||
player.SellByClass(ItemClass.COSTUME);
|
||||
System.out.println(TextColor.Green + "costumes sold" + TextColor.Reset);
|
||||
}
|
||||
case 5 -> {
|
||||
player.SellByClass(ItemClass.WEAPON);
|
||||
System.out.println(TextColor.Green + "weapons sold" + TextColor.Reset);
|
||||
}
|
||||
case 6 -> {
|
||||
System.out.println("Money = " + player.GetMoney() + "\n");
|
||||
|
||||
System.out.println(TextColor.Blue + "Current shield: ");
|
||||
ArrayList<Item> item = new ArrayList<>();
|
||||
item.add(player.Shield);
|
||||
DisplayItem.DisplayItems(item);
|
||||
System.out.println(TextColor.Reset);
|
||||
|
||||
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Shields.getShields()));
|
||||
Dictionary<Integer, Item> dictionary = DisplayItem.MenuDisplay(items);
|
||||
|
||||
System.out.println("Please set the number of the accessory you want to buy, set any other number to abort:");
|
||||
Integer index = scanner.nextInt();
|
||||
Item shield = dictionary.get(index);
|
||||
Accessory accessory = (Accessory) shield;
|
||||
|
||||
if (accessory != null) {
|
||||
if (player.GetMoney() >= accessory.GetPrice()) {
|
||||
accessory.AttachTo(player);
|
||||
player.ModifyMoney(accessory.GetPrice(), false);
|
||||
}
|
||||
else {
|
||||
System.out.println(TextColor.Red + "You do not have enough money" + TextColor.Reset);
|
||||
}
|
||||
}
|
||||
}
|
||||
case 7 -> {
|
||||
System.out.println("Money = " + player.GetMoney() + "\n");
|
||||
|
||||
System.out.println(TextColor.Blue + "Current weapon: ");
|
||||
ArrayList<Item> item = new ArrayList<>();
|
||||
item.add(player.Weapon);
|
||||
DisplayItem.DisplayItems(item);
|
||||
System.out.println(TextColor.Reset);
|
||||
|
||||
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Weapons.getWeapons()));
|
||||
Dictionary<Integer, Item> dictionary = DisplayItem.MenuDisplay(items);
|
||||
|
||||
System.out.println("Please set the number of the accessory you want to buy, set any other number to abort:");
|
||||
Integer index = scanner.nextInt();
|
||||
Item weapon = dictionary.get(index);
|
||||
Accessory accessory = (Accessory) weapon;
|
||||
|
||||
if (accessory != null) {
|
||||
if (player.GetMoney() >= accessory.GetPrice()) {
|
||||
accessory.AttachTo(player);
|
||||
player.ModifyMoney(accessory.GetPrice(), false);
|
||||
}
|
||||
else {
|
||||
System.out.println(TextColor.Red + "You do not have enough money" + TextColor.Reset);
|
||||
}
|
||||
}
|
||||
}
|
||||
case 8 -> {
|
||||
System.out.println("Money = " + player.GetMoney() + "\n");
|
||||
|
||||
System.out.println(TextColor.Blue + "Current costume: ");
|
||||
ArrayList<Item> item = new ArrayList<>();
|
||||
item.add(player.Costume);
|
||||
DisplayItem.DisplayItems(item);
|
||||
System.out.println(TextColor.Reset);
|
||||
|
||||
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Costumes.getCostumes()));
|
||||
Dictionary<Integer, Item> dictionary = DisplayItem.MenuDisplay(items);
|
||||
|
||||
System.out.println("Please set the number of the accessory you want to buy, set any other number to abort:");
|
||||
Integer index = scanner.nextInt();
|
||||
Item costume = dictionary.get(index);
|
||||
Accessory accessory = (Accessory) costume;
|
||||
|
||||
if (accessory != null) {
|
||||
if (player.GetMoney() >= accessory.GetPrice()) {
|
||||
accessory.AttachTo(player);
|
||||
player.ModifyMoney(accessory.GetPrice(), false);
|
||||
}
|
||||
else {
|
||||
System.out.println(TextColor.Red + "You do not have enough money" + TextColor.Reset);
|
||||
}
|
||||
}
|
||||
}
|
||||
case 9 -> wantsToStay = false;
|
||||
}
|
||||
}
|
||||
else if (location instanceof GraveYard) {
|
||||
return player.Name + " goes inside the grave ward, they cannot see a more than 10 steps ahead because of the fog in the air. After lurking through out the graves, the shadow appears... It's a skeleton!";
|
||||
}
|
||||
else if (location instanceof DarkCaves) {
|
||||
return player.Name + " dives into the darkness. As our hero was going deeper, a black smoke appears, a vampire is nearby...";
|
||||
}
|
||||
else if (location instanceof Castle) {
|
||||
return player.Name + " Goes through the gates, the dragon looks at " + player.Name + "... It knows that an epic battle awaits both it them";
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void InventoryView() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("You open your inventory, what would you like to do?");
|
||||
boolean wantsToStay = true;
|
||||
while (wantsToStay) {
|
||||
System.out.println("Money = " + player.GetMoney() + "\n");
|
||||
System.out.println("""
|
||||
0 > Show Inventory
|
||||
1 > Show Shields
|
||||
2 > Show Weapons
|
||||
3 > Show Costumes
|
||||
4 > Exit
|
||||
""");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 0 -> DisplayItem.DisplayItems(player.GetInventory());
|
||||
case 1 -> {
|
||||
System.out.println(TextColor.Blue + "Current shield: ");
|
||||
ArrayList<Item> item = new ArrayList<>();
|
||||
item.add(player.Shield);
|
||||
DisplayItem.DisplayItems(item);
|
||||
System.out.println(TextColor.Reset);
|
||||
|
||||
Dictionary<Integer, Item> dictionary = DisplayItem.MenuDisplay(player.GetInventoryByClass(ItemClass.SHIELD));
|
||||
|
||||
System.out.println("Please set the number of the accessory you want to wear, set any other number to abort:");
|
||||
Integer index = scanner.nextInt();
|
||||
Item shield = dictionary.get(index);
|
||||
|
||||
if (shield != null) {
|
||||
((Accessory) shield).AttachTo(player);
|
||||
}
|
||||
}
|
||||
case 2 -> {
|
||||
System.out.println(TextColor.Blue + "Current weapon: ");
|
||||
ArrayList<Item> item = new ArrayList<>();
|
||||
item.add(player.Weapon);
|
||||
DisplayItem.DisplayItems(item);
|
||||
System.out.println(TextColor.Reset);
|
||||
|
||||
Dictionary<Integer, Item> dictionary = DisplayItem.MenuDisplay(player.GetInventoryByClass(ItemClass.WEAPON));
|
||||
|
||||
System.out.println("Please set the number of the accessory you want to wear, set any other number to abort:");
|
||||
Integer index = scanner.nextInt();
|
||||
Item weapon = dictionary.get(index);
|
||||
|
||||
if (weapon != null) {
|
||||
((Accessory) weapon).AttachTo(player);
|
||||
}
|
||||
}
|
||||
case 3 -> {
|
||||
System.out.println(TextColor.Blue + "Current costume: ");
|
||||
ArrayList<Item> item = new ArrayList<>();
|
||||
item.add(player.Costume);
|
||||
DisplayItem.DisplayItems(item);
|
||||
System.out.println(TextColor.Reset);
|
||||
|
||||
Dictionary<Integer, Item> dictionary = DisplayItem.MenuDisplay(player.GetInventoryByClass(ItemClass.COSTUME));
|
||||
|
||||
System.out.println("Please set the number of the accessory you want to wear, set any other number to abort:");
|
||||
Integer index = scanner.nextInt();
|
||||
Item costume = dictionary.get(index);
|
||||
|
||||
if (costume != null) {
|
||||
((Accessory) costume).AttachTo(player);
|
||||
}
|
||||
}
|
||||
case 4 -> wantsToStay = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user