private MouseListener playChessHandler=new MouseAdapter(){
public void mousePressed(MouseEvent e){
int x=e.getX();
int y=e.getY();
//******放一颗棋子
if(canplay=true){
if(x<=grids*space&&x>=0&&y<=grids*space&&y>=0){
if(chesses[round(x)][round(y)]==0){
chesses[round(x)][round(y)]=currColor;
//currColor=currColor==1?2:1; //切换棋子颜色
if(currColor==1){
currColor=2;
message="白棋先行"; //使上方提示信息随回合转变。
}
else{
currColor=1;
message="黑棋先行";
}
repaint();
}
else{
JOptionPane.showMessageDialog(null,"此处已有棋子,请重下!");
}
}//*****
/*
if(currColor ==chesses[round(x)][round(y) + i]){
count++;
i++;
}
i = 1;
if(currColor == chesses[round(x)][round(y) - i]){
count++;
i++;
}
if (count >= 5) {
flag = true;
}
if(flag==true){
JOptionPane.showMessageDialog(null,"游戏结束");
canplay=false;
} */
}
else{
JOptionPane.showMessageDialog(null,"游戏结束,大侠请重新来过!");
}
}
public void mouseClicked(MouseEvent e){
int x=e.getX();
int y=e.getY();
int count =1 ;
int i = 1 ;
if(currColor ==chesses[round(x)][round(y) + i]){
count++;
i++;
}
i = 1;
if(currColor == chesses[round(x)][round(y) - i]){
count++;
i++;
}
if (count >= 5) {
canplay = false;
}
if(canplay==false){
JOptionPane.showMessageDialog(null,"游戏结束");
}
}
};