示例#1
0
        public void DigTunnel(BoardGenerator boardGenerator, GridPosition startPosition, GridPosition tunnelGoal)
        {
            GridPosition currentDigPosition = startPosition;

            for (int i = 0; i < maxLengthPerTunnel; i++)
            {
                if (currentDigPosition.x < tunnelGoal.x)
                {
                    currentDigPosition.x++;
                }
                else if (currentDigPosition.x > tunnelGoal.x)
                {
                    currentDigPosition.x--;
                }
                else
                {
                    if (spawnRoomsAtTunnelEnds)
                    {
                        SpawnRoomTemplateAtTunnelEnd(boardGenerator, currentDigPosition);
                    }

                    break;
                }

                for (int j = 0; j < tunnelWidth; j++)
                {
                    boardGenerator.WriteToBoardGrid(currentDigPosition.x, currentDigPosition.y + j, GetCharToWriteForTunnel(boardGenerator), true, true);
                }
            }
            for (int k = 0; k < maxLengthPerTunnel; k++)
            {
                if (currentDigPosition.y < tunnelGoal.y)
                {
                    currentDigPosition.y++;
                }
                else if (currentDigPosition.y > tunnelGoal.y)
                {
                    currentDigPosition.y--;
                }
                else
                {
                    if (spawnRoomsAtTunnelEnds)
                    {
                        SpawnRoomTemplateAtTunnelEnd(boardGenerator, currentDigPosition);
                    }
                    break;
                }
                for (int s = 0; s < tunnelWidth; s++)
                {
                    boardGenerator.WriteToBoardGrid(currentDigPosition.x + s, currentDigPosition.y, GetCharToWriteForTunnel(boardGenerator), true, true);
                }
            }
        }