Skip to content

Commit

Permalink
added TransactionLimits and modified advanceDailyCycle method,
Browse files Browse the repository at this point in the history
transactions are now counted in createTransaction method
updated test class for RPGame
  • Loading branch information
wkc12001 committed Feb 28, 2015
1 parent 0d0978d commit 891fbd1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
50 changes: 48 additions & 2 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stringname> <price> and store them in the inventory list member variables
*
Expand Down Expand Up @@ -119,9 +160,14 @@ public ArrayList<String> 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.");
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions MerchantRPGCSE2102/src/tests/TestTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 891fbd1

Please sign in to comment.