Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. import javafx.geometry.Pos;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Monster {
  6.  
  7. private int health = 100;
  8. private boolean alive = true;
  9. private int moveCol;
  10. private int moveRow;
  11. private Position monsterLocation;
  12. private int direction = 1;
  13. public static final int NORTH = 0;
  14. public static final int EAST = 1;
  15. public static final int SOUTH = 2;
  16. public static final int WEST = 3;
  17. private TowerDefenceLevel level;
  18.  
  19.  
  20. public Monster(int rowStart, int colStart, TowerDefenceLevel level){
  21. monsterLocation = new Position(rowStart,colStart);
  22. this.level = level;
  23. }
  24.  
  25. public int getHealth() {
  26. return health;
  27. }
  28.  
  29. public Position getPosition() {
  30. return monsterLocation;
  31. }
  32.  
  33. public void setHealth(int damage){
  34. health = health - damage;
  35. }
  36.  
  37. public boolean frontIsClear() {
  38. if (){
  39. }
  40. int row = monsterLocation.getRow();
  41. int col = monsterLocation.getCol();
  42. if (direction == NORTH)
  43. row = row -1;
  44. else if (direction == SOUTH)
  45. row = row +1;
  46. else if (direction == EAST)
  47. col = col +1;
  48. else
  49. col = col -1;
  50. return level.passable[row][col];
  51.  
  52. //return world.isValid(loc) && world.getImage(loc) == null;
  53. }//frontIsClear
  54. public boolean leftIsClear() {
  55. int row = monsterLocation.getRow();
  56. int col = monsterLocation.getCol();
  57. if (direction == NORTH)
  58. col = col - 1;
  59. else if (direction == SOUTH)
  60. col = col +1;
  61. else if (direction == EAST)
  62. row = row -1;
  63. else
  64. row = row + 1;
  65. return level.passable[row][col];
  66. }//leftisclear
  67.  
  68. //före: roboten vet inte vad som finns till höger i körriktningen
  69. //efter: roboten vet vad som finns till höger i körriktningen
  70. public boolean rightIsClear() {
  71. int row = monsterLocation.getRow();
  72. int col = monsterLocation.getCol();
  73. if (direction == NORTH)
  74. col = col +1;
  75. else if (direction == SOUTH)
  76. col = col -1;
  77. else if (direction == EAST)
  78. row = row + 1;
  79. else
  80. row = row - 1;
  81. return level.passable[row][col];
  82. }//frontIsClear
  83.  
  84. public boolean[] wallCheck(){
  85. boolean[] whatWay = {false,false,false};
  86. if (frontIsClear())
  87. whatWay[0] = true;
  88. if(leftIsClear())
  89. whatWay[1] = true;
  90. if(rightIsClear())
  91. whatWay[2] = true;
  92. return whatWay;
  93. }
  94. public int directionPlanner(){
  95. boolean[] whatWay;
  96. whatWay = wallCheck();
  97. int t=0;
  98. int r;
  99. Random random = new Random();
  100. r = random.nextInt(3);
  101. System.out.println("Skriv ut r: "+r);
  102. for(int i = 0;i < 3;i++) {
  103. if (whatWay[i]) {
  104. t = r;
  105. }
  106. }
  107. //System.out.println(t);
  108. return t;
  109. }
  110. public void move(){
  111. int row = monsterLocation.getRow();
  112. int col = monsterLocation.getCol();
  113. Position newPosition;
  114. if (direction == NORTH)//up
  115. newPosition = new Position(row - 1, col);
  116. else if (direction == SOUTH)//down
  117. newPosition = new Position(row + 1, col);
  118. else if (direction == WEST)//right
  119. newPosition = new Position(row, col - 1);
  120. else//left
  121. newPosition = new Position(row, col + 1);
  122. monsterLocation = newPosition;
  123. }
  124. public void turnLeft() {
  125. if (direction == NORTH) {
  126. direction = WEST;
  127. } else if (direction == SOUTH) {
  128. direction = EAST;
  129. } else if (direction == WEST) {
  130. direction = SOUTH;
  131. } else {
  132. direction = NORTH;
  133. }
  134. }
  135. public void turnRight() {
  136. if (direction == NORTH) {
  137. direction = EAST;
  138. } else if (direction == SOUTH) {
  139. direction = WEST;
  140. } else if (direction == EAST) {
  141. direction = SOUTH;
  142. } else {
  143. direction = NORTH;
  144. }
  145. }//turnRight
  146.  
  147. public void setDirection(int direction){
  148. this.direction = direction;
  149. }
  150. public int getDirection(){
  151. return this.direction;
  152. }
  153. public boolean getIsAlive(){
  154. return alive;
  155. }
  156. public void setIsAlive(boolean death){
  157. alive = death;
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement