简单的地图绘制问题
Simple Map Plotting Issue
我已经编写了一个简单的地图绘图程序,但有一些我无法识别的错误。
- 该错误仅在 X 坐标为正时发生,当它是负值时可以。
- 为什么当我的范围只有 11 时打印最后一列点?
代码如下:
int xRange = 11;
int yRange = 11;
string _space = " ";
string _star = " * ";
for( int x = xRange; x > 0; x-- )
{
for( int y = 0; y < yRange; y++ )
{
int currentX = x - 6;
int currentY = y - 5;
//demo input
int testX = 2; //<----------ERROR for +ve int, correct for -ve
int testY = -4; //<-------- Y is working ok for +ve and -ve int
//Print x-axis
if( currentY == 0 )
{
if( currentX < 0 )
cout << currentX << " ";
else
cout << " " << currentX << " ";
}
//Print y-axis
if( currentX == 0 )
{
if( currentY < 0 )
cout << currentY << " ";
else
//0 printed in x axis already
if( currentY != 0 )
cout << " " << currentY << " ";
}
else if( currentY == testX and currentX == testY )
cout << _star;
else
cout << " . ";
}
//print new line every completed row print
cout << endl;
}
演示输入的输出 (x: 2, y: -4): (它在 3 处显示 x 这是错误的)
. . . . . 5 . . . . . .
. . . . . 4 . . . . . .
. . . . . 3 . . . . . .
. . . . . 2 . . . . . .
. . . . . 1 . . . . . .
-5 -4 -3 -2 -1 0 1 2 3 4 5
. . . . . -1 . . . . . .
. . . . . -2 . . . . . .
. . . . . -3 . . . . . .
. . . . . -4 . . * . . .
. . . . . -5 . . . . . .
演示输入的输出 (x: -2, y: 4):
. . . . . 5 . . . . . .
. . . * . 4 . . . . . .
. . . . . 3 . . . . . .
. . . . . 2 . . . . . .
. . . . . 1 . . . . . .
-5 -4 -3 -2 -1 0 1 2 3 4 5
. . . . . -1 . . . . . .
. . . . . -2 . . . . . .
. . . . . -3 . . . . . .
. . . . . -4 . . . . . .
. . . . . -5 . . . . . .
谁能帮助确定我的代码中的两个问题?谢谢。
if( currentY == testX and currentX == testY )
这看起来不对。你不应该比较X到X和Y与Y吗?
仔细一看,一切都更加奇怪了。外部循环生成行,但使用 x
索引它们。内部循环为每一行生成列,您可以使用 y
对其进行索引。对于哪个轴是X轴,哪个轴是Y轴,人们普遍存在混淆。
编辑:啊,我现在看到了问题。currentY == 0
时,打印轴的数字,并打印点。
问题是,当你打印 Y 轴时,你仍然打印一个点,所以 y 轴右侧的所有内容都移动了 1。 你应该在那里有另一个else
:
if( currentY == 0 )
{
....
}
else if (currentX == 0) // <--- add an else there
{
....
}
else if ...
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 绘制文本问题
- 我正在尝试创建一个 C++ 贪吃蛇游戏,但我似乎无法绘制第二个高度边框,我该如何解决这个问题?
- 在 Qt C++ 中在自定义项委托上绘制文本时的性能问题
- 绘制的 OpenGL 点消失,绘制调用和交换缓冲区问题
- 绘制非常大的 2D 图形时出现问题
- 对于循环重复绘制问题
- 绘制多边形网格时出现 Opengl 性能问题
- TMX问题,在正确位置绘制瓷砖(c++)
- 使用纹理,法线和索引列表从VBO绘制OpenGL对象的问题
- 简单的地图绘制问题
- 使用SpriteFont类绘制文本时出现问题
- 在 SDL 中,当我在屏幕上绘制菜单时,它会使游戏变慢并且无法正常工作,我该如何解决这个问题?
- 为什么我的非所有者绘制的列表框在添加字符串后会出现绘图问题
- opengl =中缓冲区数据的问题仅在我缓冲比需要更多的字节时绘制
- 在OpenGL中绘制线的问题
- Direct3d绘制2d精灵.扩展问题
- Q项目绘制问题