The Code I inputed changed the color of the Critter to match the color of the actor it surronded , it did not change it's neighboring actors colors to black. My teacher is telling me to add a for lood but i do not know where to add one.
My Code:
//© A+ Computer Science - www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import java.awt.Color;
import java.util.ArrayList;
import info.gridworld.grid.Grid;
import info.gridworld.actor.Rock;
import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.grid.Location;
public class BlackPlagueCritter extends Critter
{
//processActors will turn all Actors around this critter Black
//unless the Actor is a Rock or another BlackPlagueCritter
public void processActors(ArrayList<Actor> dudes)
{
int n = dudes.size();
if(n == 0)
{
return;
}
int r = (int) (Math.random() *n );
Actor other = dudes.get(r);
setColor(other.getColor());
}
}
____________________________________________________________________________-
In the Main Class:
//© A+ Computer Science - www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import java.awt.Color;
import info.gridworld.actor.Rock;
import info.gridworld.actor.Actor;
import info.gridworld.actor.Flower;
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;
import info.gridworld.grid.BoundedGrid;
import info.gridworld.actor.ActorWorld;
public class BlackPlagueCritterRunner
{
public static void main(String[] args)
{
ActorWorld world = new ActorWorld(new BoundedGrid<Actor>(8,8));
world.add(new Location(1, 1), new BlackPlagueCritter());
world.add(new Location(3, 1), new Rock());
world.add(new Location(5, 2), new Actor());
world.add(new Location(7, 6), new Flower());
world.add(new Location(6, 6), new Actor());
world.add(new Location(0, 5), new Actor());
world.add(new Location(2, 6), new Bug(Color.GREEN));
world.add(new Location(3, 5), new Actor());
world.show(); }
}
This post has been edited by jon.kiparsky: 30 January 2012 - 11:42 AM
Reason for edit:: fixed code tags

New Topic/Question
Reply


MultiQuote







|