因此,我有一个char 2D指针动态数组,其中包含以下元素:
请忽略所有数字和***符号,仅关注X和空格以及'-','+','|'符号。
当用户从1到6中选择一个车道时,程序会将一个元素推到顶部,如图所示。如果最后一个元素是蓝色符号,则需要将其删除并继续推动数组中的其他元素,直到我能形成一条直线才能赢得比赛。
例如,如果蓝色符号“ +”位于arr 0中,则下次在该列中插入符号时,蓝色符号“ +”将被删除,并且数组将从底部添加另一个符号
到目前为止,这是我用于推送元素的代码:
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;
}
}
}
你们还知道如何将彩色字符插入图片中所示的数组吗?我尝试使用//boardOfGame[6][userChoice] = printf("\033[1;34m%c\033[0m\n",typeOfUserTile);
,但它只会在输出中打印一个新的颜色符号,而不是将其分配为我的2D数组的值。