Mother bug would have a bug appear every 1-3 moves behind it, and it would behave as a normal bug (move straight, turn at walls/rocks, leave flowers behind). The mother bug would eat flowers in front of it, eat rocks in front of it, and turn at walls.....It would also eat other bugs (This includes it's kids). Only doing that to get a kick out of the teacher.
The reason I chose this is, in all honesty, I don't know how to program...at all really. The fact that I'm passing the class is a miracle. I chose this because I believed I would be able to take the code from other, completed bugs (a normal bug spawning flowers, crabs eating flowers, etc)
But, after (very shortly) copy and pasting, fixing a few things I knew how to fix, I'm still getting errors. I only have tomorrow to finish working on the bug, and I need a passing grade on this to keep my grade in the class from dropping below a C.
In short, I would like help identifying the current error I'm getting on this bug. I have yet to try much (adding some imports, fixed a few things).
I'm guessing my issue is I'm trying to bring in methods from the critter project, meaning some terms aren't defined or something. I'll be adding the methods to have the bug remove adjacent bugs and rocks from the grid.
The current issue is in the canMove() method. About 4 or 5 errors (unable to find symbol if I remember correctly) pop up through the method (2 in line 44, I can't remember the rest off the top of my head).
import info.gridworld.actor.Bug;
import info.gridworld.actor.ActorWorld;
import info.gridworld.grid.Location;
import info.gridworld.actor.Rock;
import info.gridworld.actor.Actor;
import java.util.ArrayList;
import java.awt.Color;
public class MotherBug extends Bug
{
public void act()
{
if (canMove())
move();
else
turn();
}
public void turn()
{
setDirection(getDirection() + Location.HALF_RIGHT);
}
public void move()
{
Grid<Actor> gr = getGrid();
if (gr == null)
return;
Location loc = getLocation();
Location next = loc.getAdjacentLocation(getDirection());
if (gr.isValid(next))
moveTo(next);
else
removeSelfFromGrid();
Bug child = new Bug(getColor());
bug.putSelfInGrid(gr, loc);
}
public boolean canMove()
{
Grid<Actor> gr = getGrid();
if (gr == null)
return false;
Location loc = getLocation();
Location next = loc.getAdjacentLocation(getDirection());
if (!gr.isValid(next))
return false;
Actor neighbor = gr.get(next);
return (neighbor == null) || (neighbor instanceof Flower);
}
public void processActors(ArrayList<Actor> actors)
{
for (Actor a : actors)
{
if (a instanceof Rock)
a.removeSelfFromGrid();
}
}
}
Any tips or pointers would be appreciated. If I can't copy and paste or anything, I'll appreciate knowing that as well. I'll try to post again while I'm in class tomorrow (to get the exact errors and what not) if I can get help here. I'll ask around class, and worst case scenario just have the new bug spawn other bugs.
If someone could also tell me which method of CrabCritter I can use, that would be amazing, but I don't think I'll need it (at most, just the imports).
Thank you for your time.

New Topic/Question
Reply


MultiQuote



|