private IList <Tile> BuildSquare(int sideLength, bool centerOrigin) { var square = new List <Tile>(); var increment = TileShape.Square.DoubleIncrement ? 2 : 1; var centerOffset = centerOrigin ? (((sideLength * increment) / 2) - 1) : 0; // Loop through rows x columns for (var rowIndex = 0; rowIndex < sideLength; rowIndex++) { var row = (rowIndex * increment) - centerOffset; for (var colIndex = 0; colIndex < sideLength; colIndex++) { var col = (colIndex * increment) - centerOffset; var cubicCoordinates = CubicCoordinates.FromOffset( new OffsetCoordinates(row: row, col: col) ); square.Add(new Tile( cubicCoordinates: cubicCoordinates, tileShape: TileShape.Square, terrain: Terrain.Water )); } } // return the square tiles return(square); }
private IList <Tile> BuildRectangle(int columnCount, int rowCount, TileShape tileShape) { var rectangle = new List <Tile>(); var increment = tileShape.DoubleIncrement ? 2 : 1; for (var rowIndex = 0; rowIndex < rowCount; rowIndex++) { var row = rowIndex * increment; for (var colIndex = 0; colIndex < columnCount; colIndex++) { var col = colIndex * increment; var cubicCoordinates = CubicCoordinates.FromOffset( new OffsetCoordinates(col: col, row: row) ); rectangle.Add(new Tile( cubicCoordinates: cubicCoordinates, tileShape: tileShape, terrain: Terrain.Water )); } } return(rectangle); }
private IList <Tile> BuildRegularHexagon(int sideLength, bool centerOrigin, TileShape tileShape = null) { var hexagon = new List <Tile>(); var increment = TileShape.Hexagon.DoubleIncrement ? 2 : 1; var maxLength = (2 * sideLength) - 1; var centerOffset = centerOrigin ? ((sideLength * increment) - 1) : 0; if (tileShape == null) { tileShape = TileShape.Hexagon; } // Build top portion of hexagon var rowLength = sideLength - 1; var rowIndex = -1; while (rowLength < (maxLength - 1)) { rowLength++; rowIndex++; var topRow = (rowIndex * increment) - centerOffset; var colOffset = Convert.ToInt32(Math.Floor((maxLength - rowLength) / 2.0)); // TODO: Fix bug where column offset produces fractional value for (var colIndex = 0; colIndex < rowLength; colIndex++) { var col = ((colIndex + colOffset) * increment) - centerOffset; hexagon.Add(new Tile( cubicCoordinates: CubicCoordinates.FromOffset( new OffsetCoordinates(row: topRow, col: col) ), tileShape: tileShape, terrain: Terrain.Water )); } } // Build middle row of hexagon rowIndex++; rowLength = maxLength; var middleRow = (rowIndex * increment) - centerOffset; for (var colIndex = 0; colIndex < rowLength; colIndex++) { var col = (colIndex * increment) - centerOffset; hexagon.Add(new Tile( cubicCoordinates: CubicCoordinates.FromOffset( new OffsetCoordinates(row: middleRow, col: col) ), tileShape: tileShape, terrain: Terrain.Water )); } // Build bottom portion of hexagon while (rowLength > sideLength) { rowLength--; rowIndex++; var bottomRow = (rowIndex * increment) - centerOffset; var colOffset = Convert.ToInt32(Math.Floor((maxLength - rowLength) / 2.0)); // TODO: Fix bug where column offset produces fractional value for (var colIndex = 0; colIndex < rowLength; colIndex++) { var col = ((colIndex + colOffset) * increment) - centerOffset; hexagon.Add(new Tile( cubicCoordinates: CubicCoordinates.FromOffset( new OffsetCoordinates(row: bottomRow, col: col) ), tileShape: tileShape, terrain: Terrain.Water )); } } // return the hexagon tiles return(hexagon); }
private IList <Tile> BuildRegularOctagon(int sideLength, bool centerOrigin) { var octagon = new List <Tile>(); var increment = TileShape.Octagon.DoubleIncrement ? 2 : 1; var maxLength = sideLength + 2 * (sideLength - 1); var centerOffset = centerOrigin ? (((maxLength * increment) / 2) - 1) : 0; // Build top portion of octagon var rowLength = sideLength - 2; var rowIndex = -1; while (rowLength < (maxLength - 2)) { rowLength += 2; rowIndex++; var row = (rowIndex * increment) - centerOffset; var colOffset = (maxLength - rowLength) / 2; for (var colIndex = 0; colIndex < rowLength; colIndex++) { var col = ((colIndex + colOffset) * increment) - centerOffset; octagon.Add(new Tile( cubicCoordinates: CubicCoordinates.FromOffset( new OffsetCoordinates(row: row, col: col) ), tileShape: TileShape.Octagon, terrain: Terrain.Water )); } } // Build middle portion of octagon rowIndex++; var middleRowCount = rowIndex + sideLength; int middleRowIndex; for (middleRowIndex = rowIndex; middleRowIndex < middleRowCount; middleRowIndex++) { rowLength = maxLength; var row = (middleRowIndex * increment) - centerOffset; for (var colIndex = 0; colIndex < rowLength; colIndex++) { var col = (colIndex * increment) - centerOffset; octagon.Add(new Tile( cubicCoordinates: CubicCoordinates.FromOffset( new OffsetCoordinates(row: row, col: col) ), tileShape: TileShape.Octagon, terrain: Terrain.Water )); } } rowIndex = middleRowIndex; // Build bottom portion of octagon rowIndex--; while (rowLength > sideLength) { rowLength -= 2; rowIndex++; var row = (rowIndex * increment) - centerOffset; var colOffset = (maxLength - rowLength) / 2; for (var colIndex = 0; colIndex < rowLength; colIndex++) { var col = ((colIndex + colOffset) * increment) - centerOffset; octagon.Add(new Tile( cubicCoordinates: CubicCoordinates.FromOffset( new OffsetCoordinates(row: row, col: col) ), tileShape: TileShape.Octagon, terrain: Terrain.Water )); } } // return the octagon tiles return(octagon); }