2021-Output tiles in string

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Issue

Future improvements will need to get a list for the tiles within the HexGrid. However the tiles list is protected and therefore not accessible.

Solution

We can create a new method in HexGrid to return the tiles, this will be just as a string:

        public string GetTiles()
        {
            string temp = "";
            foreach (Tile t in tiles)
            {
                temp = temp + t.GetTerrain() + ";";
            }
            temp = temp.Substring(0, temp.Length - 1);
            return temp;
        }

The foreach loop will cycle through each tile, and add the terrain type to the temp string.

Adding ";" to the will mean the final string will have a ; at the end. The Substring will remove this final ;.