简体   繁体   English

Xcode中的预期表达错误

[英]Expected Expression Error in Xcode

I am making a move function for a game and I get a expected expression error I can't figure out why, it seems legal what i did. 我正在为游戏制作移动功能,但出现了预期的表达错误,我不知道为什么,我所做的事情似乎合法。

void Ant::move()
{
int dir=rand()%4;

if (dir==0)
{
    if ((y>0) && (world->getAt(x,y-1)==NULL))
    {
        world->setAt(x,y-1,world->getAt(x,y));
        world->setAt(x,y,NULL);
        y++;
    }
}
else
{
    if ((x<WORLDSIZE-1) && (world->getAt(x+1,y)==NULL))
    {
        world->setAt(x-1,y,world->getAt(x,y));
        world->setAt(x,y,NULL);
        x--;
    }
}
else
{
    if ((x<WORLDSIZE-1) && (world-getAt(x+1,y)==NULL))
    {
        world->setAt(x+1,y,world->getAt(x,y));
        world->setAt(x,y,NULL);
        x++;
    }
}
}

The problem is the second else call. 问题是第二个else调用。

I think the problem is: 我认为问题是:

world-getAt(x+1,y)==NULL

You forgot the > 您忘记了>

world->getAt(x+1,y)==NULL

In the second if statement. 在第二个if语句中。

There is an if missing after the first else. 有一个if第一个else后失踪。 You have now 你现在有

if {
    ...
} else { // here you need an if - or revise the structure

} else {

}

For instance try ... 例如尝试...

void Ant::move()
{
    int dir=rand()%4;

    if (dir==0)
    {
        if ((y>0) && (world->getAt(x,y-1)==NULL))
        {
            world->setAt(x,y-1,world->getAt(x,y));
            world->setAt(x,y,NULL);
            y++;
        } else
        if ((x<WORLDSIZE-1) && (world->getAt(x+1,y)==NULL))
        {
            world->setAt(x-1,y,world->getAt(x,y));
            world->setAt(x,y,NULL);
            x--;
        } else
        if ((x<WORLDSIZE-1) && (world-getAt(x+1,y)==NULL))
        {
            world->setAt(x+1,y,world->getAt(x,y));
            world->setAt(x,y,NULL);
            x++;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM