From dd2991f3c44c04792dbbc0edd9bbd84a411a841d Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Mon, 2 Feb 2015 03:27:02 -0500 Subject: [PATCH] flushed out the player class and the testplayer class a little. --- MerchantRPGCSE2102/src/game/Player.java | 62 ++++++++++++++++++++ MerchantRPGCSE2102/src/tests/TestPlayer.java | 20 ++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/MerchantRPGCSE2102/src/game/Player.java b/MerchantRPGCSE2102/src/game/Player.java index d38f960..3c5122d 100644 --- a/MerchantRPGCSE2102/src/game/Player.java +++ b/MerchantRPGCSE2102/src/game/Player.java @@ -4,16 +4,78 @@ 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/tests/TestPlayer.java b/MerchantRPGCSE2102/src/tests/TestPlayer.java index 68e8dea..00e758c 100644 --- a/MerchantRPGCSE2102/src/tests/TestPlayer.java +++ b/MerchantRPGCSE2102/src/tests/TestPlayer.java @@ -1,8 +1,24 @@ package tests; +import junit.framework.TestCase; import game.Player; -public class TestPlayer +public class TestPlayer extends TestCase { - + private Player p; + + public void setup() + { + p = new Player("TestPlayer", 1000, 1); + } + + //test cash system for Player class + public void testPlayerCashSystem() + { + setup(); + p.deductCash(500); + assertEquals(500, p.getPlayerCash()); + p.increaseCash(500); + assertEquals(1000,p.getPlayerCash()); + } }