2016-12-03 39 views
1

关于此代码:方法名称预期错误 - C#

我正在为TIC TAC TOE游戏制作Windows窗体应用程序。这是其中的一种方法。它对角地,水平地,垂直地检查赢家。

错误:

在& &语句的右手边,我得到一个错误说“有望方法名称”。我无法弄清楚这个错误。我希望有人能帮忙。

 private void checkForwinner() 
     { 
     bool there_is_a_winner= false; 

     //horizontal check 
     if((A1.Text==A2.Text)&& (A2.Text==A3.Text)(!A1.Enabled)) 
     there_is_a_winner=true; 

     else if((B1.Text==B2.Text)&& (B2.Text==B3.Text)(!A2.Enabled)) 
     there_is_a_winner=true; 

     else if ((C1.Text == C2.Text) && (C2.Text == C3.Text)(!A3.Enabled)) 
      there_is_a_winner = true; 

     //Vertical Check 
     else if ((A1.Text == B1.Text) && (B1.Text == C1.Text)(!A1.Enabled)) 
      there_is_a_winner = true; 

     else if ((A2.Text == B2.Text) && (B2.Text == C2.Text)(!B1.Enabled)) 
      there_is_a_winner = true; 

     else if ((A3.Text == B3.Text) && (B3.Text == C3.Text)(!C1.Enabled)) 
      there_is_a_winner = true; 

     //Diagonal Check 
     else if ((A1.Text == B2.Text) && (B2.Text == C3.Text)(!A1.Enabled)) 
      there_is_a_winner = true; 

     else if ((A3.Text == B2.Text) && (B2.Text == C1.Text)(!C1.Enabled)) 
      there_is_a_winner = true; 
     } 
+0

'(A2.Text == A3.Text)(!A1.Enabled)'是什么意思?那是你的问题。 –

回答

1

你缺少每& & if语句。

此外,请务必填写&&之前的空格。尝试让您的代码更易于阅读。

if((A1.Text==A2.Text) && (A2.Text==A3.Text)(!A1.Enabled)) 
     there_is_a_winner=true; 

使用

if((A1.Text==A2.Text) && (A2.Text==A3.Text) && (!A1.Enabled)) 
     there_is_a_winner=true; 

同样,做所有的if-else语句。

+0

哦..谢谢你的回答。 – YoMama

+0

@YoMama - 你也可以赞成答案。干杯,:) –