From 891fbd1901e92075e021112a8243ab484dd3f14c Mon Sep 17 00:00:00 2001 From: MrWilliamC Date: Sat, 28 Feb 2015 14:31:38 -0500 Subject: [PATCH 1/7] added TransactionLimits and modified advanceDailyCycle method, transactions are now counted in createTransaction method updated test class for RPGame --- MerchantRPGCSE2102/src/controller/RPGame.java | 50 ++++++++++++++++++- .../src/tests/TestTransaction.java | 7 +++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index 692abff..5f8e603 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -18,11 +18,52 @@ public class RPGame { private Merchant _merchant2; private Merchant _merchant3; private boolean _movement; - + private int _currentDay; + private int _transactionLimit; + + public RPGame() { - //constructor + _currentDay = 1; + _transactionLimit = 3; } + /** + * Will refresh number of transactions the Player has available + * + */ + private void refreshTransactionLimit(){ + _transactionLimit = 3; + } + + /** + * This method will advance the game to the next day, therefore refreshing Merchant cash, + * incrementing the Merchant's max cash every 3 days, refreshing the player's _transactionLimit, + * Will call setDailyRandomPercentage, scaleAllAdjustedPrices, refreshCash, incrementBaseCash + * + */ + private void advanceDailyCycle(){ + _merchant1.setDailyRandomPercentage(50,200); + _merchant2.setDailyRandomPercentage(80,500); + _merchant3.setDailyRandomPercentage(10,1000); + _merchant1.scaleAllAdjustedPrices(); + _merchant2.scaleAllAdjustedPrices(); + _merchant3.scaleAllAdjustedPrices(); + if( (_currentDay % 3) == 0){ + _merchant1.addCash(100); + _merchant1.refreshCash(); + _merchant2.addCash(100); + _merchant2.refreshCash(); + _merchant3.addCash(100); + _merchant3.refreshCash(); + }else{ + _merchant1.refreshCash(); + _merchant2.refreshCash(); + _merchant3.refreshCash(); + } + refreshTransactionLimit(); + _currentDay++; + } + /** * 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 * @@ -119,9 +160,14 @@ public ArrayList getPlayerInventoryList() { */ public void createTransaction(Player player, Merchant targetMerchant) { + if(_transactionLimit > 0){ toggleMovement("OFF"); Transaction newTransaction = new Transaction(player, targetMerchant); toggleMovement("ON"); + _transactionLimit -= 1; + }else{ + System.out.println("The shops are closed."); + } } /** diff --git a/MerchantRPGCSE2102/src/tests/TestTransaction.java b/MerchantRPGCSE2102/src/tests/TestTransaction.java index c529250..876e1be 100644 --- a/MerchantRPGCSE2102/src/tests/TestTransaction.java +++ b/MerchantRPGCSE2102/src/tests/TestTransaction.java @@ -23,6 +23,13 @@ public void setup() public void testActionSell() { setup(); + System.out.println("Transaction 1:"); + _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); + System.out.println("Transaction 2:"); + _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); + System.out.println("Transaction 3:"); + _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); + System.out.println("Transaction 4:"); _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); } } From 37a7b6f99834da2b17cd25c707957ed13bbdd25e Mon Sep 17 00:00:00 2001 From: MrWilliamC Date: Sat, 28 Feb 2015 14:39:14 -0500 Subject: [PATCH 2/7] MainMenuUI --- MerchantRPGCSE2102/src/view/MainMenuUI.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 MerchantRPGCSE2102/src/view/MainMenuUI.java diff --git a/MerchantRPGCSE2102/src/view/MainMenuUI.java b/MerchantRPGCSE2102/src/view/MainMenuUI.java new file mode 100644 index 0000000..0af06b8 --- /dev/null +++ b/MerchantRPGCSE2102/src/view/MainMenuUI.java @@ -0,0 +1,5 @@ +package view; + +public class MainMenuUI { + +} From 91b1d9c711d3a5e0678dbda285bd4ff8baa7a85f Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sat, 28 Feb 2015 15:11:06 -0500 Subject: [PATCH 3/7] Created new exception --- .../src/controller/Transaction.java | 4 ++- .../MerchantNotEnoughCashException.java | 11 +++++++ MerchantRPGCSE2102/src/model/Player.java | 6 ++-- MerchantRPGCSE2102/src/tests/TestPlayer.java | 3 +- .../src/view/TransactionUI.java | 32 +++++++++++-------- 5 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 MerchantRPGCSE2102/src/exceptions/MerchantNotEnoughCashException.java diff --git a/MerchantRPGCSE2102/src/controller/Transaction.java b/MerchantRPGCSE2102/src/controller/Transaction.java index def3e51..4e1d13f 100644 --- a/MerchantRPGCSE2102/src/controller/Transaction.java +++ b/MerchantRPGCSE2102/src/controller/Transaction.java @@ -1,5 +1,6 @@ package controller; +import exceptions.MerchantNotEnoughCashException; import exceptions.NotInInventoryException; import view.TransactionUI; import model.Item; @@ -50,8 +51,9 @@ public boolean actionBuy(String itemName, int amount) * @param amount amount that the player wants to buy * @return returns true if transaction successful, false otherwise * @throws NotInInventoryException + * @throws MerchantNotEnoughCashException */ - public boolean actionSell(String itemName, int amount) throws NotInInventoryException + public boolean actionSell(String itemName, int amount) throws NotInInventoryException, MerchantNotEnoughCashException { if(_player.sell(itemName, _targetMerchant, amount)) return true; diff --git a/MerchantRPGCSE2102/src/exceptions/MerchantNotEnoughCashException.java b/MerchantRPGCSE2102/src/exceptions/MerchantNotEnoughCashException.java new file mode 100644 index 0000000..a839581 --- /dev/null +++ b/MerchantRPGCSE2102/src/exceptions/MerchantNotEnoughCashException.java @@ -0,0 +1,11 @@ +package exceptions; + +@SuppressWarnings("serial") +public class MerchantNotEnoughCashException extends Exception{ + + public MerchantNotEnoughCashException() + { + super(); + } + +} diff --git a/MerchantRPGCSE2102/src/model/Player.java b/MerchantRPGCSE2102/src/model/Player.java index 39c45d1..3ce3a68 100644 --- a/MerchantRPGCSE2102/src/model/Player.java +++ b/MerchantRPGCSE2102/src/model/Player.java @@ -2,6 +2,7 @@ import java.util.ArrayList; +import exceptions.MerchantNotEnoughCashException; import exceptions.NotInInventoryException; public class Player extends Character @@ -71,8 +72,9 @@ public boolean buy(String itemName, Merchant targetMerchant, int amount) * @param amount the amount of the item that the player is selling * @return returns true if transaction successful, false otherwise * @throws NotInInventoryException + * @throws MerchantNotEnoughCashException */ - public boolean sell(String itemName, Merchant targetMerchant, int amount) throws NotInInventoryException + public boolean sell(String itemName, Merchant targetMerchant, int amount) throws NotInInventoryException, MerchantNotEnoughCashException { int totalPrice = targetMerchant.getItemPrice(itemName)* amount; //calculates the total price of the items @@ -92,7 +94,7 @@ public boolean sell(String itemName, Merchant targetMerchant, int amount) throws return true; } else - return false; + throw new MerchantNotEnoughCashException(); } else return false; diff --git a/MerchantRPGCSE2102/src/tests/TestPlayer.java b/MerchantRPGCSE2102/src/tests/TestPlayer.java index f1e424a..1052553 100644 --- a/MerchantRPGCSE2102/src/tests/TestPlayer.java +++ b/MerchantRPGCSE2102/src/tests/TestPlayer.java @@ -1,6 +1,7 @@ package tests; import controller.RPGame; +import exceptions.MerchantNotEnoughCashException; import exceptions.NotInInventoryException; import model.Item; import model.Merchant; @@ -47,7 +48,7 @@ public void testBuy() assertEquals(10, p.getItem("water").getQuantity()); } - public void testSell() throws NotInInventoryException + public void testSell() throws NotInInventoryException, MerchantNotEnoughCashException { setup(); testBuy(); diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index 8d1be0e..180cf05 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -15,6 +15,7 @@ import javax.swing.JTextField; import controller.Transaction; +import exceptions.MerchantNotEnoughCashException; import exceptions.NotInInventoryException; import java.awt.event.MouseAdapter; @@ -233,7 +234,7 @@ public static void createSellWindow() itemList[i] = MASTER.getPlayer().getInventory()[i].getItemName(); itemList[i] = itemList[i] + " (x" + MASTER.getPlayer().getInventory()[i].getQuantity() + ")"; } - + JLabel lblYouHave = new JLabel(MASTER.getTargetMerchant().getName() + " has: $" + MASTER.getTargetMerchant().getCurrentCash()); lblYouHave.setBounds(61, 27, 299, 14); contentPane.add(lblYouHave); @@ -275,20 +276,25 @@ public void mouseClicked(MouseEvent e) { //information is consumed w boolean isGood = false; try{ - try{ //will attempt to parse the number player entered, will stay on the same screen if it cannot - int chosenAmount = Integer.parseInt(textField.getText()); - isGood = MASTER.actionSell(chosenItem, chosenAmount); //checks if the merchant will buy that item - if(isGood) //will attempt to sell the specified amount of the chosen item - { - System.out.println(chosenAmount); - _inTransaction = false; - frame.dispose(); + try{ + try{ //will attempt to parse the number player entered, will stay on the same screen if it cannot + int chosenAmount = Integer.parseInt(textField.getText()); + isGood = MASTER.actionSell(chosenItem, chosenAmount); //checks if the merchant will buy that item + if(isGood) //will attempt to sell the specified amount of the chosen item + { + System.out.println(chosenAmount); + _inTransaction = false; + frame.dispose(); + } + else + throw new NumberFormatException(); //will throw a NumberFormatException if actionSell returns a false + } + catch(NumberFormatException exception){ + System.out.println("Must input a number less than or equal to the total amount of the item that you have"); } - else - throw new NumberFormatException(); //will throw a NumberFormatException if actionSell returns a false } - catch(NumberFormatException exception){ - System.out.println("Must input a number less than or equal to the total amount of the item that you have"); + catch(MerchantNotEnoughCashException mnecexception){ + System.out.println("Merchant does not have enough cash"); } } catch(NotInInventoryException niiexception){ From e53a0fb5e63ea077c100f4796341ef70d2ea7c70 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 1 Mar 2015 13:12:05 -0500 Subject: [PATCH 4/7] Updated TransactionUI to address the known bugs --- MerchantRPGCSE2102/src/model/Player.java | 4 ++-- MerchantRPGCSE2102/src/view/TransactionUI.java | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/MerchantRPGCSE2102/src/model/Player.java b/MerchantRPGCSE2102/src/model/Player.java index 3ce3a68..dc6a9a6 100644 --- a/MerchantRPGCSE2102/src/model/Player.java +++ b/MerchantRPGCSE2102/src/model/Player.java @@ -94,10 +94,10 @@ public boolean sell(String itemName, Merchant targetMerchant, int amount) throws return true; } else - throw new MerchantNotEnoughCashException(); + return false; } else - return false; + throw new MerchantNotEnoughCashException(); } /** diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index 180cf05..bd72d3e 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -228,11 +228,12 @@ public static void createSellWindow() frame.setContentPane(contentPane); contentPane.setLayout(null); - String[] itemList = new String[MASTER.getPlayer().getInventory().length]; //create a new array of strings with the length of the player's inventory //item that the player chooses from the combobox + String[] itemList = new String[MASTER.getTargetMerchant().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(); - itemList[i] = itemList[i] + " (x" + MASTER.getPlayer().getInventory()[i].getQuantity() + ")"; + itemList[i] = MASTER.getTargetMerchant().getInventory()[i].getItemName(); + itemList[i] = itemList[i] + " (x" + MASTER.getPlayer().getInventory()[i].getQuantity() + ")"; //appends the quantity of items that the player has + itemList[i] = itemList[i] + " ($" + MASTER.getTargetMerchant().getInventory()[i].getAdjustedPrice() + ")"; //appends the price of the item } JLabel lblYouHave = new JLabel(MASTER.getTargetMerchant().getName() + " has: $" + MASTER.getTargetMerchant().getCurrentCash()); @@ -289,12 +290,12 @@ public void mouseClicked(MouseEvent e) { //information is consumed w else throw new NumberFormatException(); //will throw a NumberFormatException if actionSell returns a false } - catch(NumberFormatException exception){ - System.out.println("Must input a number less than or equal to the total amount of the item that you have"); + catch(MerchantNotEnoughCashException mnecexception){ + System.out.println("Merchant does not have enough cash"); } } - catch(MerchantNotEnoughCashException mnecexception){ - System.out.println("Merchant does not have enough cash"); + catch(NumberFormatException exception){ + System.out.println("Must input a number less than or equal to the total amount of the item that you have"); } } catch(NotInInventoryException niiexception){ From b2d7c5b14be5ea0e71125b5c8bb5d17f58640be5 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 1 Mar 2015 13:31:14 -0500 Subject: [PATCH 5/7] Split the advanceDailyCycle method into multiple other methods for organization purposes --- MerchantRPGCSE2102/src/controller/RPGame.java | 114 +++++++++++------- MerchantRPGCSE2102/src/tests/TestRPGame.java | 15 ++- 2 files changed, 85 insertions(+), 44 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index 5f8e603..a60174f 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -20,50 +20,13 @@ public class RPGame { private boolean _movement; private int _currentDay; private int _transactionLimit; - - + + public RPGame() { _currentDay = 1; _transactionLimit = 3; } - /** - * Will refresh number of transactions the Player has available - * - */ - private void refreshTransactionLimit(){ - _transactionLimit = 3; - } - - /** - * This method will advance the game to the next day, therefore refreshing Merchant cash, - * incrementing the Merchant's max cash every 3 days, refreshing the player's _transactionLimit, - * Will call setDailyRandomPercentage, scaleAllAdjustedPrices, refreshCash, incrementBaseCash - * - */ - private void advanceDailyCycle(){ - _merchant1.setDailyRandomPercentage(50,200); - _merchant2.setDailyRandomPercentage(80,500); - _merchant3.setDailyRandomPercentage(10,1000); - _merchant1.scaleAllAdjustedPrices(); - _merchant2.scaleAllAdjustedPrices(); - _merchant3.scaleAllAdjustedPrices(); - if( (_currentDay % 3) == 0){ - _merchant1.addCash(100); - _merchant1.refreshCash(); - _merchant2.addCash(100); - _merchant2.refreshCash(); - _merchant3.addCash(100); - _merchant3.refreshCash(); - }else{ - _merchant1.refreshCash(); - _merchant2.refreshCash(); - _merchant3.refreshCash(); - } - refreshTransactionLimit(); - _currentDay++; - } - /** * 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 * @@ -161,15 +124,80 @@ public ArrayList getPlayerInventoryList() { public void createTransaction(Player player, Merchant targetMerchant) { if(_transactionLimit > 0){ - toggleMovement("OFF"); - Transaction newTransaction = new Transaction(player, targetMerchant); - toggleMovement("ON"); - _transactionLimit -= 1; + toggleMovement("OFF"); + Transaction newTransaction = new Transaction(player, targetMerchant); + toggleMovement("ON"); + _transactionLimit -= 1; }else{ System.out.println("The shops are closed."); } } + /** + * Will refresh number of transactions the Player has available + * + */ + private void refreshTransactionLimit(){ + _transactionLimit = 3; + } + + /** + * This method will advance the game to the next day, therefore refreshing Merchant cash, + * incrementing the Merchant's max cash every 3 days, refreshing the player's _transactionLimit, + * Will call setDailyRandomPercentage, scaleAllAdjustedPrices, refreshCash, incrementBaseCash + * + */ + private void advanceDailyCycle(){ + Merchant[] allMerchants = {_merchant1, _merchant2, _merchant3}; + + _merchant1.setDailyRandomPercentage(50,200); //these methods have to be separated since they all take different percentages + _merchant2.setDailyRandomPercentage(80,500); + _merchant3.setDailyRandomPercentage(10,1000); + + scaleAllMerchantPrices(allMerchants); //will scale all the prices of the items that the merchants hold based on their dailyRandomPercent + + if( (_currentDay % 3) == 0) //will increase the merchant's base cash every 3 days + { + addAndRefreshCash(_merchant1, 100); + addAndRefreshCash(_merchant2, 100); + addAndRefreshCash(_merchant3, 100); + } + else //if not on a third day, will just refresh the merchant's cash amount + { + for(Merchant m : allMerchants) + { + m.refreshCash(); + } + } + refreshTransactionLimit(); + _currentDay++; + } + + /** + * Will call scaleAllAdjustedPrices method on all the merchants in the array provided + * + * @param merchants The array of merchants that the method will loop through + */ + private void scaleAllMerchantPrices(Merchant[] merchants) + { + for(Merchant m : merchants) + { + m.scaleAllAdjustedPrices(); + } + } + + /** + * Will call addCash on the merchant provided then refreshes their cash + * + * @param targetMerchant The merchant whose base cash you want to increase + * @param increaseAmount The amount that the base cash increases by + */ + public void addAndRefreshCash (Merchant targetMerchant, int increaseAmount) + { + targetMerchant.addCash(increaseAmount); + targetMerchant.refreshCash(); + } + /** * Toggles the movement on or off based on the input * @param command either "ON" or "OFF" diff --git a/MerchantRPGCSE2102/src/tests/TestRPGame.java b/MerchantRPGCSE2102/src/tests/TestRPGame.java index 7c56296..78324a6 100644 --- a/MerchantRPGCSE2102/src/tests/TestRPGame.java +++ b/MerchantRPGCSE2102/src/tests/TestRPGame.java @@ -1,5 +1,7 @@ package tests; +import java.util.ArrayList; + import controller.RPGame; import junit.framework.TestCase; @@ -10,13 +12,18 @@ public class TestRPGame extends TestCase public void setup() { game = new RPGame(); + game.inventoryFromFile(); + game.buildMerchants(); + ArrayList playerInventory = game.getMerchantInventoryList(1); + playerInventory.addAll(game.getMerchantInventoryList(2)); + playerInventory.addAll(game.getMerchantInventoryList(3)); + game.buildPlayer("Test", 1000, playerInventory); } public void testFile() { // tests that the RPGame is able to read from the text file correctly setup(); - game.inventoryFromFile(); assertEquals("water 3", game.getMerchantInventoryList(1).get(0)); assertEquals("armor 5", game.getMerchantInventoryList(1).get(1)); assertEquals("food 10", game.getMerchantInventoryList(1).get(2)); @@ -26,4 +33,10 @@ public void testFile() assertEquals("tape 13", game.getMerchantInventoryList(3).get(1)); assertEquals("rope 5", game.getMerchantInventoryList(3).get(2)); } + + public void testDailyCycle() + { + setup(); + + } } From f88638172f82de0270a6a2978af4b64f54644949 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 1 Mar 2015 13:38:02 -0500 Subject: [PATCH 6/7] Added a getter for the currentDay and updated the RPGame constructor --- MerchantRPGCSE2102/src/controller/RPGame.java | 15 +++++++++++---- MerchantRPGCSE2102/src/tests/TestRPGame.java | 3 +-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index a60174f..ae9c1e1 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -14,9 +14,7 @@ public class RPGame { private ArrayList merchantInventoryList3 = new ArrayList(); // merchant 3's inventory list private ArrayList playerInventoryList = new ArrayList(); // the player's inventory list private Player _player; - private Merchant _merchant1; - private Merchant _merchant2; - private Merchant _merchant3; + private Merchant _merchant1, _merchant2, _merchant3; private boolean _movement; private int _currentDay; private int _transactionLimit; @@ -25,6 +23,7 @@ public class RPGame { public RPGame() { _currentDay = 1; _transactionLimit = 3; + inventoryFromFile(); } /** @@ -235,6 +234,15 @@ else if(merchantNum == 2) else return _merchant3; } + + /** + * Getter for the current day number + * @return The day number + */ + public int getDay() + { + return _currentDay; + } /** * Main method used to test the GUI components since test classes do not maintain the GUI @@ -243,7 +251,6 @@ else if(merchantNum == 2) public static void main(String[] args) { RPGame _rpg = new RPGame(); - _rpg.inventoryFromFile(); _rpg.buildMerchants(); ArrayList playerInventory = _rpg.getMerchantInventoryList(1); playerInventory.addAll(_rpg.getMerchantInventoryList(2)); diff --git a/MerchantRPGCSE2102/src/tests/TestRPGame.java b/MerchantRPGCSE2102/src/tests/TestRPGame.java index 78324a6..12504ef 100644 --- a/MerchantRPGCSE2102/src/tests/TestRPGame.java +++ b/MerchantRPGCSE2102/src/tests/TestRPGame.java @@ -12,7 +12,6 @@ public class TestRPGame extends TestCase public void setup() { game = new RPGame(); - game.inventoryFromFile(); game.buildMerchants(); ArrayList playerInventory = game.getMerchantInventoryList(1); playerInventory.addAll(game.getMerchantInventoryList(2)); @@ -37,6 +36,6 @@ public void testFile() public void testDailyCycle() { setup(); - + assertEquals(1, game.getDay()); } } From ef93f2362bfe3c4c8e28c54a9d74a718e53f33fd Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 1 Mar 2015 13:59:27 -0500 Subject: [PATCH 7/7] Updated TestRPGame class --- MerchantRPGCSE2102/src/controller/RPGame.java | 9 ++++++--- MerchantRPGCSE2102/src/tests/TestRPGame.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index ae9c1e1..a643482 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -122,12 +122,15 @@ public ArrayList getPlayerInventoryList() { */ public void createTransaction(Player player, Merchant targetMerchant) { - if(_transactionLimit > 0){ + if(_transactionLimit > 0) + { toggleMovement("OFF"); Transaction newTransaction = new Transaction(player, targetMerchant); toggleMovement("ON"); _transactionLimit -= 1; - }else{ + } + else + { System.out.println("The shops are closed."); } } @@ -146,7 +149,7 @@ private void refreshTransactionLimit(){ * Will call setDailyRandomPercentage, scaleAllAdjustedPrices, refreshCash, incrementBaseCash * */ - private void advanceDailyCycle(){ + public void advanceDailyCycle(){ Merchant[] allMerchants = {_merchant1, _merchant2, _merchant3}; _merchant1.setDailyRandomPercentage(50,200); //these methods have to be separated since they all take different percentages diff --git a/MerchantRPGCSE2102/src/tests/TestRPGame.java b/MerchantRPGCSE2102/src/tests/TestRPGame.java index 12504ef..272bbbb 100644 --- a/MerchantRPGCSE2102/src/tests/TestRPGame.java +++ b/MerchantRPGCSE2102/src/tests/TestRPGame.java @@ -37,5 +37,21 @@ public void testDailyCycle() { setup(); assertEquals(1, game.getDay()); + game.getMerchant(1).subtractCash(500); + assertEquals(500, game.getMerchant(1).getCurrentCash()); + game.advanceDailyCycle(); + assertEquals(2, game.getDay()); + + boolean test; + if(game.getMerchant(1).getRandomPercent() >= 50 && game.getMerchant(1).getRandomPercent() <= 200) + { + test = true; + } + else + test = false; + + assertEquals(true, test); + assertEquals(1000, game.getMerchant(1).getCurrentCash()); + } }