即使有一个,也找不到If语句

时间:2013-04-25 13:45:08

标签: java maze

当我尝试编译此代码时,如果没有,我会收到错误消息。我相信我把所有的牙套放在了正确的位置。我还得到了其他错误,我已经附加了图片,但我只是相信他们在那里,因为如果没有错误就不能使用其他错误。

问题代码:

public static boolean goNorth(){
        boolean success;
        if(maze[currCol]currRow - 1] == CLEAR){
            maze[currCol][startRow -1] = PATH;
            currRow--;
            success = goNorth();
                if(!success){
                success = goWest();
                    if(!success){
                    success = goEast();
                        if(!success){
                            maze[currCol][currRow] = VISITED;
                            currRow++;
                            }
                        }
                    }
                    return success;
                } else {
                    return false;
            }
        }

    public static boolean goWest(){
        boolean success;
        if(maze[currCol - 1]currRow] == CLEAR){
            maze[currCol - 1][startRow] = PATH;
            currRow--;
            success = goWest();
                if(!success){
                success = goSouth();
                    if(!success){
                    success = goNorth();
                        if(!success){
                            maze[currCol][currRow] = VISITED;
                            currCol++;
                            }
                        }
                    }
                    return success;
                } else {
                    return false;
            }
        }

        public static boolean goEast(){
        boolean success;
        if(maze[currCol + 1]currRow] == CLEAR){
            maze[currCol + 1][startRow] = PATH;
            currRow--;
            success = goEast();
                if(!success){
                success = goNorth();
                    if(!success){
                    success = goSouth();
                        if(!success){
                            maze[currCol][currRow] = VISITED;
                            currCol--;
                            }
                        }
                    }
                    return success;
                } else {
                    return false;
            }
        }

        public static boolean goSouth(){
        boolean success;
        if(maze[currCol]currRow + 1] == CLEAR){
            maze[currCol][startRow + 1] = PATH;
            currRow--;
            success = goSouth();
                if(!success){
                success = goEast();
                    if(!success){
                    success = goWest();
                        if(!success){
                            maze[currCol][currRow] = VISITED;
                            currRow--;
                            }
                        }
                    }
                    return success;
                } else {
                    return false;
            }
        }

错误:

screen shot

2 个答案:

答案 0 :(得分:3)

    if(maze[currCol + 1]currRow] == CLEAR){

那是无效的;你错过了几个地方currRow附近的左括号。

此外,还有一大堆重构。

答案 1 :(得分:2)

阅读第一个错误。在您理解第一个错误之前,切勿读取任何错误。

第一个错误告诉您此行有语法错误:

if(maze[currCol]currRow - 1] == CLEAR){

(然后将其复制粘贴四次)。它在[之前缺少currRow