Package communication

Source Code of communication.CoordPacket

package communication;

import BasicDataType.MapUpdate;

/**
* A Packet with Coordinates in it
* @author Marcus Fredriksson
*/
public class CoordPacket extends Packet{

  /**
   * Constructs a CoordPacket of given expvalue exploration value,
   *  x coordinate and y coordinate
   * @param expvalue exploration value of the coordinate -1 Obstacle 0 Unexplored 1 Free
   * @param x coordinate of the square
   * @param y coordinate of the square
   */
  public CoordPacket(byte expvalue,byte x,byte y){
    super(COORD);
    data[0] = expvalue;
    data[1] = x;
    data[2] = y;
  }

  public CoordPacket(byte[] arr) {
    super(arr);
  }

  /**
   * Constructs a CoordPacket from a MapUpdate
   * @param map Map update to be converted to a CoordPacket
   */
  public CoordPacket(MapUpdate map) {
    this(map.getExpValue(),map.getCoordX(),map.getCoordY());
  }

  /**
   * Gets the x coordinate of the CoordPacket
   * @return the square coordinate x of the CoordPacket
   */
  public byte getCoordX(){
    return this.data[1];
  }
 
  /**
   * Gets the y coordinate of the CoordPacket
   * @return the square coordinate y of the CoordPacket
   */
  public byte getCoordY(){
    return this.data[2];
  }
 
  /**
   * Gets the exploration value of the square of the CoordPacket
   * @return the square exploration value of the square
   */
  public byte getExpValue(){
    return this.data[0];
  }

  /** Gets the packet as a MapUpdate
   * @return Returns the packet as a MapUpdate
   */
  public MapUpdate toMapUpdate() {
    return new MapUpdate(data[0], data[1], data[2]);
  }

}
TOP

Related Classes of communication.CoordPacket

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.