几个星期前我开始编码,现在正在尝试检查游戏。我创建了一个名为“figure”的类,然后是一个数组(图图[value])。 我在main.cpp中创建了一个2D字段数组,并用每个Figure []的数字填充它。 E.G:
(main.cpp)
figure Figure[33]; //Figure-array
for (int i = 0; i < 33; i++)
{
Figure[i].id = i;
}
int field[7][7] = { // (I messed the ID's up a little, just ignore it
{0, 0, 1, 2, 3, 0, 0},
{0, 0, 4, 5, 6, 0, 0},
{7, 8, 9, 10, 11, 12, 13}
{14, 15, 16, 17, 18, 19, 20},
{21, 22, 23, 24, 25, 26, 27},
{0, 0, 28, 29, 30, 0, 0},
{0, 0, 31, 32, 33, 0, 0}
};
for (int y = 0; y < 7; y++) //Field gets filled with figure-values {
for (int x = 0; x < 7; x++)
{
if (field[y][x] != 0)
{
Figure[field[y][x] - 1].setPosition(Vector2i(x + 1, y + 1));
}
}
}
现在我想制作一个更新功能,让它们互相跳过等等。我的问题是我不知道如何正确地做到这一点,我不知道如何完全写这个功能。这就是我所拥有的已:
(Updatefunction)
void figure::update(int (&field)[7][7], RenderWindow &window) {
Vector2i mouseCoords;
mouseCoords.x = int(Mouse::getPosition(window).x / 114);
mouseCoords.y = int(Mouse::getPosition(window).y / 85);
if ((field[mouseCoords.y][mouseCoords.x] != 0) && (Mouse::isButtonPressed(Mouse::Left)))
{
if ((field[mouseCoords.y][mouseCoords.x] != 0) && !(Mouse::isButtonPressed(Mouse::Left)))
{
selected = true; //selected defined in figure.h
}
}
Vector2i newMouseCoords;
newMouseCoords.x = int(Mouse::getPosition(window).x / 114);
newMouseCoords.y = int(Mouse::getPosition(window).y / 85);
if (selected = true)
{
if ((newMouseCoords.x == mouseCoords.x + 2) && (field[newMouseCoords.y][newMouseCoords.x + 2] != 0))
{
}
}
}
我不知道如何继续在这里,非常感谢提示!
答案 0 :(得分:2)
您尚未提供所有代码,因此我无法为您提供准确的解决方案(并且您的完整列表可能会太长,并且如果您将其包含在内,则会使问题无法读取,因此我不建议您)。
鉴于您现有的代码如下所示,我将如何解决它:
null
- 取决于您如何定义该变量)。