vendredi 25 décembre 2015

JAVA GAME loop?

I have a problem with my java game. I’m beginner, but i have to write it as a school project.
Game is called „Birthday Cake” there is 7 candles on the cake and randomly one of it is showing for let say 30s and during this time u have to click on it to get point, if u don’t click on it during this time next candle will show. Game end when 10 candle shows.
I made for loop and i tried to make it work for sooo long that I’m dying from frustration
my for loop works but it is so fast that i use Thread.sleep(1000), i tried lots of solutions it looks ok. BUT when i start my game nothing is happening and after few seconds all 7 candles shows and quickly disappear. I think I’m doing something wrong, but i have no idea what.

   if(Dane.start){

        int liczbaLosowa = 0;

        for(int i=0; i<10 ;i++){
            liczbaLosowa = (int)(Math.random()*7);

            this.wspX= wspX_p[liczbaLosowa];
            this.wspY= wspY_p[liczbaLosowa];
            g2d.drawImage(plomienImg, wspX, wspY,null);
            Toolkit.getDefaultToolkit().sync();
            try {
                Thread.sleep(1000);     
            } catch (Exception ex) { }
            //repaint();
        }
        Dane.start=false;

        }




Aucun commentaire:

Enregistrer un commentaire