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

2017/3/7

How to stop a clock?

1
2
danpost danpost

2017/3/12

#
I edited the code and then realized that I should not have. I was not able to re-edit it back because you had posted to the thread. Replace lines 17 and 18 with the following:
if (timer == 0) // ... game over routine
}
Fifilein Fifilein

2017/3/13

#
Is that
if (timer > 0)
{
    timer--;
    if (timer%60 == 0) updateTimerDisplay();
}...
in the act method of the worldclass?
danpost danpost

2017/3/13

#
In the world class.
Fifilein Fifilein

2017/3/13

#
Thanks,When I addes the act method to the worldclass and I compiled it showed me illegal character:"lu00a0". Here is my Code :
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class level4 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class level4 extends World
{
    private int timer;
    private Actor timerDisplay;
    Achtung a = new Achtung();
    Counter counter = new Counter();
    StartGame sg = new StartGame();
    /**
     * Constructor for objects of class level4.
     * 
     */
    public level4()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        timer = 1200;
        timerDisplay = new SimpleActor();
        addObject(timerDisplay, 120, 20); // change location as desired
        updateTimerDisplay();
        
        //addObject(new Clock(true, true, 20, "Alert actor after time is up", counter), 450, 60);
        
        {
            addObject(new Achtung(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(a, Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(new Achtung(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(new Achtung(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(new Achtung(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(new Achtung(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(new Achtung(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
        }
        {
            addObject(new Schneg(), getWidth()/2, getHeight()/2);
        }
    }
    public void act()
    {
    if (timer > 0)
    { timer--;
         if (timer%60 == 0) { 
         updateTimerDisplay(); }
    }   
    if (timer == 0) // ... game over routine
     {
        
        }
    }
      private void updateTimerDisplay()
    {timerDisplay.setImage(new GreenfootImage("Time remaining: "+(timer/60), 24, Color.BLACK, new Color(0, 0, 0, 0))); // adjust text as desired
    }
    }

Super_Hippo Super_Hippo

2017/3/13

#
It makes sense to show where the error occurs. In this case however, since it is also happening to me, remove the characters and intend it afterwards. Copying code out of the SyntaxHighlighter makes 'space' to this weird character.
danpost danpost

2017/3/13

#
You can remove all the curly brackets between lines 31 and 54, inclusive. Also, I do not see a need to keep a reference to a specific Achtung object in the class, so also remove line 13 and change 'a' in line 35 to 'new Achtung()'. I have never come across that particular type of error. Where exactly in the code does it refer you to?
Fifilein Fifilein

2017/3/13

#
The error is at the start of line 60
Nosson1459 Nosson1459

2017/3/13

#
Try backspacing line 60 to line 59 then when it moves up to line 59 press <Enter> to move it back to it's correct line.
Nosson1459 Nosson1459

2017/3/13

#
danpost wrote...
I have never come across that particular type of error. Where exactly in the code does it refer you to?
I don't remember if I came across this exact letter but the error I got was also a bunch of random looking characters. The way I fixed it is shown above.
Fifilein Fifilein

2017/3/13

#
Thank you now there is no errormessage anymore. But when the time is 0 you win the game . In the game when the Schneh hits the Achtung you lose . I want the clock to stop when the gameover screen is added.
danpost danpost

2017/3/13

#
Change line 58 to:
if (timer > 0 && getObjects(GameOver.class).isEmpty())
Fifilein Fifilein

2017/3/13

#
Thank you! Now it works. Thank you very much!
You need to login to post a reply.
1
2