This site requires JavaScript, please enable it in your browser!
Greenfoot
Username
Password
Remember Me?
Sign Up, Lost Password
Activity
About
Documentation
Download
Discuss
Scenarios
Discussions
You need to login to take part
Current Discussions
HELP WITH GREEPS URGENT
By JohnMa, with no replies.
Hi, I need help with my greeps code for my class Rule 1: Only change the class 'Greep'. No other classes may be modified or created. *** You will be making all of your changes within the act method of the Greep class. Rule 2: No additional fields. You cannot extend the Greeps' memory. That is: You are not allowed to add fields to the class (except final fields). You can use the one byte memory that is provided. Rule 3: You cannot move more than once per 'act' round. Rule 4: You cannot communicate directly with other Greeps. That is: no field accesses or method calls to other Greep objects are allowed. (Greeps can communicate indirectly via the paint spots on the ground.) Rule 5: No long vision. You are allowed to look at the world only at the immediate location of the Greep. Greeps are almost blind, and cannot look any further. Rule 6: No creation of objects. You are not allowed to create any scenario objects (instances of user-defined classes, such as Greep or Paint). Greeps have no magic powers - they cannot create things out of nothing. Rule 7: No teleporting. Methods from Actor that cheat normal movement (such as setLocation) may not be used. I CAN ONLY CHANGE THE super.act method this is my code right now. I need to get better scores import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A Greep is an alien creature that likes to collect tomatoes. * * @author (Your Name Here) * @version 0.1 */ public class Greep extends Creature { // Remember: you cannot extend the Greep's memory. So: // no additional fields (other than final fields) allowed in this class! final static int HOW_MUCH_STEPS = 10; final static int FULL_360= 360; /** * Default constructor for testing purposes. */ public Greep() { this(null); } /** * Create a Greep with its home space ship. */ public Greep(Ship ship) { super(ship); } /** * Do what a greep's gotta do * * Name: * Date: * Description: basic starting version * * * */ public void act() { super.act(); // do not delete! leave as first statement in act(). if (carryingTomato()) { int remainingSteps = getMemory(); if(remainingSteps == 0) { spit("purple"); turnHome(); } else { remainingSteps--; setMemory(remainingSteps); } if(atShip()) { dropTomato(); turn(180); } if(atWater() || atWorldEdge()) { setMemory(HOW_MUCH_STEPS + Greenfoot.getRandomNumber(HOW_MUCH_STEPS/2)); turn(Greenfoot.getRandomNumber(FULL_360)); } move(); } else { boolean hasPurple = seePaint("purple"); if(hasPurple) { turnHome(); turn(180); } if(atWater() || atWorldEdge()) { turn(Greenfoot.getRandomNumber(FULL_360)); } move(); checkFood(); } } /** * Is there any food here where we are? If so, try to load some! */ public void checkFood() { // check whether there's a tomato pile here TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class); if(tomatoes != null) { loadTomato(); // Note: this attempts to load a tomato onto *another* Greep. It won't // do anything if we are alone here. } } /** * This method specifies the name of the author (for display on the result board). */ public static String getAuthorName() { return "Ruhaan"; // write your name here! } /** * This method specifies the image we want displayed at any time. (No need * to change this for the competition.) */ public String getCurrentImage() { if(carryingTomato()) return "greep-with-food.png"; else return "greep.png"; } }
how can i limit the ammount of actors are created when act =30 cycles
By roonie01, with 11 replies.
Last reply by roonie01, almost 9 years ago:
thank you so much it works great
The scenario stops when switching worlds?
By Arakniode, with 3 replies.
Last reply by roonie01, almost 9 years ago:
do you possibly have a Greenfoot.stop(); some where in your code for the start button
how to fix this code for class moves very choppy need help quick
By roonie01, with 2 replies.
Last reply by roonie01, almost 9 years ago:
oh thanks so much man your a life saver that's exactly what I was trying to do
Bubbles with a for loop
By dbutts1@stumail.com, with 2 replies.
Last reply by dbutts1@stumail.com, almost 9 years ago:
Thank You
How to check if the game is stopped?
By Firelion, with 6 replies.
Last reply by Firelion, almost 9 years ago:
This works, thanks!
How to optimise my code?
By Arkin, with 1 reply.
Replied to by davmac, almost 9 years ago:
There are possibly a lot of things you could do, though I only scanned your code quickly. One thing that stands out: the technique you use to find a single object: <Code Omitted> ... is pretty inefficient; it needs to scan through all objects and filter out those except for the one of the specified type. If it's just a singleton, you could store a reference to it in a static variable instead (eg have a static variable "instance" in the Jambe_p2_1 class and set it in the constructor).
get a variable from object at offset from another actor
By Arkin, with 4 replies.
Last reply by Arkin, almost 9 years ago:
I found how to do this! <Code Omitted>
Passing a variable and Output
By dbutts1@stumail.com, with 2 replies.
Last reply by dbutts1@stumail.com, almost 9 years ago:
Thanks for pointing that out. Should be .12,.15,.20. I'll look into it in the morning. Too many hours make simple mistakes get more plentiful.
Dice rolling at the same time?
By WardedBowl403, with 1 reply.
Replied to by danpost, almost 9 years ago:
If your die objects are supposed to roll (that is, it is a behavior of a 'dice' object to roll), then you should have a 'roll' method in the 'dice' class. Also, if your die objects are to have values (that is, it is a state of a 'dice' object to have an integer value -- which, in turn, determines its image), then you should have an integer field in the 'dice' class for that value. Methods implement behavior and fields track states of an object. Lines 6 through 8 of the 'clicked' method are pointless as the 'dice' object created is immediately lost once the 'if' clause has finished executi
How to make a new object type appear to replace another
By protocolUnknown, with 3 replies.
Last reply by protocolUnknown, almost 9 years ago:
danpost, that worked! I did not realise that that might be the problem. Thanks a lot.
Decimal.Format
By dbutts1@stumail.com, with 2 replies.
Last reply by dbutts1@stumail.com, almost 9 years ago:
Thank you. I've been looking at this so long I see that my main issue was I never put in import java.text.DecimalFormat;
Button not working :(
By PeloviaOliver, with 4 replies.
Last reply by danpost, almost 9 years ago:
Maybe you did not understand what I was trying to say above. You need to change the offsets at which you check on the color. If you really want to check that it moves at all, change 'canMove()' to 'true' on line 11.
I dont know what to do
By Bandito, with 14 replies.
Last reply by Bandito, almost 9 years ago:
alright sorry, that I answered it so late but my comment was reported for being potential spam, i figured everything out thanks though
Why does this not work?
By Simon1122111, with 16 replies.
Last reply by Simon1122111, almost 9 years ago:
ok thank you very much!
304
305
306
307
308
309
310
X