由于某些奇怪的原因,没有满足else if条件来宣布获胜者。我调试并跟踪了该条件的值,它为 3 个变量保存了值 2,但不会触发满足条件的NSLog 。我错过了明显的血腥还是真的很累(是的......我很累)?花了几个小时试图弄清楚这一点。满足X条件并执行它的NSLog语句......但对于我的生活...... O 没有。
我试过 { } 我没试过 { }。我已经尝试了几乎所有东西......等等。
我只尝试了 O 值的条件,但它不起作用。嗯。它不喜欢那个该死的2!呵呵。
-(void)chkWinner
{
NSLog(@"At the top of Check Winner method, player %d %d %d ", tl_Int, tm_Int, tr_Int);
if(tl_Int & tm_Int & tr_Int == 1)
{
NSLog(@" X is the WINNER %d %d %d", tl_Int, tm_Int, tr_Int);
}
else if(tl_Int & tm_Int & tr_Int == 2)
{
NSLog(@" O is the WINNER %d %d %d", tl_Int, tm_Int, tr_Int);
}
else
{
NSLog(@"In Check Winner method, player %d %d %d ", tl_Int, tm_Int, tr_Int);
}
}
这是正在按下的按钮的代码。它将值传递给方法......我只是不知道为什么它适用于一个值而不适用于另一个值。
-(IBAction) topLeftBtn:(id) sender
{
if(playerX.enabled == true)
{
tl_Int = 1;
NSLog(@" X %d ", tl_Int);
[tlBtn setImage:[UIImage imageNamed:@"X.png"] forState:UIControlStateNormal];
playerX.enabled = false;
tlBtn.enabled = false;
blockingBtn.enabled = true;
blockingBtn.hidden = false;
topLSquare.image = [UIImage imageNamed:nil];
SEL methodSelector1 = @selector(chkWinner);
[NSTimer scheduledTimerWithTimeInterval:0 target:self selector:methodSelector1 userInfo:nil repeats:NO];
}
if(playerO.enabled == true)
{
tl_Int = 2;
NSLog(@"TL O %d ", tl_Int);
[tlBtn setImage:[UIImage imageNamed:@"O.png"] forState:UIControlStateNormal];
playerO.enabled = false;
tlBtn.enabled = false;
blockingBtn.enabled = true;
blockingBtn.hidden = false;
topLSquare.image = [UIImage imageNamed:nil];
SEL methodSelector1 = @selector(chkWinner);
[NSTimer scheduledTimerWithTimeInterval:0 target:self selector:methodSelector1 userInfo:nil repeats:NO];
}
}
这里甚至是输出窗口:
2013-07-25 00:43:08.167 [16079:c07] TR O 2
2013-07-25 00:43:08.170 [16079:c07] At the top of Check Winner method, player 0 0 2
2013-07-25 00:43:08.172 [16079:c07] In Check Winner method, player 0 0 2
2013-07-25 00:43:10.934 [16079:c07] TM O 2
2013-07-25 00:43:10.938 [16079:c07] At the top of Check Winner method, player 0 2 2
2013-07-25 00:43:10.939 [16079:c07] In Check Winner method, player 0 2 2
2013-07-25 00:43:14.444 [16079:c07] TL O 2
2013-07-25 00:43:14.447 [16079:c07] At the top of Check Winner method, player 2 2 2
2013-07-25 00:43:14.449 [16079:c07] In Check Winner method, player 2 2 2
值在那里,但没有 NSLog 输出表明条件已满足...发出断点并进入调试,进入代码并在满足条件时直接遍历 NSLog。帮助...