微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我将如何设置一个网格系统来显示每行/列是什么?

如何解决我将如何设置一个网格系统来显示每行/列是什么?

我已经被困了几个小时试图制作一个类似于战舰中的网格,一侧有字母,另一侧有数字,但我无法让它工作,当我在所有字母之间循环时想要它只是坚持某个集合(即第一次从 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 举报,一经查实,本站将立刻删除。