mardi 3 novembre 2015

Minimizing the the use of if statement

I am trying to minimize the conditional statements as much as possible within the following if statement, how can it be achieved?

if(safeHalFromCros == true){
        System.out.println("Crossbowman cannot win, Halbedier out of range");
        if(speedHalToCav < speedCavToCros){
            halberdier.setXPos(cavalier.getXPos());
            halberdier.setYPos(cavalier.getYPos());
            System.out.printf("***The winner is: %3s:\n",halberdier.toString());

        }else{
            cavalier.setXPos(crossBowMan.getXPos());
            cavalier.setYPos(crossBowMan.getYPos());
            System.out.printf("***The winner is %3s:\n",cavalier.toString());
            crossBowMan.setXPos(-1.0);
            crossBowMan.setYPos(-1.0);

        }
    }else{
        System.out.println("Crossbowman has a chance to win, Halbedier is within range");
        if(speedCrosToHal < speedHalToCav && speedCrosToHal < speedCavToCros){
            System.out.println("Printing out the speeds for testing purposes");
            System.out.println("Speed of crossbowman to halberdier is: "+speedCrosToHal);
            System.out.println("Speed of halbedier to cavalier is: "+speedHalToCav);
            System.out.println("Speed of cavalier to crossbowman is: "+speedCavToCros);
            halberdier.setXPos(-1.0);
            halberdier.setYPos(-1.0);
            System.out.printf("***The winner is %3s:\n",crossBowMan.toString());
        }
    }

Aucun commentaire:

Enregistrer un commentaire