Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 4.56 KB | None | 0 0
  1.     public int checkNext(int amount) {
  2.         if (this.dir == Direction.NORTH && (this.posY + amount == 12 || this.posY + amount == -1)) {
  3.             return -1;
  4.         } else if (this.dir == Direction.EAST && (this.posX + amount == 12 || this.posX + amount == -1)) {
  5.             return -1;
  6.         } else if (this.dir == Direction.SOUTH && (this.posY - amount == -1 || this.posY - amount == 12)) {
  7.             return -1;
  8.         } else if (this.dir == Direction.WEST && (this.posX - amount == -1 || this.posX - amount == 12)) {
  9.             return -1;
  10.         } else if (gameMap.wallNearby(this.dir, this.posX, this.posY, amount)) {
  11.             return 0;
  12.         // If the move in a direction gives this robot and another robot the same location, then the other robot will be pushed in that direction for the same distance
  13.         // Single player first:
  14.         } else if (RoboRallyDemo.getSinglePlayerMode()) {
  15.             // Player checks for AI:
  16.             // AI checking for player or AI is in AIRobot
  17.             for (int i = 0; i < RoboRallyDemo.getAIs().length; i++) {
  18.                 if (RoboRallyDemo.getAIs()[i] != null) {
  19.                     if (this.dir == Direction.NORTH) {
  20.                         if (this.posY + amount == RoboRallyDemo.getAIs()[i].getPosY() && this.posX == RoboRallyDemo.getAIs()[i].getPosX()) {
  21.                             System.out.println("player collided in AI");
  22.                             return 2;
  23.                         }
  24.                     } else if (this.dir == Direction.WEST) {
  25.                         if (this.posX + amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
  26.                             System.out.println("player collided with AI");
  27.                             return 2;
  28.                         }
  29.                     } else if (this.dir == Direction.SOUTH) {
  30.                         if (this.posY - amount == RoboRallyDemo.getRobots()[i].getPosY() && this.posX == RoboRallyDemo.getRobots()[i].getPosX()) {
  31.                             System.out.println("player collided with AI");
  32.                             return 2;
  33.                         }
  34.                     } else if (this.dir == Direction.WEST) {
  35.                         if (this.posX - amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
  36.                             System.out.println("player collided with AI");
  37.                             return 2;
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.             // Checking for other players
  43.         } else if (!RoboRallyDemo.getSinglePlayerMode()) {
  44.             for (int i = 0; i < RoboRallyDemo.getRobots().length; i++) {
  45.                 if (RoboRallyDemo.getRobots()[i] != null) {
  46.                     if (i != RoboRallyDemo.getID()) {
  47.                         if (this.dir == Direction.NORTH) {
  48.                             if (this.posY + amount == RoboRallyDemo.getRobots()[i].getPosY()
  49.                                     && this.posX == RoboRallyDemo.getRobots()[i].getPosX()) {
  50.                                 System.out.println("player collided with another player");
  51.                                 return 2;
  52.                             }
  53.                         } else if (this.dir == Direction.WEST) {
  54.                             if (this.posX + amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
  55.                                 System.out.println("player collided with another player");
  56.                                 return 2;
  57.                             }
  58.                         } else if (this.dir == Direction.SOUTH) {
  59.                             if (this.posY - amount == RoboRallyDemo.getRobots()[i].getPosY() && this.posX == RoboRallyDemo.getRobots()[i].getPosX()) {
  60.                                 System.out.println("player collided with another player");
  61.                                 return 2;
  62.                             }
  63.                         } else if (this.dir == Direction.WEST) {
  64.                             if (this.posX - amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
  65.                                 System.out.println("player collided with another player");
  66.                                 return 2;
  67.                             }
  68.                         }
  69.                     }
  70.                 }
  71.             }
  72.         } else {
  73.             return 1;
  74.         }
  75.         System.out.println("boring");
  76.         return 1;
  77.  
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement