All pastes #2051500 Raw Edit

Someone

public text v1 · immutable
#2051500 ·published 2011-04-28 11:44 UTC
rendered paste body

//PolinatorCritter finds SteadyFlowers and stores the first flower's color. 
//It then colors all the other flowers it finds to the first flower's color.
package src;
import info.gridworld.actor.*;
import info.gridworld.world.*;
import info.gridworld.grid.*;

import java.*;
import java.util.ArrayList;
public class PolinatorCritter extends Critter{
	//First flower bool
	boolean firstflower = false;
	//First flower
	SteadyFlower first;
	// The grid
	Grid gr;
	//Stores current location, changed every act.
	Location current;
	//Array that holds 
	Actor []people = new Actor[3];
	public void act(){
		gr = getGrid();
		current = getLocation();
		if(!gr.isValid(current.getAdjacentLocation(getDirection()-45))
				&&!gr.isValid(current.getAdjacentLocation(getDirection()))
				&& !gr.isValid(current.getAdjacentLocation(getDirection()+45))){
	        ArrayList<Location> moveLocs = getMoveLocations();
	        Location loc = selectMoveLocation(moveLocs);
	        makeMove(loc);
	        return;
		}
		people = getPeople(getDirection());
		for(Actor iter:people){
			if(firstflower == false&&iter instanceof SteadyFlower){
				first = (SteadyFlower)iter;
				firstflower = true;
				setColor(first.getColor());
				return;
			}
			if( iter instanceof SteadyFlower){
				iter.setColor(first.getColor());
			}
		}
        if (getGrid() == null)
            return;
        ArrayList<Location> moveLocs = getMoveLocations();
        Location loc = selectMoveLocation(moveLocs);
        makeMove(loc);
	}
	public Actor[]  getPeople(int direction){

		Actor [] neigh = new Actor [3];
		if(gr.isValid(current.getAdjacentLocation(getDirection()-45)))
			neigh[0] = (Actor)gr.get(current.getAdjacentLocation(direction-45));
		if(gr.isValid(current.getAdjacentLocation(getDirection())))
			neigh[1] = (Actor)gr.get(current.getAdjacentLocation(direction));
			if(gr.isValid(current.getAdjacentLocation(getDirection()+45)))
			neigh[2] = (Actor)gr.get(current.getAdjacentLocation(direction+45));
			return neigh;
	}
    public void makeMove(Location loc)
    {
        setDirection(getLocation().getDirectionToward(loc));
        super.makeMove(loc);
    }
	
}