So I have one char 2D pointer dynamic array which contains my elements like this:
Please ignore all the number and *** symbol and just focus on the X and space and '-', '+', '|' symbol.
When the user chooses one lane from 1 to 6, the program will push one element to the top as shown in the picture. If the last element is a blue symbol, I will need to remove it and keep pushing other elements in the array until I can form a straight line to win the game.
For example, if blue symbol '+' is in arr0 then the next time a symbol is inserted in the column, the blue symbol '+' will be removed and array will add another symbol from the bottom.
Here is my code so far for pushing the elements:
int countElement = 6;
char tempElement;
for (int i = 0; i < *sizeOfBoardGame; i++)
{
if (!isspace(boardOfGame[i][userChoice]))
{
countElement--;
}
}
if (typeOfUserTile == '+' || typeOfUserTile == '-' || typeOfUserTile == '|')
{
if (boardOfGame[userChoice][6] == 'X')
{
cout << "A locked tile is preventing your tile from being added. Try to be more careful next turn." << endl;
}
if (boardOfGame[6][userChoice] == ' ')
{
//boardOfGame[6][userChoice] = printf("\033[1;34m%c\033[0m\n",typeOfUserTile);
boardOfGame[6][userChoice] = typeOfUserTile;
}
else if (boardOfGame[6][userChoice] == '+' || boardOfGame[6][userChoice] == '-' || boardOfGame[6][userChoice] == '|')
{
for (int i = 6; i > countElement; i--)
{
boardOfGame[i-1][userChoice] = boardOfGame[i][userChoice];
boardOfGame[6][userChoice] = typeOfUserTile;
}
}
}
Do you guys also know how to insert a color char to the array like shown in the picture? I tried to use the //boardOfGame[6][userChoice] = printf("\033[1;34m%c\033[0m\n",typeOfUserTile);
but it only print a new color symbol to the output instead of assigning it to be the value of my 2D array.