欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

java tic tac toe_请问我这个tic tac toe的游戏代码的问题在哪里

发布时间:2025/4/5 编程问答 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java tic tac toe_请问我这个tic tac toe的游戏代码的问题在哪里 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

Scanner in = new Scanner(System.in);

final int SIZE =3;

int[][] board = new int[SIZE][SIZE];

boolean gotResult = false;

int numofx = 0;

int numofo = 0;

// 读入矩阵

for(int i=0; i

{

for(int j=0; j

{

board[i][j] = in.nextInt();

}

}

// 检查行

if(!gotResult)

{

for(int i=0; i

{

numofx =0;

numofo =0;

for(int j=0; j

{

if(board[i][j] ==1)

{

numofx ++;

}

else

{

numofo ++;

}

}

if(numofx ==SIZE|| numofo ==SIZE)

{

gotResult = true;

break;

}

}

}

// 检查列

if(!gotResult)

{

for(int i=0; i

{

numofx =0;

numofo =0;

for(int j=0; j

{

if(board[j][i] ==1)

{

numofx ++;

}

else

{

numofo ++;

}

}

if(numofx == SIZE|| numofo ==SIZE)

{

gotResult = true;

break;

}

}

}

//检查对角线

if(!gotResult)

{

numofo =0;

numofx =0;

for(int i=0; i

{

if(board[i][i] ==1)

{

numofx ++;

}

else

{

numofo ++;

}

}

if(numofx ==SIZE|| numofo ==SIZE)

{

gotResult = true;

}

}

// 检查反对角线

if(!gotResult)

{

numofx =0;

numofo =0;

for(int i=0; i

{

if(board[i][SIZE-i-1] ==1)

{

numofx ++;

}

else

{

numofo ++;

}

}

if(numofx ==SIZE|| numofo ==SIZE)

{

gotResult = true;

}

}

if(gotResult)

{

if(numofx == SIZE)

{

System.out.println(1+"赢了");

}

else

{

System.out.println(0+"赢了");

}

}

总结

以上是生活随笔为你收集整理的java tic tac toe_请问我这个tic tac toe的游戏代码的问题在哪里的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。