I am trying to create a player class to pick up and drop as well as carry items and this is the code I have so far. However, I am unsure what needs to be changed for it to work.
import java.util.ArrayList;
public class Player
{
private String Name_;
private ArrayList<Item> playerItems_;
/**Construtor for Player class
*@param Name - Name of the player
*/
public Player(String name)
{
Name_ = name;
playerItems_ = new ArrayList<Item>();
}
/**Accesor Method for the pkayer name
*
*/
public String getName()
{
return Name_;
}
/**
* Add an item the player item storage
* @param Item item - the item that the payer will pick up
*/
public void pickUpItem(Item item)
{
if(!item.gotIt()) playerItems_.add(item);
item.pickUpItem();
}
/**
* Remove an item the player item storage
* @param Item item - the item that the payer will drop
*/
public void dropItem(String itemName)
{
for(int i = 0; i < playerItems_.size();i++)
{
if(playerItems_.get(i).getName().equalsIgnoreCase(itemName))
{
playerItems_.remove(i);
break;
}
}
}
/**
*Determines wheter the player has this item or now
*@param String itemNAme
*/
public boolean contains(String itemName)
{
for(Item item : playerItems_)
{
if(item.getName().equalsIgnoreCase(itemName))return true;
}
return false;
}
}//Class