2021-Output tiles in string

From TRCCompSci - AQA Computer Science
Revision as of 10:24, 4 September 2020 by Admin (talk | contribs) (Created page with "=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 cr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 ;.