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

2018/1/31

Separate scoreboard and timer for 3 classes

1
2
3
danpost danpost

2018/2/1

#
frequency wrote...
I dont know how to syntax the bool!
public static boolean done; // or 'finished', 'completed', 'elapsed', 'gameOver' or whatever
Remove line 14, 29 and 34 and add the following field as well as the boolean:
private long endTime;
The act method should start with what I gave above.
danpost danpost

2018/2/1

#
My third line (the commented one) can be replaced with:
updateImage();
and the following can be placed as the first line in act:
if (done) return;
Now, it is just a matter of updating the image.
frequency frequency

2018/2/1

#
Cant understand which is (the commented one) Can you please edit this piece of code to fit what you mean? I cant get it. I made this
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Timer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public static boolean done; // or 'finished', 'completed', 'elapsed', 'gameOver' or whatever

public class Timer30 extends thirty_seconds
{
    private static final Color TEXT_COLOR = new Color(255,255,255);
    private static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
    private long timeStarted;
    
     
    /**
     * Act - do whatever the Timer wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void Timer()
    {
        updateImage();
        timeStarted=System.currentTimeMillis();
    }
     
    public void act() 
    {
	if (done) return;
	private long endTime;
        updateImage();
        
         
        if (System.currentTimeMillis()-timeStarted>1000)
        {
            timeStarted=System.currentTimeMillis();
           
        }
     
    } 
     
    private void updateImage()
    {
        String text="Seconds left";
        GreenfootImage image =new GreenfootImage(text,30,TEXT_COLOR,TRANSPARENT_COLOR);
        setImage(image);
    }
}
danpost danpost

2018/2/1

#
Replace line 15 with line 31 (in other words, cut line 31 and paste it to replace line 15. Also, move line 9 down to line 16 (the only thing that can go outside the class code block are import lines (and comments). Put the other code that I gave for the act method in after line 30 and remove lines 32 through 40. Then post what you ended up with for further changes.
frequency frequency

2018/2/1

#
Is this correct?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Timer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

 
public class Timer30 extends thirty_seconds
{
    private static final Color TEXT_COLOR = new Color(255,255,255);
    private static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
    private long endTime;
    public static boolean done; // or 'finished',
     
      
    /**
     * Act - do whatever the Timer wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void Timer()
    {
        updateImage();
        endTime=System.currentTimeMillis();
    }
      
    public void act() 
    {
        if (done) return;
        
    } 
      
    private void updateImage()
    {
        String text="Seconds left";
        GreenfootImage image =new GreenfootImage(text,30,TEXT_COLOR,TRANSPARENT_COLOR);
        setImage(image);
    }
}
frequency frequency

2018/2/1

#
Its not running,please help. I am so stressed out and i have no time left. I am really really stressed atm. Can you PLEASE fill this for me? This is the scenario http://www.greenfoot.org/scenarios/20777 All i am missing is the count down timer the image update and the score reset.All images are on the folder. I am deeply sorry to ask that but i have to other choice at the moment. Please mr Dan, i never wanted to say it but can you do it for me? The only problem that i have is the time.Rules changed for the presentation and i cant make it without you :/ Thank you!
danpost danpost

2018/2/1

#
Replace lines 25 and 26 with the following:
setImage(new GreenfootImage("Time remaining: 30", 30, TEXT_COLOR, TRANSPARENT_COLOR));
Then, insert the code given here and the first part here at line 32. Then, post the class again for the final phase.
frequency frequency

2018/2/1

#
I actually made it before 2-3 hours.Thanks,i will post new stuff
You need to login to post a reply.
1
2
3