lundi 10 juillet 2017

Android Quiz test if questions is asked before - cleanup Code

I have created a quiz app with categories, when playing the quiz can come up to 4 questions in the same category. To check if the question is asked before, I have this large code. The questions are selected randomly from the category.

Can someone help me how to simplify and clean up this?

auswahl = question number
lastauswahl = last question number
vorlastauswahl = last last question number
vorvorlastauswahl = last last last question number

if (auswahl == lastauswahl) { //Check if the current question is the same as the last question
            if (auswahl + 1 >= anzahl) { //If is equal, take the question before if there is no one after
                auswahl--;
                if (auswahl == vorlastauswahl) { //Check if the new question is the same as the last last question
                    auswahl--;
                    if (auswahl == vorvorlastauswahl) { //Check if the new question is the same as the last last last question
                        auswahl--;
                    }
                }else if(auswahl == vorvorlastauswahl){ (//Check if the new question is the same as the last last last question
                    auswahl--;
                    if (auswahl == vorlastauswahl) { //Check if the new question is the same as the last last question
                        auswahl--;
                    }
                }
            } else { //if is equal and there is a question after the current question so
                auswahl++;
                if (auswahl == vorlastauswahl) { //same game like before
                    if (auswahl + 1 >= anzahl) {
                        auswahl--;
                        auswahl--;
                        if (auswahl == vorvorlastauswahl) {
                            auswahl--;
                        }
                    } else {
                        auswahl++;
                        if (auswahl + 1 >= anzahl) {
                            if (auswahl == vorvorlastauswahl) {
                                auswahl--;
                                auswahl--;
                                auswahl--;
                            }
                        }else{
                            if (auswahl == vorvorlastauswahl) {
                                auswahl++;
                            }
                        }
                    }
                }
            }
        } else if (auswahl == vorlastauswahl) { //Check if the current question is the same as the last last question
            if (auswahl + 1 >= anzahl) {
                auswahl--;
                if (auswahl == lastauswahl) {
                    auswahl--;
                    if (auswahl == vorvorlastauswahl) {
                        auswahl--;
                    }
                }else if (auswahl == vorvorlastauswahl) {
                    auswahl--;
                    if (auswahl == lastauswahl) {
                        auswahl--;
                    }
                }
            } else {
                auswahl++;
                if (auswahl == lastauswahl) {
                    if (auswahl + 1 >= anzahl) {
                        auswahl--;
                        auswahl--;
                        if (auswahl == vorvorlastauswahl) {
                            auswahl--;
                        }
                    } else {
                        auswahl++;
                        if (auswahl == vorvorlastauswahl) {
                            if (auswahl + 1 >= anzahl) { 
                                auswahl--;
                                auswahl--;
                                auswahl--;
                            }else{
                                auswahl++;
                            }
                        }
                    }
                }else if (auswahl == vorvorlastauswahl) {
                    if (auswahl + 1 >= anzahl) { 
                        auswahl--;
                        auswahl--;
                        if (auswahl == vorlastauswahl) {
                            auswahl--;
                        }
                    } else {
                        auswahl++;
                        if (auswahl == lastauswahl) {
                            if (auswahl + 1 >= anzahl) { 
                                auswahl--;
                                auswahl--;
                                auswahl--;
                            }else{
                                auswahl++;
                            }
                        }
                    }
                }
            }
        } else if (auswahl == vorvorlastauswahl) {
            if (auswahl + 1 >= anzahl) { 
                auswahl--;
                if (auswahl == lastauswahl) {
                    auswahl--;
                    if (auswahl == vorlastauswahl) {
                        auswahl--;
                    }
                }else if (auswahl == vorlastauswahl) {
                    auswahl--;
                    if (auswahl == lastauswahl) {
                        auswahl--;
                    }
                }
            } else {
                auswahl++;
                if (auswahl == lastauswahl) {
                    if (auswahl + 1 >= anzahl) {
                        auswahl--;
                        auswahl--;
                        if (auswahl == vorlastauswahl) {
                            auswahl--;
                        }
                    } else {
                        auswahl++;
                        if (auswahl == vorlastauswahl) {
                            if (auswahl + 1 >= anzahl) {
                                auswahl--;
                                auswahl--;
                                auswahl--;
                            }else{
                                auswahl++;
                            }
                        }
                    }
                }else if (auswahl == vorlastauswahl) {
                    if (auswahl + 1 >= anzahl) { 
                        auswahl--;
                        auswahl--;
                        if (auswahl == lastauswahl) {
                            auswahl--;
                        }
                    } else {
                        auswahl++;
                        if (auswahl == lastauswahl) {
                            if (auswahl + 1 >= anzahl) {
                                auswahl--;
                                auswahl--;
                                auswahl--;
                            }else{
                                auswahl++;
                            }
                        }
                    }
                }
            }
        }

This time I don't have any idea how I can search something like this on Google. So I also happy if anyone told me how I can search about things like this.

Falke Design

Aucun commentaire:

Enregistrer un commentaire