mardi 18 avril 2017

Java calling function from another class not working correctly.

When i call a function from my Scoring class "down()". When i call the function from the same class it works as expected.

He is the function down in class App:

public void down(){
    for(int first=0; first<board.length; first++){
        for(int second=0; second<board[first].length; second++){
            System.out.print(board[first][second]);
        }
        System.out.println("");
    }
    for(int first=0; first<cords.length; first++){
        for(int second=0; second<cords[first].length; second++){
            System.out.print(cords[first][second]);
        }
        System.out.println("");
    }
    boolean pass=true;
    int max=getMaxRow(cords);
    for(int i=0; i<cords.length; i++){
        if(cords[3][0] < 19 && board[cords[i][0]+1][cords[i][1]]>0){
            if(cords[i][0]==max){
                pass=false;
            }else{
                boolean contains=false;
                for(int x=i; x<cords.length; x++){
                    if(cords[i][0]==cords[x][0]-1 && cords[i][1]==cords[x][1]){
                        contains=true;
                    }
                }
                if(contains==false){
                    pass=false;
                }
            }
        }
    }
    if(cords[3][0] < 19 && pass==true){
        deleteCordsOnBoard();
        for(int i=0; i<cords.length; i++){
            cords[i][0]+=1;
        }
        placeCordsOnBoard();
    }else{
        checkComplete();
        boolean fail=checkFail();
        if(fail){
            active=false;
            fail();
        }else{
            setCords();
            placeCordsOnBoard();
        }
    }
    refreshBoard();
}

Here is the class Timer which calls the function down:

public class Scoring extends Thread{

    public void run(){
        System.out.println("pass here");
        App a=new App();
        if(a.getActive()){
            try{
                a.down();
                Thread.sleep(1000);
                run();
            }catch(InterruptedException e){
                System.out.println("Not pass");
            }
        }
    }
}






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire