2016-12-03 72 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 - 你也可以贊成答案。乾杯,:) –