Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully implement shop #93

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/command/mapmove/InteractingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void execute() {
mapIndex.put(SHOP, storedMaps.size() - 1);
BaseMap.currentMap = mapIndex.get(SHOP);

textBox.setNextNarration("You are greeted by a cat with oddly small eyes.\n");
textBox.setNextNarration("You are greeted by a cat with oddly small eyes.");
textBox.setNextInstruction("To enter the shop enter [fight]. To leave now, enter [run].");
break;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/interactable/ShopKeeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public String formatShop() {
.append(item.getName())
.append(" - ")
.append(item.getDescription())
.append(" - ")
.append(" $")
.append(item.getSellPrice())
.append("\n");
}
return formattedList.toString();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/inventoryitems/Consumable.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public Consumable(int heal, int damage, String itemDescription, String itemName,
damageAmpAmt = damage;
super.name = itemName;
super.price = cost;
super.sellPrice = cost;
}

public void use() {}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/map/ShopMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ public void enableFight(Scanner in) {
while (!answerCommand.equalsIgnoreCase("exit")) {

ui.printPlayerStatus(currentPlayer);
ui.printShopKeeper(currentEntity);
ui.printTextBox(currentTextBox);

answerCommand = in.nextLine().trim();

answerCommand = (answerCommand.length() > 10) ? answerCommand.substring(0, 10) : answerCommand;
// Check if the input is numeric
if (answerCommand.matches("\\d+")) {
int index = Integer.parseInt(answerCommand) - 1;
Expand All @@ -81,7 +82,7 @@ public void enableFight(Scanner in) {
currentTextBox.setNextNarration("NEW ITEM ADDED TO INVENTORY");
inventory.addItems(item);
} else {
currentTextBox.setNextNarration("You are greeted by a cat with oddly small eyes.\n");
currentTextBox.setNextNarration("The cat silently judged your broke ass.\n");
}
} else {
currentTextBox.setNextError("Invalid index. Please enter a valid item index or 'exit'.");
Expand All @@ -95,6 +96,7 @@ public void enableFight(Scanner in) {
"enter [exit]" +
" to leave the shop.");
}
currentTextBox.clearAll();
}


Expand Down
18 changes: 18 additions & 0 deletions src/main/java/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package ui;

import interactable.Enemy;
import interactable.ShopKeeper;
import inventoryitems.Item;
import map.BaseMap;
import textbox.PlayerStatus;
import textbox.TextBox;
import math.MathQuestion;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class Ui {
private static final int DEFAULT_WIDTH_OF_BATTLE_INTERFACE = 50;
Expand Down Expand Up @@ -116,6 +122,18 @@ public void printEnemy(BaseMap map) {
printDividingLine();
}

public void printShopKeeper(ShopKeeper cat){
String filePath = cat.getFilePath();
try {
List<String> lines = Files.readAllLines(Paths.get(filePath));
for (String line : lines) {
System.out.println(line);
}
} catch (IOException e) {
System.out.println("Error reading the file at " + filePath);
}
}

public void printInventoryLine(String text, int quantity, int width) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("|");
Expand Down
Loading