alright so the goal of the project is to make a bug that moves 2 spaces at a time BUT must know if a rock is 2 spaces ahead, if it is then it must only move 1, if another bug/flower is 2 spaces ahead it just "squishes" it.
im having trouble writing the code to test for 2 spaces ahead of it, this is what i have so far
import info.gridworld.actor.Actor;
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;
import java.util.ArrayList;
import info.gridworld.grid.Grid;
import java.awt.Color;
public class jumperBug extends Bug
{
public boolean canMove()
{
Grid<Actor> gr = getGrid();
if (gr == null)
return false;
Actor neighbor = gr.get(testLoc); // get an error on this line
return (neighbor == null) || (neighbor instanceof Flower); //suppose to return true if no rocks are here but cant find symbol flower?
}
public Location testLoc (int testRow, int testCol) // havent finished the ifs yet but depending on the direction it is facing it will get the row and col of the spot 2 spaces ahead of him
{
Location loc = getLocation();
int x = loc.getRow();
int y = loc.getCol();
int z = getDirection();
if (z == 0)
{
testRow = loc.getRow()-2;
testCol = loc.getCol();
}
Location testLoc = new Location(testRow,testCol);
return testLoc;
}
}
anyone know how to makes work or improve it? i also havent even started the method to make it move yet.
Edited by: vouslavous on Apr 19, 2009 1:54 PM
Edited by: vouslavous on Apr 19, 2009 1:55 PM
Edited by: vouslavous on Apr 19, 2009 1:56 PM