问题描述
我已经被困了几个小时试图制作一个类似于战舰中的网格,一侧有字母,另一侧有数字,但我无法让它工作,当我在所有字母之间循环时想要它只是坚持某个集合(即第一次从 a 到 j,但下次它从 k 到 t),当我只想要 1 到 10 时,数字会继续循环。
谢谢!
#include <iostream>
#include <string>
bool gameend = true;
char cUserInput;
class boat
{
int length;
int x1,x2,y1,y2;
int health;
};
int iXPlayerPos = 2;
int iYPlayerPos = 2;
int iXShipPos = 2;
int iYShipPos = 2;
int iXCoffeePotPos = 3;
int iYCoffeePotPos = 7;
// Room Bounds (square room in positive quadrant)
int iKitchenWallMax = 10; // max length of our walls,reused from older grid code
char cSpace = ' ';
char cPlayer = 'p';
char cShip = 'O';
int cHorizontalWall = 1;
char cVerticalWall = 'a';
int a[10][10];
int main()
{
std::cout << "Where do you want the ship to go?";
std::cin >> iXShipPos >> iYShipPos;
movement:
for (int iTop = 0; iTop <= iKitchenWallMax + 10; iTop++)
{
std::cout << cHorizontalWall,cHorizontalWalL++;
if (cHorizontalWall > 10 ) {
cHorizontalWall = 0;
// trying to only show numbers 1 to 10,for the 10 rows
}
}
std::cout << std::endl;
for (int cols = 0; cols < iKitchenWallMax; cols++)
{
std::cout << cVerticalWall; // put letters a to j here
for (int rows = 0; rows < iKitchenWallMax; rows++)
{
std::cout << " " << a[rows][cols];
if (cols == iYPlayerPos && rows == iXPlayerPos)
{
std::cout << cPlayer;
}
else if (cols == iXShipPos && rows == iYShipPos)
{
std::cout << cShip;
}
}
std::cout << std::endl;;
}
for (int iBottom = 0; iBottom <= iKitchenWallMax + 10; iBottom++)
{
std::cout << cHorizontalWall;
}
std::cout << std::endl;
// USER INPUT
char cInput = 'z';
for (; cInput != 'y' && cInput != 'n' && cInput != 'w' && cInput != 'a' && cInput != 's' && cInput != 'd'; (std::cin >> cInput))
{
std::cout << "Please enter 'y' or 'n' and hit return to proceed" << std::endl;
}
cUserInput = cInput;
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)