Beispiel #1
0
  protected void renderSpace(Graphics g, Tile t, int height, int inx, int iny) {
    int x = inx + 1;
    int y = iny + 1;

    Image tileFace = dirt;

    if (t != null) {
      if (t.getType() == TileType.RICE) {
        tileFace = rice;
      }
      if (t.getType() == TileType.VILLAGE) {
        tileFace = village;
      }
    }

    g.setColor(Color.white);
    g.drawImage(tileFace, x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, this);

    int givenHeight = height;

    if (t != null) {
      g.setColor(Color.black);
      if (t.getJoined(Grid.TOP) == null) {
        g.drawLine(
            (x) * TILE_WIDTH, (y) * TILE_HEIGHT, (x + 1) * TILE_WIDTH - 1, (y) * TILE_HEIGHT);
        g.drawLine(
            (x) * TILE_WIDTH,
            (y) * TILE_HEIGHT + 1,
            (x + 1) * TILE_WIDTH - 1,
            (y) * TILE_HEIGHT + 1);
      }
      if (t.getJoined(Grid.BOTTOM) == null) {
        g.drawLine(
            (x) * TILE_WIDTH,
            (y + 1) * TILE_HEIGHT - 1,
            (x + 1) * TILE_WIDTH - 1,
            (y + 1) * TILE_HEIGHT - 1);
        g.drawLine(
            (x) * TILE_WIDTH,
            (y + 1) * TILE_HEIGHT - 2,
            (x + 1) * TILE_WIDTH - 1,
            (y + 1) * TILE_HEIGHT - 2);
      }
      if (t.getJoined(Grid.LEFT) == null) {
        g.drawLine(
            (x) * TILE_WIDTH, (y) * TILE_HEIGHT, (x) * TILE_WIDTH, (y + 1) * TILE_HEIGHT - 1);
        g.drawLine(
            (x) * TILE_WIDTH + 1,
            (y) * TILE_HEIGHT,
            (x) * TILE_WIDTH + 1,
            (y + 1) * TILE_HEIGHT - 1);
      }
      if (t.getJoined(Grid.RIGHT) == null) {
        g.drawLine(
            (x + 1) * TILE_WIDTH - 1,
            (y) * TILE_HEIGHT,
            (x + 1) * TILE_WIDTH - 1,
            (y + 1) * TILE_HEIGHT - 1);
        g.drawLine(
            (x + 1) * TILE_WIDTH - 2,
            (y) * TILE_HEIGHT,
            (x + 1) * TILE_WIDTH - 2,
            (y + 1) * TILE_HEIGHT - 1);
      }
    }

    if (height > 0 && t.getType() == TileType.PALACE) {
      givenHeight = ((PalaceTile) t).getLevel();
      renderPalaceRecursive(
          g, givenHeight / 2, x * TILE_WIDTH, y * TILE_WIDTH, TILE_WIDTH, TILE_HEIGHT);
      if (!((PalaceTile) t).isHeadsUp()) {
        g.setColor(new Color(0, 0, 0, 0.5f));
        g.fillRect(x * TILE_WIDTH, y * TILE_WIDTH, TILE_WIDTH, TILE_HEIGHT);
      }
    }
  }
Beispiel #2
0
  /** recursively renders a network of spaces */
  protected void renderNetworkRecursive(
      Graphics g, AbstractCollection<Tile> finished, Tile origin, int x, int y, Color hilight) {
    int dummyHeight = 0;

    if (x >= 0 && x < boardWidth && y >= 0 && y < boardHeight) {
      dummyHeight = spaceHeights[x][y];
    }
    renderSpace(g, origin, dummyHeight, x, y);
    g.setColor(hilight);
    g.fillRect((x + 1) * TILE_WIDTH, (y + 1) * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
    if (x >= 0 && x < boardWidth && y >= 0 && y < boardHeight) {
      renderText(
          g,
          Integer.toString(spaceHeights[x][y]),
          (x + 1) * TILE_WIDTH,
          (y + 1) * TILE_HEIGHT + g.getFont().getSize());
    }
    if (origin.getJoined(Grid.LEFT) != null && !finished.contains(origin.getJoined(Grid.LEFT))) {
      finished.add(origin.getJoined(Grid.LEFT));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.LEFT), x - 1, y, hilight);
    }
    if (origin.getJoined(Grid.RIGHT) != null && !finished.contains(origin.getJoined(Grid.RIGHT))) {
      finished.add(origin.getJoined(Grid.RIGHT));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.RIGHT), x + 1, y, hilight);
    }
    if (origin.getJoined(Grid.TOP) != null && !finished.contains(origin.getJoined(Grid.TOP))) {
      finished.add(origin.getJoined(Grid.TOP));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.TOP), x, y - 1, hilight);
    }
    if (origin.getJoined(Grid.BOTTOM) != null
        && !finished.contains(origin.getJoined(Grid.BOTTOM))) {
      finished.add(origin.getJoined(Grid.BOTTOM));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.BOTTOM), x, y + 1, hilight);
    }
  }