Advertisement
Guest User

Character

a guest
Dec 9th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. package com.group4.gameLogic;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5.  
  6. import javafx.beans.Observable;
  7. import javafx.collections.FXCollections;
  8. import javafx.collections.ObservableList;
  9.  
  10. public class Character extends Coordinate {
  11.  
  12. private String name; //consider revising this to work with scanner input
  13. private int breath, amountOfBreathLeft, life, levelReached, carryCapacity, recyclingUpgrade, rewards;
  14. private ObservableList<Collectables> inventory;
  15. private HashMap<String, Integer> collectablesData = new HashMap<String, Integer>();
  16.  
  17. public Character(String name, int xPos, int yPos) {
  18. super(xPos, yPos);
  19. this.breath = 14;
  20. this.name = name;
  21. this.amountOfBreathLeft = breath;
  22. this.life = 100;
  23. this.levelReached = 0; //Note all numbers are
  24. this.recyclingUpgrade = 0;
  25. this.carryCapacity = 3;
  26. this.inventory = FXCollections.observableArrayList();
  27. }
  28.  
  29. public Character(int xPos, int yPos){
  30. this("ThisIsAPlaceHolderForUI", xPos, yPos);
  31. }
  32. public void incrementCollectablesData(String type) {
  33. if (this.collectablesData.get(type) == null) {
  34. this.collectablesData.put(type, 1);
  35. }else {
  36. this.collectablesData.put(type, (this.collectablesData.get(type) + 1));
  37. }
  38. }
  39.  
  40. public HashMap getCollectablesData(){
  41. return this.collectablesData;
  42. }
  43.  
  44. // Checks if the player is on the surface to get air
  45. // Else remove on from breathLeft and then check if they died.
  46. public boolean UpdateBreath() {
  47. this.amountOfBreathLeft--;
  48. if (getCoordinateY() == 0) {
  49. this.amountOfBreathLeft = breath;
  50. return false;
  51. } else {
  52. if (this.amountOfBreathLeft <= 0) {
  53. // They are dead
  54. life = 0;
  55. return true;
  56. } else {
  57. return false;
  58. }
  59. }
  60.  
  61. }
  62.  
  63. // check if character has the same coordinate as collectables and then pick it up.
  64. public void OnItem(Room[][] itemInRoom) {
  65. if(itemInRoom[getCoordinateX()][getCoordinateY()].getCollectable() != null ){
  66. if(addToInventory(itemInRoom[getCoordinateX()][getCoordinateY()].getCollectable())){
  67. itemInRoom[getCoordinateX()][getCoordinateY()].clearCollectable();
  68. } else {
  69. System.out.println("You dont have any more room.");
  70. System.out.println("Your inventory size: " + getCarryCapacity() + "/" + getCarryCapacity());
  71. }
  72. }
  73. }
  74.  
  75.  
  76.  
  77. // check if character has the same coorddinnate as hostile and then take damage.
  78. // return true if dead else return false.
  79. public boolean hitHostile(ArrayList<Hostiles> hostiles) {
  80. for (Hostiles hostile : hostiles) {
  81. if (hostile.getCoordinateX() == getCoordinateX()
  82. && hostile.getCoordinateY() == getCoordinateY()) {
  83. // Damage the player
  84. life -= hostile.getDamage();
  85. // Checks if the player is dead
  86. if (getLife() <= 0) {
  87. return true;
  88. }
  89. }
  90. }
  91. return false;
  92.  
  93. }
  94.  
  95. // Name
  96. public String getName() {
  97. return this.name;
  98. }
  99.  
  100. public void setName(String nameIn) {
  101. this.name = nameIn;
  102. }
  103.  
  104. // Breath
  105. public int getBreath() {
  106. return this.amountOfBreathLeft;
  107. }
  108.  
  109. public void upgradeBreath() {
  110. breath++;
  111. amountOfBreathLeft = breath;
  112. }
  113.  
  114. public int getRewards() {
  115. return this.rewards;
  116. }
  117.  
  118. public void setRewards(int rewardsIn) {
  119. this.rewards = rewardsIn;
  120. }
  121.  
  122. // Life
  123. public int getLife() {
  124. return this.life;
  125. }
  126.  
  127. public void setLife(int life) {
  128. this.life = life;
  129. }
  130.  
  131. // LevelReached
  132. public int getLevelReached() {
  133. return this.levelReached;
  134. }
  135.  
  136. public void setLevelReached(int levelReachedIn) {
  137. this.levelReached = levelReachedIn;
  138. }
  139.  
  140. // carryCapacity
  141. public int getCarryCapacity() {
  142. return this.carryCapacity;
  143. }
  144.  
  145. // This is not used yey -- Kevin 11-11-2019
  146. public void setCarryCapacity(int carryCapacityIn) {
  147. this.carryCapacity = carryCapacityIn;
  148. }
  149.  
  150. // addToInventory
  151. public boolean addToInventory(Collectables collectable) {
  152. if (this.inventory.size() < this.carryCapacity) {
  153. this.inventory.add(collectable);
  154. return true;
  155. } else {
  156. return false;
  157. }
  158. }
  159.  
  160. public void addToInventoryCheat(Collectables collectable) {
  161. this.inventory.add(collectable);
  162. }
  163.  
  164. // getInventory
  165. public ObservableList<Collectables> getInventory() {
  166. return this.inventory;
  167. }
  168.  
  169. public void setInventory(ObservableList<Collectables> inventory) {
  170. this.inventory = inventory;
  171. }
  172.  
  173. public void clearInventory() {
  174. this.inventory.clear();
  175. }
  176.  
  177. public int getRecyclingUpgrade() {
  178. return this.recyclingUpgrade;
  179. }
  180.  
  181. // This is not used yet 11-11-2019
  182. public void setRecyclingUpgrade(int aRecyclingUpgrade) {
  183. this.recyclingUpgrade = aRecyclingUpgrade;
  184. }
  185.  
  186. @Override
  187. public String toString() {
  188. return "Error toString on character object";
  189. }
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement