随机坐标中的 cout 向量 n 次

Cout Vector in Random Coordinates n times

本文关键字:向量 cout 坐标 随机      更新时间:2023-10-16

我正在尝试在随机坐标处循环 12 次向量。我在这里创建了我的矢量:

vector<Item> sV(MAXPILLS, pill);

目前它只打印出其中一个矢量。这是我的代码,用于矢量的随机坐标以及尝试打印出其中的 12 个坐标。如果你能帮忙,我会很感激的!

    void generatePowerPills(char gr[][SIZEX], Item pill){
    for (int i = 0; i < 12; i++)
    {
        gr[pill.y][pill.x] = pill.symbol;
    }
}
void initialiseRandomPillsCoordinates(vector<Item>& sV) {
    //pass the vector to the function to give each pill random coordinates
    Seed();
    for (size_t i(0); i < sV.size(); ++i)
    {
        sV.at(i).y = Random(SIZEY - 2);    //vertical coordinate in range [1..(SIZEY - 2)]
        sV.at(i).x = Random(SIZEX - 2);    //horizontal coordinate in range [1..(SIZEX - 2)]
    }
}

我只是发表评论,但遗憾的是我只能回答。无论如何,您在这里迭代:

 for (int i = 0; i < 12; i++)
{
    gr[pill.y][pill.x] = pill.symbol;
}

但是你在这个循环中在哪里使用"i"?似乎它会做同样的事情,12 次。除非里面有一些隐藏的功能,如果是这样,我感到羞耻。