我使用秋千和Jpanel制作了井字游戏。我得到它来检查赢家。既然我已经有了赢家,我不希望用户能够继续在游戏中放下更多的棋子(即使还有棋子的空间)。
这里有最后的代码,其中_board表示3 x 3板:
if (_board.testcrossDownwards() || _board.testcrossUpwards() || _board.testTopRow() || _board.testMiddleRow() || _board.testBottomRow() ||
_board.testLeftColumn() || _board.testMiddleColumn() || _board.testRightColumn()) {
_message.setText(player_name + " wins!");
} else if (_board.isTicTacRunThru()) {
_message.setText("It's a DRAW!");
} else {
_message.setText("You clicked on " + s.getCoordString() +". " + next_player_name + " to play.");
}
我假设我需要添加的片段将遵循player_name +“ wins!”线。
似乎您需要禁用JPanel,请检查此帖子: