我在C#编写一个tic tac toe游戏 无论如何,我继续得到第57行的解析错误,但是我没有第57行。 这是代码?有谁可以帮助我?
我使用mcs作为我的编译器,这是警告。
game.cs(57,1): error CS8025: Parsing error Compilation failed: 1 error(s), 0 warnings
这是代码。 托管在pastebin上 http://pastebin.com/ft1FkDqU
谁能告诉我如何解决这个问题? 感谢帮助! 另外,如果您发现任何其他问题,请告诉我?
答案 0 :(得分:8)
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";
答案 1 :(得分:0)
我认为你缺少if语句的大括号:
if(move == 0){board [0,0] =“x”; \ clsoing bracket here}
P.s最好不要以任何方式使用起始大括号 语法:
if(boolean)statement;
或
if(boolean)
语句;
无论如何是有效的..
通过此更改,它应该编译并运行
答案 2 :(得分:0)
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
}
}
这应该现在可以工作,虽然你需要进行验证检查等... P.S更好地使用bool而不是数组中的字符串和bool for while条件