- import java.util.ArrayList;
- /**
- * Write a description of class Player here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Player
- {
- // instance variables - replace the example below with your own
- private Room currentRoom;
- private String playerName;
- private ArrayList<Item> items;
- private int strength;
- private int encumberance;
- /**
- * Constructor for objects of class Player
- */
- public Player()
- {
- this.currentRoom = currentRoom;
- this.playerName = playerName;
- items = new ArrayList<Item>();
- strength = 3;
- encumberance = 0;
- }
- /**
- * Gets the current room
- */
- public Room getCurrentRoom(){
- return currentRoom;
- }
- /**
- * Sets the current room to a different room
- */
- public void setCurrentRoom(Room room)
- {
- currentRoom = room;
- }
- public String takeItem(String itemName)
- {
- if(currentRoom.roomContents() == false)
- {
- return "there is nothing here.";
- }
- if(currentRoom.roomContents() == true)
- {
- if(item.getItemWeight <= encumberance)
- {
- items.add(currentRoom.itemCheck(itemName));
- encumberance = encumberance + item.getItemWeight();
- return "you have taken " + itemName;
- }
- if(item.getItemWeight() > strength)
- {
- return "" + item.getItemName() + " is too heavy";
- }
- else
- {
- return "You are carrying too much to take " + item.getItemName();
- }
- }
- }
- public String dropItem(String itemName){
- if(items.isEmpty())
- {
- return "you are not carrying anything";
- }
- else{
- Item droppedItem = null;
- for (Item item : items){
- if (item.getItemName().equals(itemName)){
- droppedItem = item;
- currentRoom.setItems(item);
- }
- }
- items.remove(droppedItem);
- return "you have dropped " + droppedItem.getItemDescription();
- }
- }
- public String checkInventory()
- {
- if(items.isEmpty())
- {
- return "you are not carrying anything";
- }
- else
- {
- for (Item item : items)
- {
- return "" + item.getItemDescription();
- }
- }
- return null;
- }
- }