You're declaring a 5 x 7 array, but then trying to access (for example) Cave[7,5]
because your variables are backwards.
char[,] Cave = new char[GridHeight, GridWidth]; // declare 5x7 array
for (int i = 0; i < GridWidth; i++) // range of i is 0 - 6
{
for (int j = 0; j < GridHeight; j++) // range of j is 0 - 4
{
Cave[i, j] = '*'; //Error Here // try to access Cave[6,4] - oops!
}
}
Try swapping them:
char[,] Cave = new char[GridWidth, GridHeight];
Or swap the other pair if it makes more sense to you:
char[,] Cave = new char[GridHeight, GridWidth];
for (int i = 0; i < GridHeight; i++)
{
for (int j = 0; j < GridWidth; j++)
{
Cave[i, j] = '*';
}
}