我想为我正在制作的 40x20 字符块制作动画cout
。我想清除控制台,system("cls");
然后立即出现下一个字符块。目前,下一个区块是打字机风格。
对我的问题最简单的答案就是一次拥有一个 20 行 x 40 个字符的 oss 流 cout,而不是打字机风格。
主要.cpp:
mazeCreator.cout();
Sleep(5000);
system("cls");
cout()
void MazeCreator::cout() {
char wallChar = (char) 219;
char pavedChar = (char) 176;
char lightChar = ' ';
char startChar = 'S';
char finishChar = 'F';
char errorChar = '!';
char removedWallChar = 'R';
char landmarkLocationChar = 'L';
ostringstream oss;
for (int row = 0; row < rows; row++) {
oss << " ";
for (int col = 0; col < columns; col++) {
if (mazeArray[row][col] == wall)
oss << wallChar;
else if (mazeArray[row][col] == paved)
oss << pavedChar;
else if (mazeArray[row][col] == light)
oss << lightChar;
else if (mazeArray[row][col] == start)
oss << startChar;
else if (mazeArray[row][col] == finish)
oss << finishChar;
else if (mazeArray[row][col] == removedWall)
oss << removedWallChar;
else if (mazeArray[row][col] == landmarkLocation)
oss << landmarkLocationChar;
else
oss << errorChar;
}
oss << "\n";
}
oss << "\n\n";
cout << oss.str();
}