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

2016/8/24

Need to display the time at the end

BEASTYLAD BEASTYLAD

2016/8/24

#
Hi, I have a timer running from 0 to 300. if it reaches 300 I get a image up that says well done. I want to be able to have an image appear telling me the amount of time that the user has lasted if they do not get to 300. Timer Code:
Timer wrote...
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; public class Timer extends Actor { public int time = 0; public int count = 65; public void act() { // Add your action code here. if(time == 200) { display2(); Greenfoot.stop(); return; } if(counter()) { time ++; count = 65; } display(); } public boolean counter() { if(count > 0) { count--; } return count == 0; } private void display() { setImage(new GreenfootImage("Game Ends : " + time, 30, Color.WHITE, Color.BLACK)); } public void display2() { getWorld().removeObjects(getWorld().getObjects(LadyBug.class)); getWorld().removeObjects(getWorld().getObjects(Spider.class)); setImage(new GreenfootImage("Well Done you have completed the Game! \n you lasted 200 Seconds", 50, Color.WHITE, Color.BLACK)); } public void display3() { setImage(new GreenfootImage("Well Done you have completed the Game! \n you lasted\n" + "want ths time shown here"), 50, Color.WHITE, Color.BLACK)); } public void setTime() { time = 0; } public boolean isTimeUp() { return time == 200; } i want to have the display 3 store the current time to be shown in a different class.
BEASTYLAD BEASTYLAD

2016/8/25

#
Can anyone help please
Super_Hippo Super_Hippo

2016/8/25

#
So the 'display3' method is in a different class than the Timer class and you want to use the 'timer' variable there? Then you can use this instead of "want ths time shown here":
((Timer)(getWorld().getObjects(Timer.class).get(0)).time
BEASTYLAD BEASTYLAD

2016/8/25

#
No the display 3 method is in the timer and i want it to store the current time into display 3 and then call the method in a different class so that when they click on the wrong actor it stops green foot and calls this method which should say well done you lasted x seconds. And when I use the line above it tells me that int cannot be converted to timer Cheers
Super_Hippo Super_Hippo

2016/8/25

#
There was a ) missing, I guess. Isn't display3 saying that the player won the game? How can that happen when he clicks the wrong actor? Well, to call display3 from a different actor class, you can use this:
((Timer)(getWorld().getObjects(Timer.class).get(0))).display3();
BEASTYLAD BEASTYLAD

2016/8/25

#
No it's telling them how long they lasted before they died which is why I want to put the current time from the counter into method 3. I am then already calling method 3 on my spider class which ends the game and displays an image of method 3 stating " you lasted x seconds", So im actually looking how to get the current time of the timer and stroe it in method 3 to be called by the spider. Hope this makes more sence.
BEASTYLAD BEASTYLAD

2016/8/25

#
Don't worry i used what you gave me earlier and put it into display3() THANK you very much.
You need to login to post a reply.