diff --git a/src/main/java/command/fight/FightingCommand.java b/src/main/java/command/fight/FightingCommand.java index 1463ee8ff5..61b66218c8 100644 --- a/src/main/java/command/fight/FightingCommand.java +++ b/src/main/java/command/fight/FightingCommand.java @@ -1,6 +1,7 @@ package command.fight; import command.Command; import map.BaseMap; +import map.ShopMap; import java.util.Scanner; @@ -20,15 +21,22 @@ public void execute() { @Override public void execute(Scanner in) { - currentMap.enableFight(in); - BaseMap.currentMap = mapIndex.get(FIRST_MAP_IDENTITY); - if (currentMap.getEntityDeath()){ - int xPos = storedMaps.get(BaseMap.currentMap).getInteractX(); - int yPos = storedMaps.get(BaseMap.currentMap).getInteractY(); - storedMaps.get(BaseMap.currentMap).clearSpot(xPos, yPos); - currentMap.handleLootingByPlayer(); - } else if (currentMap.getPlayerDeath()){ - currentMap.handleDeath(); + if (currentMap instanceof map.battleinterface.BattleInterface) { + currentMap.enableFight(in); + BaseMap.currentMap = mapIndex.get(FIRST_MAP_IDENTITY); + if (currentMap.getEntityDeath()) { + int xPos = storedMaps.get(BaseMap.currentMap).getInteractX(); + int yPos = storedMaps.get(BaseMap.currentMap).getInteractY(); + storedMaps.get(BaseMap.currentMap).clearSpot(xPos, yPos); + currentMap.handleLootingByPlayer(); + } else if (currentMap.getPlayerDeath()) { + currentMap.handleDeath(); + } + } + + if (currentMap instanceof ShopMap) { + currentMap.enableFight(in); + BaseMap.currentMap = mapIndex.get(FIRST_MAP_IDENTITY); } } } diff --git a/src/main/java/command/mapmove/InteractingCommand.java b/src/main/java/command/mapmove/InteractingCommand.java index 458c8a5da5..ecf8cd571f 100644 --- a/src/main/java/command/mapmove/InteractingCommand.java +++ b/src/main/java/command/mapmove/InteractingCommand.java @@ -13,6 +13,7 @@ import java.util.Objects; +import static main.CalculaChroniclesOfTheAlgorithmicKingdom.PLAYER_INVENTORY; import static map.BaseMap.storedMaps; import static map.BaseMap.mapIndex; import static map.MapGenerator.CENTAUR; @@ -61,7 +62,7 @@ public void execute() { break; case DEMON: monster = new Demon(15, 15, 15, xPos, yPos, 15, 15); - textBox.setNextDialogue("*the " + monster.getName() + " stares at you menacingly*"); + textBox.setNextDialogue("*the " + monster.getName() + " growls at you menacingly*"); battleMap = new BattleInterface(playerStatus, textBox, monster); battleMap.initMap(30, monster.getHeight()); storedMaps.add(battleMap); @@ -70,7 +71,7 @@ public void execute() { break; case DRAGON: monster = new Dragon(20, 20, 20, xPos, yPos, 20, 20); - textBox.setNextDialogue("*the " + monster.getName() + " stares at you menacingly*"); + textBox.setNextDialogue("*the " + monster.getName() + " breathes a ball of flame menacingly*"); battleMap = new BattleInterface(playerStatus, textBox, monster); battleMap.initMap(30, monster.getHeight()); storedMaps.add(battleMap); @@ -79,7 +80,7 @@ public void execute() { break; case GOBLIN: monster = new Goblin(25, 25, 25, xPos, yPos, 25, 25); - textBox.setNextDialogue("*the " + monster.getName() + " stares at you menacingly*"); + textBox.setNextDialogue("*the " + monster.getName() + " laughs maniacally*"); battleMap = new BattleInterface(playerStatus, textBox, monster); battleMap.initMap(30, monster.getHeight()); storedMaps.add(battleMap); @@ -88,7 +89,7 @@ public void execute() { break; case GRYPHON: monster = new Gryphon(30, 30, 30, xPos, yPos, 30, 30); - textBox.setNextDialogue("*the " + monster.getName() + " stares at you menacingly*"); + textBox.setNextDialogue("*the " + monster.getName() + " screams at you loudly*"); battleMap = new BattleInterface(playerStatus, textBox, monster); battleMap.initMap(30, monster.getHeight()); storedMaps.add(battleMap); @@ -98,17 +99,21 @@ public void execute() { case SHOP: //some shopkeeper ShopMap shopMap; ShopKeeper shopkeeper = new ShopKeeper("src/main/resources/ShopKeeper/ShopKeeper", - "Hi welcome to my shop!"); - shopMap = new ShopMap(playerStatus, textBox, shopkeeper); + "*meow* Hi welcome to my shop! *meow*"); + shopMap = new ShopMap(playerStatus, textBox, shopkeeper, PLAYER_INVENTORY); shopMap.initMap(30, 0); // Set appropriate width and height - //shopMap.printShopItems(); + shopkeeper.addConsumable(20, 0, "The caffeine is so strong, it heals wounds", + "Cup of Coffee", 10); + shopkeeper.addConsumable(0, 100, "Gun with a single round. Why does a cat have a " + + "gun anyway?", "Desert Eagle", 50); + storedMaps.add(shopMap); mapIndex.put(SHOP, storedMaps.size() - 1); BaseMap.currentMap = mapIndex.get(SHOP); - //((ShopMap) battleMap).interact(textBox); // Interact with the shop - textBox.setNextNarration(shopkeeper.getDefaultMessgage()); + textBox.setNextNarration("You are greeted by a cat with oddly small eyes.\n"); + textBox.setNextInstruction("To enter the shop enter [fight]. To leave now, enter [run]."); break; default: diff --git a/src/main/java/interactable/ShopKeeper.java b/src/main/java/interactable/ShopKeeper.java index 9a4caf1345..aa8de92ffa 100644 --- a/src/main/java/interactable/ShopKeeper.java +++ b/src/main/java/interactable/ShopKeeper.java @@ -7,15 +7,15 @@ public class ShopKeeper extends InteractableEntity{ protected ArrayList shopItems; - protected String defaultMessgage; //whatever the guy says to introduce his items + protected String defaultMessage; //whatever the guy says to introduce his items protected String filePath; public ShopKeeper(String filePathway, String message){ //addConsumable(); this.filePath = filePathway; - this.defaultMessgage = message; - + this.defaultMessage = message; + this.shopItems = new ArrayList<>(); } public ArrayList getShopItems() { @@ -27,24 +27,28 @@ public void addConsumable(int heal, int damage, String itemDescription, String i shopItems.add(newConsumable); } - public String getDefaultMessgage() { - return defaultMessgage; + public String getDefaultMessage() { + return defaultMessage; } public String formatShop() { - StringBuilder formattedList = new StringBuilder(); - for (int i = 0; i < shopItems.size(); i += 1) { - ShopItem item = shopItems.get(i); - formattedList.append(i + 1).append(". ") - .append(item.getName()) - .append(" - ") - .append(item.getDescription()) - .append("\n"); + if (shopItems != null) { + StringBuilder formattedList = new StringBuilder(); + for (int i = 0; i < shopItems.size(); i += 1) { + ShopItem item = shopItems.get(i); + formattedList.append(i + 1).append(". ") + .append(item.getName()) + .append(" - ") + .append(item.getDescription()) + .append("\n"); + } + return formattedList.toString(); } - return formattedList.toString(); + return "The shop is empty"; } + @Override public int getHealth() { return 0; diff --git a/src/main/java/map/ShopMap.java b/src/main/java/map/ShopMap.java index 46b3936c0e..270b8ddb12 100644 --- a/src/main/java/map/ShopMap.java +++ b/src/main/java/map/ShopMap.java @@ -2,21 +2,26 @@ import interactable.ShopKeeper; import filereader.FileReader; +import inventoryitems.ShopItem; import textbox.PlayerStatus; import textbox.TextBox; +import ui.Ui; import java.util.ArrayList; +import java.util.Scanner; public class ShopMap extends BaseMap{ protected PlayerStatus currentPlayer; protected TextBox currentTextBox; protected ShopKeeper currentEntity; + protected PlayerInventory inventory; - public ShopMap(PlayerStatus player, TextBox text, ShopKeeper shopKeeper){ + public ShopMap(PlayerStatus player, TextBox text, ShopKeeper shopKeeper, PlayerInventory bag){ this.currentPlayer = player; this.currentTextBox = text; this.currentEntity = shopKeeper; + this.inventory = bag; //this.currentMap = new ArrayList<>(height); //loadShopMap(); } @@ -37,17 +42,62 @@ public void initMap(int givenWidth, int givenHeight) { public void queueTextBox(){ - currentTextBox.setNextNarration("Welcome to " + currentEntity.getName() + "'s shop"); - currentTextBox.setNextDialogue(currentEntity.getDefaultMessgage() + "\n" + currentEntity.formatShop()); - currentTextBox.setNextInstruction("Enter the index of the item you wish to purchase"); + currentTextBox.setNextNarration("You are greeted by a cat with oddly small eyes.\n"); + currentTextBox.setNextDialogue(currentEntity.getDefaultMessage() + "\n" + currentEntity.formatShop()); + currentTextBox.setNextInstruction("Give the shop keeper an [INDEX] to view the item and purchase" + + " or enter [exit]" + + " to leave the shop."); } - @Override - public void enableFight() { + public void enableFight(){ + + } + + + @Override + public void enableFight(Scanner in) { + String answerCommand = ""; + Ui ui = new Ui(); + queueTextBox(); + while (!answerCommand.equalsIgnoreCase("exit")) { + + ui.printPlayerStatus(currentPlayer); + ui.printTextBox(currentTextBox); + + answerCommand = in.nextLine().trim(); + + // Check if the input is numeric + if (answerCommand.matches("\\d+")) { + int index = Integer.parseInt(answerCommand) - 1; + ArrayList shopItems = currentEntity.getShopItems(); + + if (index >= 0 && index < shopItems.size()) { + ShopItem item = shopItems.get(index); + if (currentPlayer.getPlayerMoney() >= item.getPrice()) { + int currentMoney = currentPlayer.getPlayerMoney(); + currentPlayer.setPlayerMoney(currentMoney - item.getPrice()); + currentTextBox.setNextNarration("NEW ITEM ADDED TO INVENTORY"); + inventory.addItems(item); + } else { + currentTextBox.setNextNarration("You are greeted by a cat with oddly small eyes.\n"); + } + } else { + currentTextBox.setNextError("Invalid index. Please enter a valid item index or 'exit'."); + } + } else if (!answerCommand.equalsIgnoreCase("exit")) { + currentTextBox.setNextError("Invalid command. Please enter a valid item index or 'exit'."); + } + + currentTextBox.setNextDialogue(currentEntity.getDefaultMessage() + "\n" + currentEntity.formatShop()); + currentTextBox.setNextInstruction("Give the shopkeeper an [INDEX] to view the item and purchase or " + + "enter [exit]" + + " to leave the shop."); + } } + @Override public boolean getEntityDeath() { return false;