Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int checkNext(int amount) {
- if (this.dir == Direction.NORTH && (this.posY + amount == 12 || this.posY + amount == -1)) {
- return -1;
- } else if (this.dir == Direction.EAST && (this.posX + amount == 12 || this.posX + amount == -1)) {
- return -1;
- } else if (this.dir == Direction.SOUTH && (this.posY - amount == -1 || this.posY - amount == 12)) {
- return -1;
- } else if (this.dir == Direction.WEST && (this.posX - amount == -1 || this.posX - amount == 12)) {
- return -1;
- } else if (gameMap.wallNearby(this.dir, this.posX, this.posY, amount)) {
- return 0;
- // 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
- // Single player first:
- } else if (RoboRallyDemo.getSinglePlayerMode()) {
- // Player checks for AI:
- // AI checking for player or AI is in AIRobot
- for (int i = 0; i < RoboRallyDemo.getAIs().length; i++) {
- if (RoboRallyDemo.getAIs()[i] != null) {
- if (this.dir == Direction.NORTH) {
- if (this.posY + amount == RoboRallyDemo.getAIs()[i].getPosY() && this.posX == RoboRallyDemo.getAIs()[i].getPosX()) {
- System.out.println("player collided in AI");
- return 2;
- }
- } else if (this.dir == Direction.WEST) {
- if (this.posX + amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
- System.out.println("player collided with AI");
- return 2;
- }
- } else if (this.dir == Direction.SOUTH) {
- if (this.posY - amount == RoboRallyDemo.getRobots()[i].getPosY() && this.posX == RoboRallyDemo.getRobots()[i].getPosX()) {
- System.out.println("player collided with AI");
- return 2;
- }
- } else if (this.dir == Direction.WEST) {
- if (this.posX - amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
- System.out.println("player collided with AI");
- return 2;
- }
- }
- }
- }
- // Checking for other players
- } else if (!RoboRallyDemo.getSinglePlayerMode()) {
- for (int i = 0; i < RoboRallyDemo.getRobots().length; i++) {
- if (RoboRallyDemo.getRobots()[i] != null) {
- if (i != RoboRallyDemo.getID()) {
- if (this.dir == Direction.NORTH) {
- if (this.posY + amount == RoboRallyDemo.getRobots()[i].getPosY()
- && this.posX == RoboRallyDemo.getRobots()[i].getPosX()) {
- System.out.println("player collided with another player");
- return 2;
- }
- } else if (this.dir == Direction.WEST) {
- if (this.posX + amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
- System.out.println("player collided with another player");
- return 2;
- }
- } else if (this.dir == Direction.SOUTH) {
- if (this.posY - amount == RoboRallyDemo.getRobots()[i].getPosY() && this.posX == RoboRallyDemo.getRobots()[i].getPosX()) {
- System.out.println("player collided with another player");
- return 2;
- }
- } else if (this.dir == Direction.WEST) {
- if (this.posX - amount == RoboRallyDemo.getRobots()[i].getPosX() && this.posY == RoboRallyDemo.getRobots()[i].getPosY()) {
- System.out.println("player collided with another player");
- return 2;
- }
- }
- }
- }
- }
- } else {
- return 1;
- }
- System.out.println("boring");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement