Example – game map

Another example of the application of a two-dimensional array is a program that presents a map of a game. The map is a rectangle with 11 rows and 10 columns. Each element of the array specifies a type of terrain as grass, sand, water, or wall. Each place on the map should be shown in a particular color (such as green for grass), as well as using a custom character that depicts the terrain type (such as for water), as shown in the screenshot:

At the start, let's declare the enumeration value, named TerrainEnum, with four constants, namely GRASS, SAND, WATER, and WALL, as follows:

public enum TerrainEnum { GRASS, SAND, WATER, ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.