diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java new file mode 100644 index 0000000..0e1e3b5 --- /dev/null +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -0,0 +1,84 @@ +package controller; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class RPGame { + private ArrayList merchantInventoryList1 = new ArrayList(); // merchant 1's inventory list + private ArrayList merchantInventoryList2 = new ArrayList(); // merchant 2's inventory list + private ArrayList merchantInventoryList3 = new ArrayList(); // merchant 3's inventory list + private ArrayList playerInventoryList = new ArrayList(); // the player's inventory list + + 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 + * + */ + public void inventoryFromFile() { + Scanner fileScanner = null; + try { + fileScanner = new Scanner(new File("src/config/inventory.txt")); // inventory.txt must be located the config folder + 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")) + currentMerchant = fileScanner.nextInt(); + else { + item = token + " " + fileScanner.nextInt(); // a string containing the item name and price + if (currentMerchant == 1) + merchantInventoryList1.add(item); + else if (currentMerchant == 2) + merchantInventoryList2.add(item); + else + merchantInventoryList3.add(item); + playerInventoryList.add(item); + } + 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(); + } + + } + + /** + * This method returns the specified merchant inventory list + * + * @param merchant number + * @return the specified merchant's inventory list + */ + public ArrayList getMerchantInventoryList(int merchantNumber) { + if (merchantNumber == 1) + return merchantInventoryList1; + else if (merchantNumber == 2) + return merchantInventoryList2; + else if (merchantNumber == 3) + return merchantInventoryList3; + else + { + System.out.println("Invalid merchant number"); + return null; + } + } + + + /** + * This method returns the player's inventory list + * + * @return the player's inventory list + */ + public ArrayList getPlayerInventoryList() { + return playerInventoryList; + } +} diff --git a/MerchantRPGCSE2102/src/game/Item.java b/MerchantRPGCSE2102/src/game/Item.java deleted file mode 100644 index 058bc54..0000000 --- a/MerchantRPGCSE2102/src/game/Item.java +++ /dev/null @@ -1,83 +0,0 @@ -package game; - -public class Item -{ - private String _name; - private int _basePrice; - private int _maxPrice; - private int _minPrice; - private int _adjustedPrice; - - //Item constructor - public Item(String itemName, int basePrice, int maxPrice, int minPrice) - { - _name = itemName; - _basePrice = basePrice; - _maxPrice = maxPrice; - _minPrice = minPrice; - _adjustedPrice = _basePrice; - } - - //second Item constructor - //if max and min prices are not specified, assigns highest possible price and lowest possible price - //to the two variables respectively - public Item(String itemName, int basePrice) - { - _name = itemName; - _basePrice = basePrice; - _maxPrice = 100000; //maximum price - _minPrice = 0; - } - - //will set the adjusted price of the item based off of the daily percent of the merchant - //will need the daily percent as an input from merchant - //if the adjusted price is less than the minPrice, then it will return the minPrice and set it as the adjusted - //if greater than the max price, the adjusted will be the maxPrice and maxPrice is returned - //else it will set the price as the floor and return - public int setAdjPrice(double merchantPercent) - { - //will find the floor of the price to prevent decimals - int calculatedPrice = (int) Math.floor((merchantPercent / 100) * _basePrice); - - //checks if the calculated price is greater or less than the given bounds - if(calculatedPrice > _maxPrice) - _adjustedPrice = _maxPrice; - else if(calculatedPrice < _minPrice) - _adjustedPrice = _minPrice; - //if within bounds, then returns the calculated price - else - _adjustedPrice = calculatedPrice; - - return _adjustedPrice; - } - - //name getter - public String getItemName() - { - return _name; - } - - //base price getter - public int getBasePrice() - { - return _basePrice; - } - - //max price getter - public int getMaxPrice() - { - return _maxPrice; - } - - //min price getter - public int getMinPrice() - { - return _minPrice; - } - - //adjusted price getter - public int getAdjustedPrice() - { - return _adjustedPrice; - } -} diff --git a/MerchantRPGCSE2102/src/game/Merchant.java b/MerchantRPGCSE2102/src/game/Merchant.java deleted file mode 100644 index a4f1904..0000000 --- a/MerchantRPGCSE2102/src/game/Merchant.java +++ /dev/null @@ -1,155 +0,0 @@ -package game; - -import java.util.ArrayList; -import java.util.Random; - -public class Merchant -{ - private String _name; - private int _currentCash; - private int _baseCash; - private int _dailyRandomPercent; - private Item[] _inventory; - - //merchant constructor - public Merchant(String name, int cashLimit, ArrayList inventory) - { - _name = name; - _currentCash = cashLimit; - _baseCash = cashLimit; - generateMerchantInventory(inventory); - _dailyRandomPercent = 0; //placeholder percentage - } - - //will generate an array of items based off an ArrayList of item names - //saves the array to _inventory - private void generateMerchantInventory(ArrayList itemList) - { - _inventory = new Item[itemList.size()]; //inventory size will be the size of the list of items - String[] nameAndPrice; - String name; - String price; - - for(int i=0; i < itemList.size(); i++) - { - nameAndPrice = itemList.get(i).split("\\s+"); //splits the string into the string name and string price - name = nameAndPrice[0]; - price = nameAndPrice[1]; - _inventory[i] = new Item(name, Integer.parseInt(price)); //creates a new instance of item and adds it to the inventory - } - } - - //will restore the current Cash amount back to the base amount - //of cash that the merchant started the day with - public void refreshCash() - { - _currentCash = _baseCash; - } - - //increments the base amount of cash that the merchant - //will start the day with - public void incrementCash(int incrementAmount) - { - _baseCash += incrementAmount; - } - - //removes the specified amount from the merchant's current cash - public int decreaseCash(int decrementAmount) - { - //checks if the amount attempting to be removed is - //greater than the current amount - //if true, returns -1 and outputs error message - //the integer returned should never be negative - if(decrementAmount > _currentCash) - { - System.out.println("Merchant has insufficent cash"); - return -1; - } - //if false then removes the decrement amount - else - { - _currentCash -= decrementAmount; - return _currentCash; - } - } - - //randomizer - //will generate a number between 0 and max - public int randomizer(int max) - { - int randomNumber = 0; - Random randomGenerator = new Random(); - randomNumber = randomGenerator.nextInt(max); - return randomNumber; - } - - //will set the dailyRandomPrice to a number between the two given inputs - public void setDailyRandomPrice(int minPercent, int maxPercent) - { - int randomizerRange = maxPercent - minPercent; - _dailyRandomPercent = randomizer(randomizerRange) + minPercent; - } - - //given the name of the item then it will return - //the adjusted price of the item - public int getItemPrice(String itemName) - { - Item targetItem = getItem(itemName); - int itemPrice = targetItem.getAdjustedPrice(); - return itemPrice; - } - - //given the item name, it will search through the merchant's inventory and return the item - //if it cannot be found, it will return null and output an error message - //big O(n) runtime - public Item getItem(String itemName) - { - for(int i = 0; i < _inventory.length; i++) - { - if(_inventory[i].getItemName().equals(itemName)) - return _inventory[i]; - } - - System.out.println("No such item exists"); - return null; - } - - //will set adjusted prices for all of the items in the inventory - public void setAllAdjustedPrices() - { - for(Item i: _inventory) - { - i.setAdjPrice(_dailyRandomPercent); - } - } - - //name getter - public String getName() - { - return _name; - } - - //current cash getter - public int getCurrentCash() - { - return _currentCash; - } - - //base cash getter - public int getBaseCash() - { - return _baseCash; - } - - //dailyRandomPrice getter - public int getRandomPrice() - { - return _dailyRandomPercent; - } - - //inventory getter - public Item[] getInventory() - { - return _inventory; - } -} diff --git a/MerchantRPGCSE2102/src/game/Player.java b/MerchantRPGCSE2102/src/game/Player.java deleted file mode 100644 index 3c5122d..0000000 --- a/MerchantRPGCSE2102/src/game/Player.java +++ /dev/null @@ -1,81 +0,0 @@ -package game; - -public class Player -{ - private String _name; - private int _playerCash; - //************************************************************************* - //we need to discuss how we will store the amount of goods the player - //has in store in their inventory - //array-inside-array wastes too much space and is too slow - //need to consider another method, currently this is a placeholder member variable - private Item[] _playerInventory; - //************************************************************************* - - //constructor - public Player(String playerName, int startingCash, int startingInventory) - { - _name = playerName; - _playerCash = startingCash; - //placeholder constructor for the player inventory - _playerInventory = new Item[startingInventory]; - } - - //************************************************************************** - //Buy method, allows player to gain new items - //deducts cash based on the price of item - //needs the name of the item and the merchant that the player is buying from - //incomplete method - public void buy(String itemName, Merchant targetMerchant) - { - - } - - //sell method, will remove items from the player's inventory and - //increase the amount of cash the player has - //needs the name of the item being sold and the merchant player is selling to - //incomplete method - public void sell(String itemName, Merchant targetMerchant) - { - - } - //************************************************************************** - - //deduct cash method, will remove the input amount from playerCash - //will return an error message and will not remove any cash if - //amount attempting to be removed is greater than the player cash amount - public void deductCash(int deductAmount) - { - if(deductAmount > _playerCash) - { - System.out.println("ERROR: Player does not have sufficient cash"); - } - else - _playerCash -= deductAmount; - } - - //increase cash method, will increase the amount of cash on the player - //will increase by amount inputed - public void increaseCash(int increaseAmount) - { - _playerCash += increaseAmount; - } - - //name getter - public String getName() - { - return _name; - } - - //playerCash getter - public int getPlayerCash() - { - return _playerCash; - } - - //inventory getter - public Item[] getInventory() - { - return _playerInventory; - } -} diff --git a/MerchantRPGCSE2102/src/game/RPGame.java b/MerchantRPGCSE2102/src/game/RPGame.java deleted file mode 100644 index 4942c07..0000000 --- a/MerchantRPGCSE2102/src/game/RPGame.java +++ /dev/null @@ -1,67 +0,0 @@ -package game; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Scanner; - -public class RPGame { - private ArrayList merchantInventory1 = new ArrayList(); - private ArrayList merchantInventory2 = new ArrayList(); - private ArrayList merchantInventory3 = new ArrayList(); - - public RPGame() { - - } - - // Scans src/config/inventory.txt for each merchant's inventory and stores them as the string " " in the corresponding merchantInventory ArrayList - public void inventoryFromFile() { - Scanner fileScanner = null; - try { - fileScanner = new Scanner(new File("src/config/inventory.txt")); // inventory.txt must be located the config folder - int currentMerchant = 0; // keeps track of which merchant's inventory the scanner is reading - String token = null; - String item = null; - - // Loops through each line of the text file as long as there is another line to read - while(fileScanner.hasNextLine()) { - //must start from the beginning of a line - token = fileScanner.next(); // first word of the line - if (token.equals("merchant")) - currentMerchant = fileScanner.nextInt(); - else { - item = token + " " + fileScanner.nextInt(); // item name and cost appended together in one string - if (currentMerchant == 1) - merchantInventory1.add(item); - else if (currentMerchant == 2) - merchantInventory2.add(item); - else - merchantInventory3.add(item); - } - // advances to next line unless it has reached the end of the file - if (fileScanner.hasNextLine()) - fileScanner.nextLine(); - } - - } catch (FileNotFoundException e) { // if inventory.txt is deleted or missing - System.out.println("Inventory file not found"); - e.printStackTrace(); - } - - } - - // returns the list of inventory items for a specified merchant - public ArrayList getMerchantInventory(int merchantNumber) { - if (merchantNumber == 1) - return merchantInventory1; - else if (merchantNumber == 2) - return merchantInventory2; - else if (merchantNumber == 3) - return merchantInventory3; - else - { - System.out.println("Invalid merchant number"); - return null; - } - } -} diff --git a/MerchantRPGCSE2102/src/model/Item.java b/MerchantRPGCSE2102/src/model/Item.java new file mode 100644 index 0000000..7cb3947 --- /dev/null +++ b/MerchantRPGCSE2102/src/model/Item.java @@ -0,0 +1,111 @@ +package model; + +public class Item +{ + private String _name; // name of the item + private int _basePrice; // the item's starting price + private int _maxPrice; // maximum obtainable price for the item + private int _minPrice; // minimum obtainable price for the item + private int _adjustedPrice; // this is the item's price for the day + private int _quantity; // amount of item (will discuss if there are any alternatives) + + + public Item(String itemName, int basePrice, int maxPrice, int minPrice, int quantity) + { + _name = itemName; + _basePrice = basePrice; + _maxPrice = maxPrice; + _minPrice = minPrice; + _adjustedPrice = _basePrice; + } + + + public Item(String itemName, int basePrice, int quantity) + { + _name = itemName; + _basePrice = basePrice; + // max and min price not specified + _maxPrice = 100000; // default max price + _minPrice = 0; // default min price + _quantity = quantity; + } + + /** + * This method will set the adjusted price of the item based on the Merchant's daily percentage value + * + * @param merchantPercent the percentage to change the price as specified by the Merchant + * @return adjusted price integer + * + */ + public int scaleAdjPrice(double merchantPercent) + { + int calculatedPrice = (int) Math.floor((merchantPercent / 100) * _basePrice); //will find the floor of the price to prevent decimals + + if(calculatedPrice > _maxPrice) // if the adjusted price is outside of bounds, it is set to either the max or min + _adjustedPrice = _maxPrice; + else if(calculatedPrice < _minPrice) + _adjustedPrice = _minPrice; + else + _adjustedPrice = calculatedPrice; + return _adjustedPrice; + } + + /** + * Returns the item's name + * + * @return string name + */ + public String getItemName() + { + return _name; + } + + /** + * Returns the item's base price + * + * @return base price integer + */ + public int getBasePrice() + { + return _basePrice; + } + + /** + * Returns the item's maximum price + * + * @return maximimum price integer + */ + public int getMaxPrice() + { + return _maxPrice; + } + + /** + * Returns the item's minimum price + * + * @return minimum price integer + */ + public int getMinPrice() + { + return _minPrice; + } + + /** + * Returns the item's adjusted price + * + * @return adjusted price integer + */ + public int getAdjustedPrice() + { + return _adjustedPrice; + } + + /** + * Returns the item's quanitity + * + * @return quantity integer + */ + public int getQuantity() { + return _quantity; + } +} diff --git a/MerchantRPGCSE2102/src/model/Merchant.java b/MerchantRPGCSE2102/src/model/Merchant.java new file mode 100644 index 0000000..9bab251 --- /dev/null +++ b/MerchantRPGCSE2102/src/model/Merchant.java @@ -0,0 +1,202 @@ +package model; + +import java.util.ArrayList; +import java.util.Random; + +public class Merchant +{ + private String _name; + private int _currentCash; + private int _baseCash; + private int _dailyRandomPercent; + private Item[] _merchantInventory; + + + public Merchant(String name, int cashLimit, ArrayList inventory) + { + _name = name; + _currentCash = cashLimit; + _baseCash = cashLimit; + generateMerchantInventory(inventory); + _dailyRandomPercent = 0; //placeholder percentage + } + + /** + * Read's the merchant's item list provided by RPGame and store's instances of each item into the Merchant's inventory + * + * @param itemList an ArrayList of strings of items to be supplied to the merchant + */ + private void generateMerchantInventory(ArrayList itemList) + { + _merchantInventory = new Item[itemList.size()]; // inventory size will be the size of the list of items + String[] nameAndPrice; // a two string array of both the item name and price + String name; + String price; + + for(int i=0; i < itemList.size(); i++) + { + nameAndPrice = itemList.get(i).split("\\s+"); // splits the string into the item name and price + name = nameAndPrice[0]; + price = nameAndPrice[1]; + _merchantInventory[i] = new Item(name, Integer.parseInt(price), -1); // stores a new instance of the item in the merchant's inventory (-1 represents infinite quantity) + } + } + + /** + * Resets the merchant's current cash on hand to the base cash amount + * + */ + public void refreshCash() + { + _currentCash = _baseCash; + } + + /** + * Adds the specified amount of cash to the merchant's cash amount for the start of a day + * @param amount the amount of cash to be added + */ + public void addCash(int amount) + { + _baseCash += amount; + } + + /** + * Removes the specified amount of cash to the merchant's cash amount for the start of a day + * @param amount the amount of cash to be subtracted + */ + public int subtractCash(int amount) + { + + if(amount > _currentCash) // if more cash is being subtracted than the merchant has + { + System.out.println("Merchant has insufficent cash"); + return -1; // value of -1 indicates an unsuccessful subtraction + } else { + _currentCash -= amount; + return _currentCash; + } + } + + /** + * This method will return a psuedorandomly generated integer within the range of 0 to the specified maximum value + * + * @param max maximum integer value + * @return random integer + */ + public int randomizer(int max) + { + int randomNumber = 0; + Random randomGenerator = new Random(); + randomNumber = randomGenerator.nextInt(max); + return randomNumber; + } + + /** + * This method will set the merchant's daily random percentage to an integer value between the specified minimum and maximum percentage + * + * @param minPercent minimum percentage value + * @param maxPercent maximum percentage value + */ + public void setDailyRandomPercentage(int minPercent, int maxPercent) + { + int randomizerRange = maxPercent - minPercent; // the range used to determine a random percentage + _dailyRandomPercent = randomizer(randomizerRange) + minPercent; // caluclated a random percentage between min and max + } + + /** + * This method searches through the merchant's inventory for the specified item name and returns the corresponding item's price + * + * @param itemName string containing the name of the item to search for + * @return the price of the item + */ + public int getItemPrice(String itemName) + { + Item targetItem = getItem(itemName); + + if (targetItem == null) { + System.out.println("No such item exists"); // this will avoid a NullPointerException + return -1; // -1 represents an unsuccessful retrieval of the item's price + } + + int itemPrice = targetItem.getAdjustedPrice(); + return itemPrice; + } + + /** + * Searches through the merchant's inventory for the item corresponding to the specified item name + * + * @param itemName string containing the name of the item + * @return the item matching the specified item name + */ + public Item getItem(String itemName) + { + for(int i = 0; i < _merchantInventory.length; i++) + { + if(_merchantInventory[i].getItemName().equals(itemName)) + return _merchantInventory[i]; + } + + System.out.println("No such item exists"); // item was not found by searching the inventory + return null; + } + + /** + * Iterates through the merchant's inventory and scales each item's price by the daily random percentage value + * + */ + public void scaleAllAdjustedPrices() + { + for(Item item: _merchantInventory) + { + item.scaleAdjPrice(_dailyRandomPercent); + } + } + + /** + * Returns a string containing the name of the merchant + * + * @return merchant name string + */ + public String getName() + { + return _name; + } + + /** + * Returns a the base cash amount of the merchant + * + * @return base cash value + */ + public int getCurrentCash() + { + return _currentCash; + } + + /** + * Returns a the current amount of cash the merchant has + * + * @return current cash value + */ + public int getBaseCash() + { + return _baseCash; + } + + /** + * Returns a the daily random percent of the merchant + * @return daily random percent value + */ + public int getRandomPercent() + { + return _dailyRandomPercent; + } + + /** + * Returns the merchant's item inventorys + * @return item inventory array + */ + public Item[] getInventory() + { + return _merchantInventory; + } +} diff --git a/MerchantRPGCSE2102/src/model/Player.java b/MerchantRPGCSE2102/src/model/Player.java new file mode 100644 index 0000000..b31793a --- /dev/null +++ b/MerchantRPGCSE2102/src/model/Player.java @@ -0,0 +1,116 @@ +package model; + +import java.util.ArrayList; + +public class Player +{ + private String _name; // player's name + private int _playerCash; // current amount of cash the player has + private Item[] _playerInventory; // the player's current inventory + + + public Player(String playerName, int startingCash, ArrayList startingInventory) + { + _name = playerName; + _playerCash = startingCash; + generatePlayerInventory(startingInventory); + } + + /** + * Read's the player's item list provided by RPGame and store's instances of each item into the player's inventory + * + * @param itemList an ArrayList of strings of items to be supplied to the player + */ + private void generatePlayerInventory(ArrayList itemList) + { + _playerInventory = new Item[itemList.size()]; // inventory size will be the size of the list of items + String[] nameAndPrice; // a two string array of both the item name and price + String name; + String price; + + for(int i=0; i < itemList.size(); i++) + { + nameAndPrice = itemList.get(i).split("\\s+"); //splits the string into the string name and string price + name = nameAndPrice[0]; + price = nameAndPrice[1]; + _playerInventory[i] = new Item(name, Integer.parseInt(price), 0); // stores a new instance of the item in the player's inventory (quantity begins at 0) + } + } + + /** + * Allows player to buy an item from a target merchant + * + * @param itemName string containing the name of the item to be purchased + * @param targetMerchant the merchant who the player is purchasing from + */ + public void buy(String itemName, Merchant targetMerchant) + { + + } + + /** + * Allows player to sell an item to a target merchant + * + * @param itemName string containing the name of the item to be sold + * @param targetMerchant the merchant who the player is selling to + */ + public void sell(String itemName, Merchant targetMerchant) + { + + } + + /** + * Decreases the player's cash by the specified amount + * + * @param deductAmount amount to decrease cash by + */ + public void deductCash(int deductAmount) + { + if(deductAmount > _playerCash) + { + System.out.println("ERROR: Player does not have sufficient cash"); + } + else + _playerCash -= deductAmount; + } + + /** + * Increase's the player's cash by the specified amount + * + * @param increaseAmount amount to increase cash by + */ + public void increaseCash(int increaseAmount) + { + _playerCash += increaseAmount; + } + + /** + * Returns a string containing the player's name + * + * @return player's name + */ + public String getName() + { + return _name; + } + + /** + * Returns the current amount of cash the player has + * + * @return player's cash amount + */ + public int getPlayerCash() + { + return _playerCash; + } + + /** + * Returns the player's current inventory + * + * @return player's inventory array + */ + public Item[] getInventory() + { + return _playerInventory; + } +} diff --git a/MerchantRPGCSE2102/src/tests/TestItem.java b/MerchantRPGCSE2102/src/tests/TestItem.java index 692358d..31c865b 100644 --- a/MerchantRPGCSE2102/src/tests/TestItem.java +++ b/MerchantRPGCSE2102/src/tests/TestItem.java @@ -1,6 +1,6 @@ package tests; -import game.Item; +import model.Item; import junit.framework.TestCase; public class TestItem extends TestCase @@ -9,19 +9,19 @@ public class TestItem extends TestCase public void setup() { - i = new Item("Test", 100, 150, 50); + i = new Item("Test", 100, 150, 50, 0); } public void testAdjustedPrice() { setup(); - int testPrice = i.setAdjPrice(80); + int testPrice = i.scaleAdjPrice(80); assertEquals(80, testPrice); - testPrice = i.setAdjPrice(120); + testPrice = i.scaleAdjPrice(120); assertEquals(120, testPrice); - testPrice = i.setAdjPrice(200); + testPrice = i.scaleAdjPrice(200); assertEquals(150, testPrice); - testPrice = i.setAdjPrice(0); + testPrice = i.scaleAdjPrice(0); assertEquals(50, testPrice); } } diff --git a/MerchantRPGCSE2102/src/tests/TestMerchant.java b/MerchantRPGCSE2102/src/tests/TestMerchant.java index 08ed6fe..90b6598 100644 --- a/MerchantRPGCSE2102/src/tests/TestMerchant.java +++ b/MerchantRPGCSE2102/src/tests/TestMerchant.java @@ -1,34 +1,31 @@ package tests; -import java.util.ArrayList; -import game.Item; -import game.Merchant; +import controller.RPGame; +import model.Item; +import model.Merchant; import junit.framework.TestCase; - public class TestMerchant extends TestCase { private Merchant m; public void setup() { - ArrayList a = new ArrayList(); - a.add("water 3"); - a.add("armor 5"); - a.add("food 10"); - m = new Merchant("Test", 100, a); + RPGame game = new RPGame(); + game.inventoryFromFile(); + m = new Merchant("Test", 100, game.getMerchantInventoryList(1)); } //testing cash system public void testCashSystem() throws Exception { setup(); - assertEquals(-1, m.decreaseCash(101)); - m.incrementCash(100); + assertEquals(-1, m.subtractCash(101)); + m.addCash(100); m.refreshCash(); assertEquals(200, m.getCurrentCash()); - m.decreaseCash(120); + m.subtractCash(120); assertEquals(80, m.getCurrentCash()); } @@ -37,9 +34,9 @@ public void testRandomizer() throws Exception { setup(); boolean testCheck = false; - m.setDailyRandomPrice(10, 50); + m.setDailyRandomPercentage(10, 50); - if(10 <= m.getRandomPrice() && 50 >= m.getRandomPrice()) + if(10 <= m.getRandomPercent() && 50 >= m.getRandomPercent()) { testCheck = true; } @@ -62,7 +59,7 @@ public void testInventory() throws Exception public void testInventoryPrices() throws Exception { setup(); - m.setAllAdjustedPrices(); + m.scaleAllAdjustedPrices(); assertEquals(0, m.getItemPrice("water")); assertEquals(0, m.getItemPrice("armor")); assertEquals(0, m.getItemPrice("food")); diff --git a/MerchantRPGCSE2102/src/tests/TestPlayer.java b/MerchantRPGCSE2102/src/tests/TestPlayer.java index 00e758c..1f77d92 100644 --- a/MerchantRPGCSE2102/src/tests/TestPlayer.java +++ b/MerchantRPGCSE2102/src/tests/TestPlayer.java @@ -1,7 +1,9 @@ package tests; +import controller.RPGame; +import model.Item; +import model.Player; import junit.framework.TestCase; -import game.Player; public class TestPlayer extends TestCase { @@ -9,7 +11,9 @@ public class TestPlayer extends TestCase public void setup() { - p = new Player("TestPlayer", 1000, 1); + RPGame game = new RPGame(); //starting a new game + game.inventoryFromFile(); //read from file + p = new Player("TestPlayer", 1000, game.getPlayerInventoryList()); } //test cash system for Player class @@ -21,4 +25,12 @@ public void testPlayerCashSystem() p.increaseCash(500); assertEquals(1000,p.getPlayerCash()); } + + public void testPlayerInventory() { + setup(); + Item[] inventory = p.getInventory(); + for (Item item : inventory) { + System.out.println(item.getItemName() + " " + item.getQuantity()); + } + } } diff --git a/MerchantRPGCSE2102/src/tests/TestRPGame.java b/MerchantRPGCSE2102/src/tests/TestRPGame.java index b7cef03..0bc5f45 100644 --- a/MerchantRPGCSE2102/src/tests/TestRPGame.java +++ b/MerchantRPGCSE2102/src/tests/TestRPGame.java @@ -1,7 +1,7 @@ package tests; +import controller.RPGame; import junit.framework.TestCase; -import game.RPGame; public class TestRPGame extends TestCase { @@ -16,13 +16,13 @@ public void testFile() { setup(); game.inventoryFromFile(); - assertEquals("water 3", game.getMerchantInventory(1).get(0)); - assertEquals("armor 5", game.getMerchantInventory(1).get(1)); - assertEquals("food 10", game.getMerchantInventory(1).get(2)); - assertEquals("wood 3", game.getMerchantInventory(2).get(0)); - assertEquals("tarp 6", game.getMerchantInventory(2).get(1)); - assertEquals("glass 3", game.getMerchantInventory(3).get(0)); - assertEquals("tape 13", game.getMerchantInventory(3).get(1)); - assertEquals("rope 5", game.getMerchantInventory(3).get(2)); + assertEquals("water 3", game.getMerchantInventoryList(1).get(0)); + assertEquals("armor 5", game.getMerchantInventoryList(1).get(1)); + assertEquals("food 10", game.getMerchantInventoryList(1).get(2)); + assertEquals("wood 3", game.getMerchantInventoryList(2).get(0)); + assertEquals("tarp 6", game.getMerchantInventoryList(2).get(1)); + assertEquals("glass 3", game.getMerchantInventoryList(3).get(0)); + assertEquals("tape 13", game.getMerchantInventoryList(3).get(1)); + assertEquals("rope 5", game.getMerchantInventoryList(3).get(2)); } }