This site requires JavaScript, please enable it in your browser!
Greenfoot back
Starlord_20
Starlord_20 wrote ...

2020/2/4

need help

Starlord_20 Starlord_20

2020/2/4

#
int summe1 = 0,summe2 = 0,i,summePlayer=0,summeAI=0,counter=0,x; 

    public void act() {
        int a = intInput("Anzahl Runden:")-1; int x = 2; boolean got1 = false;
        while( a > 0) {
            x = 2;
            while(counter < 5) {
                int random = (int) (6*Math.random()+1);
                getWorld().showText(""+random,x,3); 
                x += 2;
                if(random == 1) got1 = true;
                summe1 += random; 
                counter ++;
            }
            if(got1 == false) { 
                summePlayer += summe1; summe1 = 0;
            } else got1 = false;
            getWorld().showText("Summe: "+summeAI,5,4); 
            x = 2;
            Greenfoot.delay(1);    

            while (counter != 0) {
                int random = (int) (6*Math.random()+1);
                getWorld().showText(""+random,x,7); 
                x += 2;
                if(random == 1) got1 = true;
                summe2 += random; 
                counter --;
            }
            if(got1 == false) { 
                summeAI += summe2; summe2 = 0;
            } else got1 = false;
            getWorld().showText("Summe: "+summeAI,5,8);  
            a--;   

        }

    }
in my little game, I want the player play against the computer. After every round the total is added together, but if your random number is 1, the currend round isn`t counted. The Game lasts until the required count of rounds (int a) is reached. my problem: the output of the total (int summe1 and int summe2) doesn`t work...
You need to login to post a reply.