diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index ff84e02..7fa2db1 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -18,11 +18,11 @@ public class RPGame { private Merchant _merchant2; private Merchant _merchant3; private boolean _movement; - + public RPGame() { //constructor } - + /** * This method scans the inventory.txt file located in src\config. It will read lines of the format and store them in the inventory list member variables * @@ -34,7 +34,7 @@ public void inventoryFromFile() { int currentMerchant = 0; // keeps track of which merchant's inventory the scanner is reading String token = null; String item = null; - + while(fileScanner.hasNextLine()) { // loops as long as there is another line to read token = fileScanner.next(); if (token.equals("merchant")) @@ -52,14 +52,14 @@ else if (currentMerchant == 3) if (fileScanner.hasNextLine()) // only advances to the next line if there is one to read fileScanner.nextLine(); } - + } catch (FileNotFoundException e) { // if inventory.txt is deleted or missing System.out.println("Inventory file not found"); e.printStackTrace(); } - + } - + /** * Generates all three merchants * will add them to the map, but function is not written yet @@ -70,7 +70,7 @@ public void buildMerchants() _merchant2 = new Merchant("Merchant 2", 1000, merchantInventoryList2); _merchant3 = new Merchant("Merchant 3", 1000, merchantInventoryList3); } - + /** * Generates the player * @param name Player name @@ -101,8 +101,8 @@ else if (merchantNumber == 3) return null; } } - - + + /** * This method returns the player's inventory list * @@ -111,7 +111,7 @@ else if (merchantNumber == 3) public ArrayList getPlayerInventoryList() { return playerInventoryList; } - + /** * This method will create a new instance of Transaction * incomplete method @@ -124,7 +124,7 @@ public void createTransaction(Player player, Merchant targetMerchant) toggleMovement("OFF"); Transaction newTransaction = new Transaction(player, targetMerchant); } - + /** * Toggles the movement on or off based on the input * @@ -139,7 +139,7 @@ else if(command.equals("OFF")) else System.out.println("Invalid movement toggle command"); } - + /** * Returns the player * @return Returns the player @@ -148,7 +148,7 @@ public Player getPlayer() { return _player; } - + /** * Returns a merchant based off of the input number * @param merchantNum The number of the merchant you want @@ -163,4 +163,20 @@ else if(merchantNum == 2) else return _merchant3; } + + /** + * Main method used to test the GUI components since test classes do not maintain the GUI + * @param args + */ + public static void main(String[] args) + { + RPGame _rpg = new RPGame(); + _rpg.inventoryFromFile(); + _rpg.buildMerchants(); + ArrayList playerInventory = _rpg.getMerchantInventoryList(1); + playerInventory.addAll(_rpg.getMerchantInventoryList(2)); + playerInventory.addAll(_rpg.getMerchantInventoryList(3)); + _rpg.buildPlayer("test", 500, playerInventory); + _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); + } } diff --git a/MerchantRPGCSE2102/src/controller/Transaction.java b/MerchantRPGCSE2102/src/controller/Transaction.java index 9ece05d..1815a09 100644 --- a/MerchantRPGCSE2102/src/controller/Transaction.java +++ b/MerchantRPGCSE2102/src/controller/Transaction.java @@ -15,6 +15,7 @@ public Transaction(Player player, Merchant targetMerchant) _player = player; _targetMerchant = targetMerchant; _window = new TransactionUI(this); + _window.setVisible(true); } /** diff --git a/MerchantRPGCSE2102/src/tests/TestTransaction.java b/MerchantRPGCSE2102/src/tests/TestTransaction.java index 82dbeca..c529250 100644 --- a/MerchantRPGCSE2102/src/tests/TestTransaction.java +++ b/MerchantRPGCSE2102/src/tests/TestTransaction.java @@ -22,6 +22,7 @@ public void setup() public void testActionSell() { + setup(); _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); } } diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index b37b203..8400ba3 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -110,9 +110,9 @@ public void mouseClicked(MouseEvent e) { /** * Will exit the transaction window */ - public static void exitWindow() + public void exitWindow() { - System.exit(0); + this.dispose(); } /** @@ -156,7 +156,13 @@ public static void createSellWindow() frame.setContentPane(contentPane); contentPane.setLayout(null); - JComboBox comboBox = new JComboBox(MASTER.getPlayer().getInventory()); + String[] itemList = new String[MASTER.getPlayer().getInventory().length]; //create a new array of strings with the length of the player's inventory + for(int i = 0; i < itemList.length; i++) //adds all the item names to the item list + { + itemList[i] = MASTER.getPlayer().getInventory()[i].getItemName(); + } + + JComboBox comboBox = new JComboBox(itemList); comboBox.setBounds(61, 141, 131, 20); contentPane.add(comboBox);