【发布时间】:2018-12-18 17:47:06
【问题描述】:
我正在尝试制作一个地牢爬行类游戏,并且我有这个代码来创建一个游戏板。我使用“F”作为终点,使用“P”作为播放器。
void Gameboard::CreateGameboard()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
GameGrid[i][j] = 'x';
}
}
cout << " 0 1 2 3 4 5 6 7 8 9 10" << endl;
cout << " +---------------------+" << endl;
for (int i = 0; i < 10; i++)
{
cout << " " << "|" << GameGrid[i][0];
for (int j = 0; j < 10; j++)
{
if (i == Spawn[0] && j == Spawn[0])
{
GameGrid[0][0] = 'P';
}
cout << " " << GameGrid[i][j];
}
cout << "|" << endl;
}
cout << " +---------------------+" << endl;
}
我面临的问题是。 'P' 被放置在板的前两个插槽中,不确定原因。以及如何通过玩家移动来更新棋盘?我有一个带有 x,y 位置变量的 Player 类,我的想法是根据它们的去向来向下/向上递增。每次移动后是否需要重新打印整个板子?
【问题讨论】:
-
你输出了两次
GameGrid[0][0],并且设置为'P'explicitly。
标签: c++ visual-c++ c++17