使用二维阵列在地图/栅格上显示坐标
Using a 2d array to display coordinates on a Map/Grid
我正试图在地图/网格上放置裁剪。裁剪是需要在地图边界中显示的字符串。我需要使用一个2d数组来显示将在地图上形成裁剪形状的各个字符。这是我到目前为止的代码,但当它们显示时,它并没有给我正确的裁剪形状。
bool Crop::place(char map[MAPL][MAPW],int x_crop,int y_crop)const{
cout << 'n';
cout << setw(24) << right << "11111111112n";
cout << setw(24) << right << "12345678901234567890n";
cout << " " << setw(21) << setfill('-') << left << '+' << right << '+' << setfill (' ') << endl;
for(int x=0; x < MAPW;x++){
cout << setw(2) << right << x+1 << "|";
for(int y=0; y < MAPL;y++){
cout << map[x][y];
}
cout << "|" << endl;
}
cout << " " << setw(21) << setfill('-') << left << '+' << right << '+' << setfill (' ') << endl;
cout << setw(24) << right << "11111111112n";
cout << setw(24) << right << "12345678901234567890n";
return true;
}
下面是输出应该是什么样子的示例。它有两个作物,"c"answers"p"在地图上,是20宽乘10高的
11111111112
12345678901234567890
+--------------------+
1| |
2| |
3| cc |
4| cc |
5| cc |
6| cc |
7| pppppppp |
8| pppppppp |
9| pppppppp |
10| |
+--------------------+
11111111112
12345678901234567890
看起来是一个横向错误。循环中:
for(int x=0; x < MAPW;x++){
cout << setw(2) << right << x+1 << "|";
for(int y=0; y < MAPL;y++){
cout << map[x][y];
}
cout << "|" << endl;
}
您每次打印一列,而不是一次打印一行(列的主要顺序),所以它是横向打印字段。如果切换MAPW和MAPL(并切换x和y以使变量描述此更改),则执行
for(int y=0; y < MAPL;y++){
cout << setw(2) << right << y+1 << "|";
for(int x=0; x < MAPW;x++){
cout << map[y][x];
}
cout << "|" << endl;
}
您将一次打印一行(行主要顺序),并打印出字段中的每个空格。
相关文章:
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- 为什么不;名字在地图上是按顺序排列的吗
- 基于多个条件处理地图中的所有元素
- 在C++中将矢量转换为嵌套地图
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- 替换基于地图的所有引用
- 如何区分地图中的 0 和 false?
- 地图计数确实很重要,或者只是检查是否存在
- 如何从地图中删除矢量对象
- 是否有任何C++功能可以对地图进行排序?
- 如何使用 std::variant 打印地图键/值?
- 从矢量或地图中删除共享指针
- 在 c++ 中,有一种方法可以创建一个包含地图作为值的树状地图?
- 无限嵌套具有变体的地图
- C++一会儿循环读到地图上 2 行?
- Opengl 屏幕到地图坐标转换
- QML地图:点击屏幕时获取坐标
- C++最好的文件格式存储大量地图坐标
- 使用二维阵列在地图/栅格上显示坐标