fix engines bugs

This commit is contained in:
2026-07-16 16:59:03 +03:30
parent 71f1f272f2
commit 6f39911a34
5 changed files with 173 additions and 86 deletions
@@ -29,10 +29,10 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Cyan + GetIntro() + ConsoleColor.Reset);
System.out.println();
System.out.println("How should me call you, hero? ");
System.out.println("How should we call you, hero? ");
String name = scanner.nextLine();
System.out.println("Greetings, " + name + ". May we know your role? \n");
System.out.println("Greetings, " + TextColor.Cyan + name + TextColor.Reset +". May we know your role? \n");
player = RoleMenu(name);
@@ -46,7 +46,7 @@ public class SinglePlayerEngine extends MainEngine {
boolean continueLoop = false;
do {
System.out.println(GetLocationIntro(location));
System.out.println(TextColor.Cyan + GetLocationIntro(location) + TextColor.Reset);
System.out.println("What do you do, " + player.Name + "?");
System.out.println(
"""
@@ -113,7 +113,7 @@ public class SinglePlayerEngine extends MainEngine {
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!";
player.Name + " goes inside the grave ward, they cannot see further 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 ->
@@ -125,7 +125,7 @@ public class SinglePlayerEngine extends MainEngine {
public void MarketPlace() {
Scanner scanner = new Scanner(System.in);
System.out.println("You've entered the marketplace, what would you like to do?");
System.out.println(TextColor.Cyan + "You've entered the marketplace, what would you like to do?" + TextColor.Reset);
boolean wantsToStay = true;
while (wantsToStay) {
System.out.println("Money = " + player.GetMoney() + "\n");
@@ -137,15 +137,21 @@ public class SinglePlayerEngine extends MainEngine {
4 > Sell the costumes
5 > Sell the Weapons
6 > Buy shields
7 > Buy shields
8 > Buy shields
7 > Buy weapon
8 > Buy costume
9 > Exit
""");
int choice = scanner.nextInt();
switch (choice) {
case 0 -> DisplayItem.DisplayItems(player.GetInventory());
case 0 -> {
if (player.GetInventory().isEmpty()) {
System.out.println(TextColor.Red + "You do not have anything at the moment" + TextColor.Reset);
break;
}
DisplayItem.DisplayItems(player.GetInventory());
}
case 1 -> {
player.SellByClass(ItemClass.UNNECESSARY);
System.out.println(TextColor.Green + "Unnecessary goods sold" + TextColor.Reset);
@@ -171,8 +177,13 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Blue + "Current shield: ");
ArrayList<Item> item = new ArrayList<>();
item.add(player.Shield);
DisplayItem.DisplayItems(item);
if (player.Shield == null) {
System.out.println(TextColor.Red + "You do not have a Shield" + TextColor.Reset);
}
else {
item.add(player.Shield);
DisplayItem.DisplayItems(item);
}
System.out.println(TextColor.Reset);
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Shields.getShields()));
@@ -185,7 +196,8 @@ public class SinglePlayerEngine extends MainEngine {
if (accessory != null) {
if (player.GetMoney() >= accessory.GetPrice()) {
accessory.AttachTo(player);
if (player.Shield != null) player.Shield.DeattachFrom(player, true);
accessory.AttachTo(player, false);
player.ModifyMoney(accessory.GetPrice(), false);
}
else {
@@ -198,8 +210,13 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Blue + "Current weapon: ");
ArrayList<Item> item = new ArrayList<>();
item.add(player.Weapon);
DisplayItem.DisplayItems(item);
if (player.Weapon == null) {
System.out.println(TextColor.Red + "You do not have a Weapon" + TextColor.Reset);
}
else {
item.add(player.Weapon);
DisplayItem.DisplayItems(item);
}
System.out.println(TextColor.Reset);
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Weapons.getWeapons()));
@@ -212,7 +229,8 @@ public class SinglePlayerEngine extends MainEngine {
if (accessory != null) {
if (player.GetMoney() >= accessory.GetPrice()) {
accessory.AttachTo(player);
if (player.Weapon != null) player.Weapon.DeattachFrom(player, true);
accessory.AttachTo(player, false);
player.ModifyMoney(accessory.GetPrice(), false);
}
else {
@@ -225,8 +243,13 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Blue + "Current costume: ");
ArrayList<Item> item = new ArrayList<>();
item.add(player.Costume);
DisplayItem.DisplayItems(item);
if (player.Costume == null) {
System.out.println(TextColor.Red + "You do not have a Costume" + TextColor.Reset);
}
else {
item.add(player.Costume);
DisplayItem.DisplayItems(item);
}
System.out.println(TextColor.Reset);
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Costumes.getCostumes()));
@@ -239,7 +262,8 @@ public class SinglePlayerEngine extends MainEngine {
if (accessory != null) {
if (player.GetMoney() >= accessory.GetPrice()) {
accessory.AttachTo(player);
if (player.Costume != null) player.Costume.DeattachFrom(player, true);
accessory.AttachTo(player, false);
player.ModifyMoney(accessory.GetPrice(), false);
}
else {
@@ -255,7 +279,8 @@ public class SinglePlayerEngine extends MainEngine {
public void InventoryView() {
Scanner scanner = new Scanner(System.in);
System.out.println("You open your inventory, what would you like to do?");
System.out.println(TextColor.Cyan + "You open your inventory, what would you like to do?\n" + TextColor.Reset);
boolean wantsToStay = true;
while (wantsToStay) {
System.out.println("Money = " + player.GetMoney() + "\n");
@@ -270,10 +295,20 @@ public class SinglePlayerEngine extends MainEngine {
int choice = scanner.nextInt();
switch (choice) {
case 0 -> DisplayItem.DisplayItems(player.GetInventory());
case 0 -> {
if (player.GetInventory().isEmpty()) {
System.out.println(TextColor.Red + "You do not have anything at the moment" + TextColor.Reset);
break;
}
DisplayItem.DisplayItems(player.GetInventory());
}
case 1 -> {
System.out.println(TextColor.Blue + "Current shield: ");
ArrayList<Item> item = new ArrayList<>();
if (player.Shield == null) {
System.out.println(TextColor.Red + "You do not have a Shield" + TextColor.Reset);
break;
}
item.add(player.Shield);
DisplayItem.DisplayItems(item);
System.out.println(TextColor.Reset);
@@ -285,12 +320,17 @@ public class SinglePlayerEngine extends MainEngine {
Item shield = dictionary.get(index);
if (shield != null) {
((Accessory) shield).AttachTo(player);
if (player.Shield != null) player.Shield.DeattachFrom(player, true);
((Accessory) shield).AttachTo(player, true);
}
}
case 2 -> {
System.out.println(TextColor.Blue + "Current weapon: ");
ArrayList<Item> item = new ArrayList<>();
if (player.Weapon == null) {
System.out.println(TextColor.Red + "You do not have a Weapon" + TextColor.Reset);
break;
}
item.add(player.Weapon);
DisplayItem.DisplayItems(item);
System.out.println(TextColor.Reset);
@@ -302,12 +342,17 @@ public class SinglePlayerEngine extends MainEngine {
Item weapon = dictionary.get(index);
if (weapon != null) {
((Accessory) weapon).AttachTo(player);
if (player.Weapon != null) player.Weapon.DeattachFrom(player, true);
((Accessory) weapon).AttachTo(player, true);
}
}
case 3 -> {
System.out.println(TextColor.Blue + "Current costume: ");
ArrayList<Item> item = new ArrayList<>();
if (player.Costume == null) {
System.out.println(TextColor.Red + "You do not have a Costume" + TextColor.Reset);
break;
}
item.add(player.Costume);
DisplayItem.DisplayItems(item);
System.out.println(TextColor.Reset);
@@ -319,7 +364,8 @@ public class SinglePlayerEngine extends MainEngine {
Item costume = dictionary.get(index);
if (costume != null) {
((Accessory) costume).AttachTo(player);
if (player.Costume != null) player.Costume.DeattachFrom(player, true);
((Accessory) costume).AttachTo(player, true);
}
}
case 4 -> wantsToStay = false;