samedi 3 mars 2018

how can i perform if else statement to the folowing code [duplicate]

This question already has an answer here:

I am writing an android application for X O game , I am using android studio to finish this task, I have given the code and I am required to write if else statement to the following code, but I could not figure out how to do, I wrote it in separate methods but it did not work, can someone help me in this please !!

(it is part of the code where I should perform if else statement,) public int didWin(){

    if (postions[0] == "X" && postions[1]=="X" && postions[2]=="X"){
        return  0;
    }else{
        return -1;
    }
    }
public int didWin1(){
    if (postions[3] == "X" && postions[4]=="X" && postions[5]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin2(){
    if (postions[6] == "X" && postions[7]=="X" && postions[8]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin3(){
    if (postions[0] == "X" && postions[3]=="X" && postions[6]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin4(){
    if (postions[1] == "X" && postions[4]=="X" && postions[7]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin5(){
    if (postions[2] == "X" && postions[5]=="X" && postions[8]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin6(){
    if (postions[0] == "X" && postions[3]=="X" && postions[6]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin7(){
    if (postions[0] == "X" && postions[4]=="X" && postions[8]=="X"){
        return  0;
    }else{
        return -1;
    }
}
public int didWin8(){
    if (postions[2] == "X" && postions[4]=="X" && postions[6]=="X"){
        return  0;
    }else{
        return -1;
    }
}

}

Aucun commentaire:

Enregistrer un commentaire