Exemplo n.º 1
0
  private void addFieldLines(
      final Color borderColor, final Color gridColor, final int borderWidth, final int gridWidth) {
    // Remove old lines if there were any before
    for (Line line : this.gameFieldLines) {
      line.detachSelf();
      line.dispose();
    }
    this.gameFieldLines.clear();

    // add vertical lines
    for (int cellX = 1; cellX < this.getModel().getWidth(); cellX++) {
      Line line =
          new Line(
              cellX * GameField.CELL_WIDTH,
              0,
              cellX * GameField.CELL_WIDTH,
              this.getHeight(),
              this.vertexBufferObjectManager);
      line.setColor(gridColor);
      line.setLineWidth(gridWidth);
      this.gameFieldLines.add(line);
      this.attachChild(line);
    }

    // add horizontal lines
    for (int cellY = 1; cellY < this.getModel().getHeight(); cellY++) {
      Line line =
          new Line(
              0,
              cellY * GameField.CELL_HEIGHT,
              this.getWidth(),
              cellY * GameField.CELL_HEIGHT,
              this.vertexBufferObjectManager);
      line.setColor(gridColor);
      line.setLineWidth(gridWidth);
      this.gameFieldLines.add(line);
      this.attachChild(line);
    }

    // Adding border for the game-field
    Line firstLineVertical = new Line(0, 0, 0, this.getHeight(), this.vertexBufferObjectManager);
    firstLineVertical.setColor(borderColor);
    firstLineVertical.setLineWidth(borderWidth);
    this.gameFieldLines.add(firstLineVertical);
    this.attachChild(firstLineVertical);
    Line lastLineVertical =
        new Line(
            this.getModel().getWidth() * GameField.CELL_WIDTH,
            0,
            this.getModel().getWidth() * GameField.CELL_WIDTH,
            this.getHeight(),
            this.vertexBufferObjectManager);
    lastLineVertical.setColor(borderColor);
    lastLineVertical.setLineWidth(borderWidth);
    this.gameFieldLines.add(lastLineVertical);
    this.attachChild(lastLineVertical);
    Line firstLineHorizontal = new Line(0, 0, this.getWidth(), 0, this.vertexBufferObjectManager);
    firstLineHorizontal.setColor(borderColor);
    firstLineHorizontal.setLineWidth(borderWidth);
    this.gameFieldLines.add(firstLineHorizontal);
    this.attachChild(firstLineHorizontal);
    Line lastLineHorizontal =
        new Line(
            0,
            this.getModel().getHeight() * GameField.CELL_HEIGHT,
            this.getWidth(),
            this.getModel().getHeight() * GameField.CELL_HEIGHT,
            this.vertexBufferObjectManager);
    lastLineHorizontal.setColor(borderColor);
    lastLineHorizontal.setLineWidth(borderWidth);
    this.gameFieldLines.add(lastLineHorizontal);
    this.attachChild(lastLineHorizontal);
  }