public void mousePressed(MouseEvent e){ //游戏结束时,不再能下 if (gameOver || paused) { return; } //游戏暂停时,不能下棋并弹出提示消息 if (isPaused) { JOptionPane.showMessageDialog(null, '当前处于暂停模式,请点击继续按钮继续游戏'); return; } //正常情况下可以下棋 int x = e.getX(); int y = e.getY(); int row = y / BLOCK_SIZE; int col = x / BLOCK_SIZE; if (row < ROWS && col < COLS && board[row][col] == 0) { board[row][col] = player; //更新棋盘 repaint(); //判断胜负 if (checkWin(player)) { gameOver = true; String msg = '恭喜玩家' + player + '获胜!'; JOptionPane.showMessageDialog(null, msg); } else if (checkDraw()) { gameOver = true; JOptionPane.showMessageDialog(null, '平局!'); } else { //轮换玩家 player = player == 1 ? 2 : 1; } } }


原文地址: https://www.cveoy.top/t/topic/oA5F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录