我想了解游戏是否已完成或绘制或仍然可以玩。但我想用动态代码来做。
例如,我对 3*3 tictactoe 游戏进行静态处理,如下所示:
private static boolean check_game_state(char[] board)
{
if ( (board[0]==cSymbol && board[1]==cSymbol && board[2]==cSymbol)
|| (board[3]==cSymbol && board[4]==cSymbol && board[5]==cSymbol)
|| (board[6]==cSymbol && board[7]==cSymbol && board[8]==cSymbol)
|| (board[0]==cSymbol && board[3]==cSymbol && board[6]==(cSymbol))
|| (board[1]==(cSymbol) && board[4]==(cSymbol) && board[7]==(cSymbol))
|| (board[2]==(cSymbol) && board[5]==(cSymbol) && board[8]==(cSymbol))
|| (board[0]==(cSymbol) && board[4]==(cSymbol) && board[8]==(cSymbol))
|| (board[2]==(cSymbol) && board[4]==(cSymbol) && board[6]==(cSymbol)))
{
if (cSymbol == 'X')
{
state = 5; //player 1 win
}
else if (cSymbol == 'O')
{
state = 4; player 2 win
}
}
}
我想为 4*4 或 5*5 或更高的板动态设置它。但是我该怎么做呢?是否可以?