Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Connect四款游戏不承认对角胜利_Java_Windows_Connect_Diagonal - Fatal编程技术网

Java Connect四款游戏不承认对角胜利

Java Connect四款游戏不承认对角胜利,java,windows,connect,diagonal,Java,Windows,Connect,Diagonal,我正在尝试制作一个6行7列的连接4游戏。电路板是一个字符串2D数组,电路板上的每个空插槽都是一个“.”字符串。如果我再调整循环,程序将给我一个BoundsException的indexArrayOutOfBoundsException,因此我无法确定需要对算法进行哪些更改来检查对角赢 //tests for an upper-left-to-lower-right diagonal line made by four of the same color checker for(int r

我正在尝试制作一个6行7列的连接4游戏。电路板是一个字符串2D数组,电路板上的每个空插槽都是一个“.”字符串。如果我再调整循环,程序将给我一个BoundsException的indexArrayOutOfBoundsException,因此我无法确定需要对算法进行哪些更改来检查对角赢

//tests for an upper-left-to-lower-right diagonal line made by four of the same color checker
    for(int row = 0; row <= LOWEST_ROW_INDEX - 3; row++)
    {
        for(int col = 0; col <= RIGHTMOST_COLUMN_INDEX - 3; col++)
        {
            if((gb[row][col] != ". ")
            && (gb[row + 1][col + 1] != ". ")
            && (gb[row + 2][col + 2] != ". ")
            && (gb[row + 3][col + 3] != ". ")
            && (gb[row][col] == gb[row + 1][col + 1])
            && (gb[row + 1][col + 1] == gb[row + 2][col + 2])
            && (gb[row + 2][col + 2] == gb[row + 3][col + 3]))
            {
                return gb[row][col];
            }
        }
    }

    //tests for a lower-left-to-upper-right diagonal line made by four of the same color checker
    for(int row = 0; row <= LOWEST_ROW_INDEX - 3; row++)
    {
        for(int col = RIGHTMOST_COLUMN_INDEX - 3; col >= 0; col--)
        {
            if((gb[row][col] != ". ")
            && (gb[row + 1][col + 1] != ". ")
            && (gb[row + 2][col + 2] != ". ")
            && (gb[row + 3][col + 3] != ". ")
            && (gb[row][col] == gb[row + 1][col + 1])
            && (gb[row + 1][col + 1] == gb[row + 2][col + 2])
            && (gb[row + 2][col + 2] == gb[row + 3][col + 3]))
            {
                return gb[row][col];
            }
        }
    }
//测试由四个相同颜色的棋盘格组成的左上角到右下角的对角线

对于(int row=0;row来说,逻辑看起来很合理,但有一个问题是您无法将Java中的字符串与==)进行比较;您需要使用.equals()。==检查这两个字符串是否存储在内存中的同一位置,而不是它们是否包含相同的字符