[注意:代码可能不完全是c :)仍然需要帮助plsssss]
所以我有这个代码而且我正在尝试使用tic tac toe但是其中一个int不起作用,int x应该是已经过去的但是从游戏开始以来(当它是设置为0)即使它尚未激活,它也会自动更改为1.
int a1 = 0;
int a2 = 0;
int a3 = 0;
int b1 = 0;
int b2 = 0;
int b3 = 0;
int c1 = 0;
int c2 = 0;
int c3 = 0;
int x = 0;
while(true)
{
以下代码对于所有其他棋盘方块
重复完全相同if (c1 < 1)
{
if((SensorUS(IN_1)<LONG)&&(SensorUS(IN_1)>FAR))
{
BTCheck1(B1);
until(BluetoothStatus(B1)==NO_ERR);
RemoteResetMotorPosition(B1,OUT_C,true);
until(BluetoothStatus(B1)==NO_ERR);
MOTOR1(OUT_C,100);
c1 = 2;
x = x + 1;
Wait(1000);
}
}
然后这是计算机应该做的事情,但它只是忽略了它并且它正在播放,好像x =每个值
if (x = 1)
{
if (a1 = 0)
{
BTCheck1(B1);
until(BluetoothStatus(B1)==NO_ERR);
RemoteResetMotorPosition(B1,OUT_A,true);
until(BluetoothStatus(B1)==NO_ERR);
MOTOR1(OUT_A,100);
a1 = 1;
x = x + 1;
}
else if (b1 = 0)
{
BTCheck1(B1);
until(BluetoothStatus(B1)==NO_ERR);
RemoteResetMotorPosition(B1,OUT_B,true);
until(BluetoothStatus(B1)==NO_ERR);
MOTOR1(OUT_B,100);
b1 = 1;
x = x + 1;
}
else if (c2 = 0)
{
BTCheck2(B2);
until(BluetoothStatus(B2)==NO_ERR);
RemoteResetMotorPosition(B2,OUT_C,true);
until(BluetoothStatus(B2)==NO_ERR);
MOTOR2(OUT_C,100);
c2 = 1;
x = x + 1;
}
else if (a3 = 0)
{
OnFwd(OUT_A,100);
a3 = 1;
x = x + 1;
}
else if (c3 = 0)
{
OnFwd(OUT_C,100);
c3 = 1;
x = x + 1;
}
else if (a2 = 0)
{
BTCheck2(B2);
until(BluetoothStatus(B2)==NO_ERR);
RemoteResetMotorPosition(B2,OUT_A,true);
until(BluetoothStatus(B2)==NO_ERR);
MOTOR2(OUT_A,100);
a2 = 1;
x = x + 1;
}
else if (c1 = 0)
{
BTCheck1(B1);
until(BluetoothStatus(B1)==NO_ERR);
RemoteResetMotorPosition(B1,OUT_C,true);
until(BluetoothStatus(B1)==NO_ERR);
MOTOR1(OUT_C,100);
c1 = 1;
x = x + 1;
}
else if (b3 =0)
{
BTCheck2(B2);
until(BluetoothStatus(B2)==NO_ERR);
RemoteResetMotorPosition(B2,OUT_B,true);
until(BluetoothStatus(B2)==NO_ERR);
MOTOR2(OUT_B,100);
b3 = 1;
x = x + 1;
}
}
答案 0 :(得分:2)
您正在使用赋值运算符querySelector
,您应该使用等于运算符=
if(x = 1)
这就是你的x变为1
的地方