我正在创造一个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 :(得分: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();
}
}
答案 1 :(得分: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
}