java新人求助,五子棋胜利判定无效。

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,"游戏结束");
        }
    }
};
 public void mouseClicked(MouseEvent e){     
        int x=e.getX();
        int y=e.getY();
        int count =1 ;//count是这里定义的1
        int i = 1 ; 

        if(currColor ==chesses[round(x)][round(y) + i]){ 
           count++;//这里最多加1
           i++;
        }    
        i = 1; 
        if(currColor == chesses[round(x)][round(y) - i]){ 
            count++; //这里最多加1
            i++; 
        }    
        if (count >= 5) {  //到这里如果上面条件都符合count最大也就只有3,怎么可能大于等于5呢
            canplay = false;   
        }
        if(canplay==false){
            JOptionPane.showMessageDialog(null,"游戏结束");
        }
    }

mousePressed也一样,看count能不能符合条件。每次click都清成1了

我想自己写一个五子棋的java程序。但是在判定胜负时出了问题(参见下图)。相同颜色的棋子相连超过五个。也不会弹出提示信息。图片说明

public void mouseClicked(MouseEvent e){

int x=e.getX();
int y=e.getY();
int count =1 ;

        for(int i=1;i<=4;i++){
            if(currColor ==chesses[round(x)][round(y) + i]){ 
           count++;
        } 
            else{
                break;
            }
        }


        for(int i=1;i<=4;i++){
            if(currColor == chesses[round(x)][round(y) - i]){ 
            count++; 

        }  
            else{
                break;
            }
        }
        if (count >= 5) {  
            canplay = false;   
        }
        if(canplay==false){
            JOptionPane.showMessageDialog(null,"游戏结束");
        }

    }
};

我照楼上那位朋友那样修改了代码。见楼上。但是还有原来的问题。

求助大神。。真的被折磨得不行了。。一直找不出来哪有问题。

下面这两个for循环是有编写代码逻辑冲突的。
如果你是以当前点中的坐标作为起止位置,那么一个循环是递加,一个应该是递减。自己单步跟一下吧

 for(int i=1;i<=4;i++){
            if(currColor ==chesses[round(x)][round(y) + i]){ 
           count++;
        } 
            else{
                break;
            }
        }


        for(int i=1;i<=4;i++){
            if(currColor == chesses[round(x)][round(y) - i]){ 
            count++; 

        }  
            else{
                break;
            }
        }

问题解决了,谢谢楼上的朋友。我把我的代码上传了。