I've been messing around with arrays as I'm learning them currently in my book and they gave the idea of a chess board using for loops alongside multidimensional arrays to give them individual values which you can therefore print out.
However, I thought of the old console RPG games from way back and wanted to simply add a border around the array so it prints any 0 || 19 value as an X. The code does work however, is there a way of making it more efficient by using if statements or by created a switch statement that reads the current loop variable and change that array value to a 1 for fill or leave it 0 to blank the "tile".
#include <iostream>
using namespace std;
int main()
{
int rpgLevelGrid[20][20];
//Co-od decleration
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
switch (i)
{
case 0: case 19:
rpgLevelGrid[i][j] = 1;
break;
default:
rpgLevelGrid[i][j] = 0;
break;
}
switch (j)
{
case 0:
rpgLevelGrid[i][j] = 1;
break;
case 19:
rpgLevelGrid[i][j] = 1;
break;
}
}
}
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
switch (rpgLevelGrid[i][j])
{
case 1:
cout << "X";
break;
default:
cout << "-";
}
}
cout << endl;
}
}