コード例 #1
0
ファイル: TileUtils.java プロジェクト: svenmeys/Carcassonne
  public static final int countSurroundingTiles(Tile tile) {
    int counter = 0;

    boolean tl = false;
    boolean tr = false;
    boolean bl = false;
    boolean br = false;

    for (int i = 0; i < 4; i++) {
      Area a = tile.getBorderConnections()[i * 3];
      if (a == null) continue;
      counter++;

      if (i == 0) {
        tl = (a.getLocation().getBorderConnections()[10] != null);
        tr = (a.getLocation().getBorderConnections()[4] == null);
      }
      if (i == 1) {
        tr = (a.getLocation().getBorderConnections()[1] != null);
        br = (a.getLocation().getBorderConnections()[7] != null);
      }
      if (i == 2) {
        br = (a.getLocation().getBorderConnections()[4] != null);
        bl = (a.getLocation().getBorderConnections()[10] != null);
      }
      if (i == 3) {
        bl = (a.getLocation().getBorderConnections()[7] != null);
        tl = (a.getLocation().getBorderConnections()[1] != null);
      }
    }
    return counter + (tl ? 1 : 0) + (bl ? 1 : 0) + (tr ? 1 : 0) + (br ? 1 : 0);
  }
コード例 #2
0
ファイル: TileUtils.java プロジェクト: svenmeys/Carcassonne
  private static final void connectBorders(Tile t1, int b1, Tile t2, int b2) {
    t1.getBorder()[b1].setZone(
        t1.getBorder()[b1].getZone().mergeInto(t2.getBorder()[b2].getZone()));

    t1.getBorderConnections()[b1] = t2.getBorder()[b2];
    t2.getBorderConnections()[b2] = t1.getBorder()[b1];
  }
コード例 #3
0
ファイル: TileUtils.java プロジェクト: svenmeys/Carcassonne
 public static final void matchTiles(Tile tile, Tile top, Tile bottom, Tile left, Tile right)
     throws InvalidTileException {
   if (tile == null) throw new InvalidTileException("Tile can not be null");
   if (top != null) {
     match(tile.getBorder()[0], top.getBorder()[8]);
     match(tile.getBorder()[1], top.getBorder()[7]);
     match(tile.getBorder()[2], top.getBorder()[6]);
   }
   if (right != null) {
     match(tile.getBorder()[3], right.getBorder()[11]);
     match(tile.getBorder()[4], right.getBorder()[10]);
     match(tile.getBorder()[5], right.getBorder()[9]);
   }
   if (bottom != null) {
     match(tile.getBorder()[6], bottom.getBorder()[2]);
     match(tile.getBorder()[7], bottom.getBorder()[1]);
     match(tile.getBorder()[8], bottom.getBorder()[0]);
   }
   if (left != null) {
     match(tile.getBorder()[9], left.getBorder()[5]);
     match(tile.getBorder()[10], left.getBorder()[4]);
     match(tile.getBorder()[11], left.getBorder()[3]);
   }
 }