dimanche 3 mai 2015

C# - how to simplify this code?

starting from (count == 0) {click Power = 1;} I would like that for every value of count clickPower should double, just like the code that I entered.

if (count == 0){
            clickPower = 1;
        }else if (count == 1){
            clickPower = 2;
        }else if (count == 2){
            clickPower = 4;
        }else if (count == 3){
            clickPower = 8;
        }else if (count == 4){
            clickPower = 16;
        }else if (count == 5){
            clickPower = 32;
        }else if (count == 6){
            clickPower = 64;
        }else if (count == 7){
            clickPower = 128;
        }else if (count == 8){
            clickPower = 256;
        }else if (count == 9){
            clickPower = 512;
        }else if (count == 10){
            clickPower = 1024;
        }else if (count == 11){
            clickPower = 2048;
        }else if (count == 12){
            clickPower = 4096;
        }else if (count == 13){
            clickPower = 8192;
        }else if (count == 14){
            clickPower = 16284;
        }else if (count == 15){
            clickPower = 32768;
        }else if (count == etc.){
            clickPower = etc.;
        }

Aucun commentaire:

Enregistrer un commentaire