Skip to content

Commit

Permalink
flushed out the player class and the testplayer class a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Feb 2, 2015
1 parent 5d94bdd commit dd2991f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
62 changes: 62 additions & 0 deletions MerchantRPGCSE2102/src/game/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
20 changes: 18 additions & 2 deletions MerchantRPGCSE2102/src/tests/TestPlayer.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit dd2991f

Please sign in to comment.