ace

takeitem3

ace
Aug 18th, 2010
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import java.util.ArrayList;
  2. /**
  3. * Write a description of class Player here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class Player
  9. {
  10. // instance variables - replace the example below with your own
  11. private Room currentRoom;
  12. private String playerName;
  13. private ArrayList<Item> items;
  14. private int strength;
  15. private int encumberance;
  16. /**
  17. * Constructor for objects of class Player
  18. */
  19. public Player()
  20. {
  21. this.currentRoom = currentRoom;
  22. this.playerName = playerName;
  23. items = new ArrayList<Item>();
  24. strength = 3;
  25. encumberance = 0;
  26. }
  27.  
  28. /**
  29. * Gets the current room
  30. */
  31. public Room getCurrentRoom(){
  32. return currentRoom;
  33. }
  34.  
  35. /**
  36. * Sets the current room to a different room
  37. */
  38. public void setCurrentRoom(Room room)
  39. {
  40. currentRoom = room;
  41. }
  42.  
  43. public String takeItem(String itemName)
  44. {
  45. if(currentRoom.roomContents() == false)
  46. {
  47. return "there is nothing here.";
  48. }
  49.  
  50. if(currentRoom.roomContents() == true)
  51. {
  52. if(item.getItemWeight <= encumberance)
  53. {
  54. items.add(currentRoom.itemCheck(itemName));
  55. encumberance = encumberance + item.getItemWeight();
  56. return "you have taken " + itemName;
  57. }
  58. if(item.getItemWeight() > strength)
  59. {
  60. return "" + item.getItemName() + " is too heavy";
  61. }
  62.  
  63. else
  64. {
  65. return "You are carrying too much to take " + item.getItemName();
  66. }
  67. }
  68.  
  69. }
  70.  
  71.  
  72.  
  73. public String dropItem(String itemName){
  74.  
  75. if(items.isEmpty())
  76. {
  77. return "you are not carrying anything";
  78. }
  79. else{
  80. Item droppedItem = null;
  81. for (Item item : items){
  82. if (item.getItemName().equals(itemName)){
  83. droppedItem = item;
  84. currentRoom.setItems(item);
  85. }
  86. }
  87. items.remove(droppedItem);
  88. return "you have dropped " + droppedItem.getItemDescription();
  89. }
  90. }
  91.  
  92.  
  93. public String checkInventory()
  94. {
  95. if(items.isEmpty())
  96. {
  97. return "you are not carrying anything";
  98. }
  99. else
  100. {
  101. for (Item item : items)
  102. {
  103.  
  104. return "" + item.getItemDescription();
  105. }
  106. }
  107. return null;
  108.  
  109. }
  110. }
Add Comment
Please, Sign In to add comment