Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Starts moving the player, send the position to the server, and handles the response.
- * A call to the GUI form's updateLoc method is invoked to express the new position
- */
- //public void move() {
- @Override
- public void run() {
- Object response;
- while (connected) {
- try {
- Client.sleep(40);
- int x = curLoc.getX();
- int y = curLoc.getY();
- if ((x > 1 && x < 100) && y == 1) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(--x, y) : new XYCoordinate(++x, y);
- } else if (x == 100 && (y > 1 && y < 100)) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, --y) : new XYCoordinate(x, ++y);
- } else if ((x > 1 && x < 100) && y == 100) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(++x, y) : new XYCoordinate(--x, y);
- } else if (x == 1 && (y != 1 && y < 100)) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, ++y) : new XYCoordinate(x, --y);
- } else if (x == 1 && y == 1) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, ++y) : new XYCoordinate(++x, y);
- } else if (x == 100 && y == 1) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(--x, y) : new XYCoordinate(x, ++y);
- } else if (x == 100 && y == 100) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(x, --y) : new XYCoordinate(--x, y);
- } else if (x == 1 && y == 100) {
- this.curLoc = (this.dir.equals(RotationalDirection.COUNTERCLOCKWISE)) ? new XYCoordinate(++x, y) : new XYCoordinate(x, --y);
- }
- response = sendRequestObject(new LocationUpdate(this.curLoc, this.dir));
- if (response instanceof CollisionWarning) {
- this.dir = (this.dir == RotationalDirection.CLOCKWISE) ? RotationalDirection.COUNTERCLOCKWISE : RotationalDirection.CLOCKWISE;
- }
- this.frm.updateLoc(this.curLoc);
- } catch (InterruptedException ex) {
- System.err.printf("%s\n", ex.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment