2014-01-15 36 views
0

我正在創建一個tic tac toe遊戲,並且對於再次播放部分,我獲得了其他術語的invaild表達式,任何人都可以幫忙嗎?它的工作之前,我提前無效的術語表達式其他

static void playAgainMsg(String message) 
    { 
     Console.WriteLine(message + "Do you want to play again? Y/N"); // Displaying the resukt of the game and asking the user if they would like to play again and tells them to input Y or N 
     if 
     { 
      (Console.ReadLine().Equals("Y")) // This reads the line to check the user input 
      strPlaysAgain.Equals("Y"); 
      introduction(); <---- worked before this was added... 
     } 
     else 
     { 
      strPlaysAgain.Equals("N"); // This Changes the value from the default value of Y to N so that it exits the While loop for PlaysAgain. 
      Console.Clear(); //Clears the console so that the game board is removed. 
      MainMenu(); // returns the user back to the introduction - edit to be main menu with an exit feature, highscores 
     } 
    } 

回答

0

添加引入方法 感謝您錯位的情況

 if (Console.ReadLine().Equals("Y")) //<------------ 
     { 
      // This reads the line to check the user input 
      strPlaysAgain.Equals("Y"); 
      introduction(); 
     } 
     else 
     { 
      strPlaysAgain.Equals("N"); // This Changes the value from the default value of Y to N so that it exits the While loop for PlaysAgain. 
      Console.Clear(); //Clears the console so that the game board is removed. 
      MainMenu(); // returns the user back to the introduction - edit to be main menu with an exit feature, highscores 
     } 
2

你不測試與if什麼。另外,str1.Equals(str2)是一個測試。您必須使用=來分配一個值。

static void playAgainMsg(String message) 
     { 
      Console.WriteLine(message + "Do you want to play again? Y/N"); 
      if (Console.ReadLine().Equals("Y")) 
      { 
       strPlaysAgain = "Y"; 
       introduction(); 
      } 
      else 
      { 
       strPlaysAgain = "N"; 
       Console.Clear(); removed. 
       MainMenu(); 
      } 
     }