c#解析错误,由于行不存在而无法找到
本文关键字:不存在 于行 错误 | 更新日期: 2023-09-27 18:01:54
我正在用c#编写一个井字游戏无论如何,我一直得到第57行解析错误,但是我没有第57行。这是代码吗?有人能帮我吗?
我使用MCS作为我的编译器,这里是警告。
<>之前game.cs(57,1):错误CS8025:解析错误编译失败:1个错误,0个警告之前,这是代码。托管于pastebinhttp://pastebin.com/ft1FkDqU
谁能告诉我如何解决这个问题?感谢帮助!另外,如果您看到其他问题,请告诉我。
if(move == 0){board[0, 0] = "x";
if(move == 1){board[0, 1] = "x";
if(move == 2){board[0, 2] = "x";
if(move == 3){board[1, 0] = "x";
if(move == 4){board[1, 1] = "x";
if(move == 5){board[1, 1] = "x";
if(move == 6){board[2, 0] = "x";
if(move == 7){board[2, 1] = "x";
if(move == 8){board[2, 2] = "x";
你有一个左大括号{所有这些行。
编辑:你可以用这一行删除所有IF:
board[ Math.Floor(i/3.0), (i%3) ] = "x";
我认为你缺少if语句的大括号:
if(move == 0){board[0,0] = "x";
p。最好不要有开始的大括号,因为语法:
if (boolean) statement;
或
如果(布尔)
声明;
无论如何都是有效的
修改后,它应该编译并运行
class Game
{ // declares the class
private static string[,] board = new string[3, 3]{
{" ", " ", " "}, // top row
{" ", " ", " "}, // middle row
{" ", " ", " "} // bottom row
};
private static void print()
{
System.Console.WriteLine("'n {0} | {1} | {2} ", board[2, 0], board[2, 1], board[2, 2]);
System.Console.WriteLine("------------");
System.Console.WriteLine(" {0} | {1} | {2} ", board[1, 0], board[1, 1], board[1, 2]);
System.Console.WriteLine("------------");
System.Console.WriteLine(" {0} | {1} | {2} 'n", board[0, 0], board[0, 1], board[0, 2]);
}
private static void calculateMoves()
{
System.Console.Write("The possible moves are: ");
int n = 1; // this is used to list all possible moves.
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (board[i, j] == " ")
{
System.Console.Write("{0} ", n);
}
n++;
}
} // end print possible moves.
System.Console.WriteLine(); // go to next line
}
static void Main()
{ // the main function, the program starts from (this is a method declartion)
System.Console.WriteLine("'nWelcome to theelitenoob's simple tic tac toe game!");
System.Console.WriteLine("Written in C#, released under the GPL.");
System.Console.WriteLine("The board is 3 by 3, Type a number to place a move there.");
System.Console.WriteLine("So 1 is bottom left and 9 is top right, like a standard keypad.'n");
int winner = 0; // there is no winner yet.
// write players piece
System.Console.WriteLine("You are x");
// create the board
int move;
print();
calculateMoves();
System.Console.Write("Please type in a move number: ");
while (winner == 0 && int.TryParse(Console.ReadLine() , out move) )
{
move--;
if (move == 0) board[0, 0] = "x";
if (move == 1) board[0, 1] = "x";
if (move == 2) board[0, 2] = "x";
if (move == 3) board[1, 0] = "x";
if (move == 4) board[1, 1] = "x";
if (move == 5) board[1, 1] = "x";
if (move == 6) board[2, 0] = "x";
if (move == 7) board[2, 1] = "x";
if (move == 8) board[2, 2] = "x";
print();
calculateMoves();
System.Console.Write("Please type in a move number: ");
/**/
} // end while loop
}
}
现在应该可以工作了,尽管你需要做验证检查等…注:最好在数组中使用bool而不是string,同时在while条件中也使用bool