Skip to content

Commit

Permalink
Updated TransactionUI and created a test method for it in RPGame
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Feb 24, 2015
1 parent 4b2d037 commit a4c54d7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
42 changes: 29 additions & 13 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stringname> <price> and store them in the inventory list member variables
*
Expand All @@ -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"))
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -101,8 +101,8 @@ else if (merchantNumber == 3)
return null;
}
}


/**
* This method returns the player's inventory list
*
Expand All @@ -111,7 +111,7 @@ else if (merchantNumber == 3)
public ArrayList<String> getPlayerInventoryList() {
return playerInventoryList;
}

/**
* This method will create a new instance of Transaction
* incomplete method
Expand All @@ -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
*
Expand All @@ -139,7 +139,7 @@ else if(command.equals("OFF"))
else
System.out.println("Invalid movement toggle command");
}

/**
* Returns the player
* @return Returns the player
Expand All @@ -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
Expand All @@ -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<String> 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));
}
}
1 change: 1 addition & 0 deletions MerchantRPGCSE2102/src/controller/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public Transaction(Player player, Merchant targetMerchant)
_player = player;
_targetMerchant = targetMerchant;
_window = new TransactionUI(this);
_window.setVisible(true);
}

/**
Expand Down
1 change: 1 addition & 0 deletions MerchantRPGCSE2102/src/tests/TestTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void setup()

public void testActionSell()
{
setup();
_rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1));
}
}
12 changes: 9 additions & 3 deletions MerchantRPGCSE2102/src/view/TransactionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a4c54d7

Please sign in to comment.