Esempio n. 1
0
  public static void writePosition(NetOutput out, Position pos) throws IOException {
    long x = pos.getX() & POSITION_WRITE_SHIFT;
    long y = pos.getY() & POSITION_Y_SHIFT;
    long z = pos.getZ() & POSITION_WRITE_SHIFT;

    out.writeLong(x << POSITION_X_SIZE | y << POSITION_Y_SIZE | z);
  }
  public ArrayList<Position> getMoves(Position p) {
    String e = ask("moves:" + p.getX() + ":" + p.getY() + ";");
    ArrayList<Position> m = new ArrayList<Position>();

    String[] o = e.split(":");
    for (int i = 0; i < o.length; i = i + 2) {
      m.add(new Position(Integer.parseInt(o[i]), Integer.parseInt(o[i + 1])));
    }

    return m;
  }
 public void move(Piece p, Position pos) {
   String s =
       ask(
           "move:"
               + p.getPos().getX()
               + ":"
               + p.getPos().getY()
               + ":"
               + pos.getX()
               + ":"
               + pos.getY()
               + ";");
   System.out.println(s);
 }
Esempio n. 4
0
  public static void writeEntityMetadata(NetOutput out, EntityMetadata[] metadata)
      throws IOException {
    for (EntityMetadata meta : metadata) {
      int id = MagicValues.value(Integer.class, meta.getType()) << 5 | meta.getId() & 0x1F;
      out.writeByte(id);
      switch (meta.getType()) {
        case BYTE:
          out.writeByte((Byte) meta.getValue());
          break;
        case SHORT:
          out.writeShort((Short) meta.getValue());
          break;
        case INT:
          out.writeInt((Integer) meta.getValue());
          break;
        case FLOAT:
          out.writeFloat((Float) meta.getValue());
          break;
        case STRING:
          out.writeString((String) meta.getValue());
          break;
        case ITEM:
          writeItem(out, (ItemStack) meta.getValue());
          break;
        case POSITION:
          Position pos = (Position) meta.getValue();
          out.writeInt(pos.getX());
          out.writeInt(pos.getY());
          out.writeInt(pos.getZ());
          break;
        case ROTATION:
          Rotation rot = (Rotation) meta.getValue();
          out.writeFloat(rot.getPitch());
          out.writeFloat(rot.getYaw());
          out.writeFloat(rot.getRoll());
          break;
        default:
          throw new IOException("Unmapped metadata type: " + meta.getType());
      }
    }

    out.writeByte(127);
  }
  // board stuff
  public Piece getNet(Position p) {
    Piece tmp = null;

    String b = ask("get:" + p.getX() + ":" + p.getY() + ";");
    String[] cms = b.split(":");

    if (cms[0].equals("n")) {
      return tmp;
    }
    char[] chr = cms[0].toCharArray();
    char c = chr[0];
    Player s = new Player(cms[2].equals("b"), null);
    int l = Integer.parseInt(cms[1]);

    if (c == 'P') tmp = new Pawn(p, l, s);
    else if (c == 'R') tmp = new Rook(p, l, s);
    else if (c == 'K') tmp = new Knight(p, l, s);
    else if (c == 'B') tmp = new Bishop(p, l, s);
    else if (c == 'Q') tmp = new Queen(p, l, s);
    else if (c == '!') tmp = new King(p, l, s);

    return tmp;
  }