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";
}
}