private void CalculateAvailablePathBackward(int x, int y, Hex[] way, int currentDistance, int indexStartDirection, int indexEndDirection, int pointsMove) { if (hexMap[x][y].isMove == false) { return; } //calculate distance to move there //calculate forward rotates int rotates = System.Math.Abs(indexEndDirection - indexStartDirection); if (rotates > 3) { rotates = 6 - rotates; } //calculate forward move int distance = GameLogicSettings.tankBackwardMovePoint + rotates * GameLogicSettings.tankRotateMovePoint; //calculate start back index if (currentDistance + distance > pointsMove) { return; } HexPathData cellData = hexPathData[x][y]; if (cellData.distance != -1 && cellData.distance < currentDistance + distance) { return; } Hex[] newWay = new Hex[way.Length + 1]; System.Array.Copy(way, newWay, way.Length); newWay[newWay.Length - 1] = hexMap[x][y]; if (cellData.distance == currentDistance + distance) { cellData.reservePath = newWay; } else { cellData.mainPath = newWay; } cellData.distance = currentDistance + distance; Hex[] neighbors = hexMap[x][y].neighbors; for (int i = 0; i < 6; i++) { if (neighbors[i] != null) { CalculateAvailablePathBackward(neighbors[i].X, neighbors[i].Y, cellData.mainPath, cellData.distance, indexEndDirection, i, pointsMove); } } }
public void FindAvailablePathBackward(int x, int y, int indexStartDirection, int pointsMove) { if (pointsMove == 0) { return; } HexPathData hexData = hexPathData[x][y]; hexData.mainPath = new Hex[] { hexMap[x][y] }; hexData.distance = 0; Hex[] neighbors = hexMap[x][y].neighbors; //Hex[] neighborsL2 = hexMap[x][y].neighborsL2; for (int i = 0; i < 6; i++) { if (neighbors[i] != null) { CalculateAvailablePathBackward(neighbors[i].X, neighbors[i].Y, hexData.mainPath, hexData.distance, indexStartDirection, i, pointsMove); } } }
private void GenerateHexPathData() { hexPathData = new HexPathData[widthMap][]; for (int i = 0; i < hexPathData.Length; i++) { if (i % 2 != 0) { hexPathData[i] = new HexPathData[heightMap - 1]; } else { hexPathData[i] = new HexPathData[heightMap]; } } for (int i = 0; i < hexPathData.Length; i++) { for (int j = 0; j < hexPathData[i].Length; j++) { hexPathData[i][j] = new HexPathData(); } } }