/// <summary>
    /// TODO: Saving in Unity via UI
    /// </summary>
    /// <param name="fileName"></param>
    public static void WriteDungeonFile(TileType[][] tiles, string fileName)
    {
        if (!TextDungeon.BuildTextDungeonFile(tiles))
        {
            Debug.LogError("Error: Building the dungeon file");
        }

        if (!TextDungeon.OutputToFile(Application.dataPath + "/Resources/Saves/", fileName, TextDungeon.OutputData))
        {
            Debug.LogError("Error: Outputting to file.");
        }
    }
    /// <summary>
    /// Set the enemies in avaiable rooms.
    /// </summary>
    private void SetEnemies()
    {
        bool result = TextDungeon.BuildTextDungeonFile(m_tiles);

        if (!result)
        {
            return;
        }

        var levelStr = TextDungeon.OutputData;

        // TODO: Optimise algorithm by cross referencing each room cell ID with the
        //          levelStr


        var rows    = 0;
        var columns = 0;
        var flag    = false;

        for (int i = 0; i < levelStr.Length; i++)
        {
            if (levelStr[i] == StringLiterals.NewLine)
            {
                flag = true;
                columns++;
            }

            if (!flag)
            {
                rows++;
            }
        }


        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                if (i < 0 || i >= columns)
                {
                    continue;
                }

                if (j < 0 || j >= rows)
                {
                    continue;
                }

                var idx = i * rows + j;

                if (levelStr[idx] != StringLiterals.Floor)
                {
                    continue;
                }



                int kk = 0;
                for (int _y = i - 1; _y <= i + 1; _y++)
                {
                    for (int _x = j - 1; _x <= j + 1; _x++)
                    {
                        if (_y < 0 || _y >= columns)
                        {
                            continue;
                        }

                        if (_x < 0 || _x >= rows)
                        {
                            continue;
                        }

                        var _idx = _y * rows + _x;

                        if (levelStr[_idx] != StringLiterals.Floor)
                        {
                            continue;
                        }

                        Debug.Log("ID - " + _x + ", " + _y + " is a floor");

                        kk++;
                    }
                }


                if (kk >= 8)
                {
                    m_tiles[i][j] |= TileType.Enemy;

                    var strBuilder = new System.Text.StringBuilder(levelStr);
                    strBuilder[idx] = StringLiterals.Enemy;
                    levelStr        = strBuilder.ToString();
                }
            }
        }


        /// for(int i = 0; i < columns; i++)
        /// {
        ///     for(int j = 0; j < rows; j++)
        ///     {
        ///         var idx = i * rows + j;
        ///         if(levelStr[idx] == StringLiterals.Enemy)
        ///         {
        ///
        ///         }
        ///     }
        /// }


        // foreach(var room in m_rooms)
        // {
        //     var enemyTileIDs = room.PossibleEnemyPositions(m_tiles);
        //     if(enemyTileIDs.Length < m_maxEnemiesPerRoom)
        //         m_maxEnemiesPerRoom = (uint)enemyTileIDs.Length;
        //
        //
        //     int fails = 0;
        //     for(int i = 0; i < m_maxEnemiesPerRoom; i++)
        //     {
        //         if(fails >= 100) break;
        //
        //         var rand = Random.Range(0, enemyTileIDs.Length);
        //         var id = enemyTileIDs[rand];
        //         var x = id % room.m_roomWidth;
        //         var y = id / room.m_roomHeight;
        //
        //         // if it already equals enemy
        //         if((m_tiles[x][y] & TileType.Enemy) == TileType.Enemy)
        //         {
        //             i--;
        //             fails++;
        //         }
        //         else
        //         {
        //             m_tiles[x][y] |= TileType.Enemy;
        //         }
        //     }
        //
        //
        //     // TODO: Add evil enemies to corridors.
        //     //          if a corridor is > 5 add to firth tile.
        //
        // }
    }