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

2017/12/2

Using the Enter key to re-set World

elbebe20 elbebe20

2017/12/2

#
Hello everyone so I'm trying to use the enter key to reset my little crab world. so I declare the reset like this in the World class....... Reset reset = new Reset(); and this is the code for a sub-class to world call Reset........ public class Reset extends World { /** * so this code is to reset the CrabWorld when the Enter key is press. */ public void Reset() { if (Greenfoot.isKeyDown("enter")); Greenfoot.setWorld(); } } basically I want to reset my world when ever the enter key is press. thank for the help....!
danpost danpost

2017/12/2

#
You do not need another World subclass to reset your world. You would use this line of code to reset your world:
1
Greenfoot.setWorld(new CrabWorld());
The act method of the CrabWorld class can check for the key and reset the world.
elbebe20 elbebe20

2017/12/3

#
Thank you Mr. Danpost. But, this code wont reset my world whenever I click the enter key on the keyboard....???? I deleted my original code and simply copy yours in my CrabWorld as suggested, but it is not working? any idea.
danpost danpost

2017/12/3

#
elbebe20 wrote...
But, this code wont reset my world whenever I click the enter key on the keyboard....???? I deleted my original code and simply copy yours in my CrabWorld as suggested, but it is not working? any idea.
Please show what you tried (show the code for the CrabWorld class with what you attempted that failed).
You need to login to post a reply.