有点非常规的问题,但我想知道是否有人对将计时器实现为四人连线游戏(2个玩家)的方式有任何想法。我目前有常规游戏的正常运行代码,但想添加一种方法,使用户有5秒钟的时间进行移动,否则计算机将为他们随机移动。是否有人对如何实现这一目标有任何想法?这是我处理转弯决策的主要功能。
public void handleAction (int x, int y)
{
if (gameOver)
{
JOptionPane.showMessageDialog (this, "Please Select Game...New to start a new game",
"Game Over", JOptionPane.WARNING_MESSAGE);
return;
}
int column = (x - BORDER_SIZE) / SQUARE_SIZE + 1;
int row = findNextRow (board, column);
if (row <= 0)
{
JOptionPane.showMessageDialog (this, "Please Select another Column",
"Column is Full", JOptionPane.WARNING_MESSAGE);
return;
}
animatePiece (currentPlayer, column, row);
board [row] [column] = currentPlayer;
int winner = checkForWinner (board, row, column);
if (winner == BANANA)
{
gameOver = true;
repaint ();
backgroundMusic.stop();
winBanana.play();
JOptionPane.showMessageDialog (this, "Banana Wins!!!",
"GAME OVER", JOptionPane.INFORMATION_MESSAGE);
}
else if (winner == STRAWBERRY)
{
gameOver = true;
repaint ();
backgroundMusic.stop();
winStrawberry.play();
JOptionPane.showMessageDialog (this, "Strawberry Wins!!!",
"GAME OVER", JOptionPane.INFORMATION_MESSAGE);
}
else {
currentPlayer *= -1;
if (currentPlayer == 1)
addStrawberry.play();
else
addBanana.play();
}
currentColumn = 3;
repaint ();
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。