我正在编程Checkers并遇到一个问题,我的跳棋不会移动。我正在使用Java Applet。它记录了我点击的事实,但它没有移动检查器本身。
这是我的MouseClicked,我认为这就是我遇到问题的地方:
public void mouseClicked(MouseEvent e) {
mouseX=e.getX();
mouseY=e.getY();
col = (mouseX-115)/100;
row = (mouseY-115)/100;
if(board[row][col].getPlayer()==player)
{ oldCol = col;
oldRow = row;
if(board[row][col].getPlayer()==0)
{
if(board[oldRow][oldCol].getPlayer()==1 && board[oldRow][oldCol].getKing()==false)
{
if(row==oldRow-1)
{
if(col==oldCol-1 || col==oldCol+1)
{
board[oldRow][oldCol].setPlayer(0);
board[row][col].setPlayer(1);
board[row][col].setKing(false);
}
}
}
else if(board[oldRow][oldCol].getPlayer()==1 && board[oldRow][oldCol].getKing()==true)
{
if(row==oldRow-1 || row==oldRow+1)
{
if(col==oldCol-1 || col==oldCol+1)
{
board[oldRow][oldCol].setPlayer(0);
board[row][col].setPlayer(1);
board[row][col].setKing(true);
}
}
}
else if(board[oldRow][oldCol].getPlayer()==2 && board[oldRow][oldCol].getKing()==true)
{
if(row==oldRow-1 || row==oldRow+1)
{
if(col==oldCol-1 || col==oldCol+1)
{
board[oldRow][oldCol].setPlayer(0);
board[row][col].setPlayer(2);
board[row][col].setKing(true);
}
}
}
else if(board[oldRow][oldCol].getPlayer()==2 && board[oldRow][oldCol].getKing()==false)
{
if(row==oldRow+1)
{
if(col==oldCol-1 || col==oldCol+1)
{
board[oldRow][oldCol].setPlayer(0);
board[row][col].setPlayer(2);
board[row][col].setKing(false);
}
}
}
}
}
repaint();
}