Guest User

Untitled

a guest
Feb 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1.     /**
  2.      * Starts moving the player, send the position to the server, and handles the response.
  3.      * A call to the GUI form's updateLoc method is invoked to express the new position
  4.      */
  5.     //public void move() {
  6.     @Override
  7.     public void run() {
  8.         Object response;
  9.         while (connected) {
  10.             try {
  11.                 Client.sleep(40);
  12.                 int x = curLoc.getX();
  13.                 int y = curLoc.getY();
  14.                 if ((x > 1 && x < 100) && y == 1) {
  15.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(--x, y) : new XYCoordinate(++x, y);
  16.                 } else if (x == 100 && (y > 1 && y < 100)) {
  17.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, --y) : new XYCoordinate(x, ++y);
  18.                 } else if ((x > 1 && x < 100) && y == 100) {
  19.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(++x, y) : new XYCoordinate(--x, y);
  20.                 } else if (x == 1 && (y != 1 && y < 100)) {
  21.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, ++y) : new XYCoordinate(x, --y);
  22.                 } else if (x == 1 && y == 1) {
  23.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, ++y) : new XYCoordinate(++x, y);
  24.                 } else if (x == 100 && y == 1) {
  25.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(--x, y) : new XYCoordinate(x, ++y);
  26.                 } else if (x == 100 && y == 100) {
  27.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, --y) : new XYCoordinate(--x, y);
  28.                 } else if (x == 1 && y == 100) {
  29.                     this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(++x, y) : new XYCoordinate(x, --y);
  30.                 }
  31.                 response = sendRequestObject(new LocationUpdate(this.curLoc, this.dir));
  32.                 if (response instanceof CollisionWarning) {
  33.                     this.dir = (this.dir == RotationalDirection.CLOCKWISE) ? RotationalDirection.COUNTERCLOCKWISE : RotationalDirection.CLOCKWISE;
  34.                 }
  35.                 this.frm.updateLoc(this.curLoc);
  36.             } catch (InterruptedException ex) {
  37.                 System.err.printf("%s\n", ex.getMessage());
  38.             }
  39.         }
  40.     }
Add Comment
Please, Sign In to add comment