Basically I created a class, and made a matrix out of that class and tried to give the property of that a class a certain name.
I've tried initializing it already but it still doesn't work
public class Tile
{
public string TileName { get; set; }
public int Status { get; set; }
}
public class ChessBoard
{
private const int BOARDHEIGHT = 8;
private const int BOARDWIDTH = 9;
public Tile[,] InitializeBoard()
{
Tile[,] newBord = new Tile[BOARDHEIGHT, BOARDWIDTH];
for (int x = 0; x < BOARDWIDTH; x++)
{
for (int y = 0; y < BOARDHEIGHT; y++)
{
newBord[x, y].TileName = x+"-"+y;
newBord[x, y].Status = 0;
}
}
return newBord;
}
public void DisplayBoard(Tile[,] Board)
{
for (int x = 0; x < BOARDWIDTH; x++)
{
for (int y = 0; y < BOARDHEIGHT; y++)
{
Console.WriteLine(Board[x,y].TileName);
}
Console.WriteLine();
}
}
}
static void Main(string[] args)
{
ChessBoard CB = new ChessBoard();
Tile[,] CBoard = CB.InitializeBoard();
CB.DisplayBoard(CBoard);
}
I wanted to try naming the Tile with its index, however I was only met with "System.NullReferenceException: Object reference not set to an instance of an object."