Skip to content

Instantly share code, notes, and snippets.

@zachdtaylor
Created October 26, 2021 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachdtaylor/18e5e62c51bf227bb80c89b2afa759d5 to your computer and use it in GitHub Desktop.
Save zachdtaylor/18e5e62c51bf227bb80c89b2afa759d5 to your computer and use it in GitHub Desktop.
One of the first classes I ever wrote (2011)
import java.util.ArrayList;
import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class Hornet extends Critter{
public Hornet(){
setColor(Color.yellow);
}
public ArrayList<Actor> getActors(){
ArrayList<Actor> actors = new ArrayList<Actor>();
Grid<Actor> g = getGrid();
Location b = getLocation().getAdjacentLocation(Location.AHEAD + 180);
if(g.isValid(b)){
if(g.get(b) == null);
else{
actors.add(g.get(b));
}}
return actors;
}
public void processActors(ArrayList<Actor> actors){
for(int x = 0; x < actors.size(); x++){
if(actors.get(x) instanceof Hornet);
else if(actors.get(x) instanceof Bug){
Actor actor = actors.get(x);
Grid<Actor> gr = actor.getGrid();
Location loc = actor.getLocation();
int dir = actor.getDirection();
actor.removeSelfFromGrid();
Actor actor2 = new EmptyBug();
actor2.setColor(actor.getColor());
actor2.setDirection(dir);
if(gr.get(loc)== null) actor2.putSelfInGrid(gr, loc);
}
else if(actors.get(x) instanceof CrabCritter){
Actor actor = actors.get(x);
Grid<Actor> gr = actor.getGrid();
Location loc = actor.getLocation();
int dir = actor.getDirection();
actor.removeSelfFromGrid();
Actor actor2 = new EmptyCrabCritter();
actor2.setColor(actor.getColor());
actor2.setDirection(dir);
if(gr.get(loc)== null) actor2.putSelfInGrid(gr, loc);
}
else if(actors.get(x) instanceof Critter){
Actor actor = actors.get(x);
Grid<Actor> gr = actor.getGrid();
Location loc = actor.getLocation();
int dir = actor.getDirection();
actor.removeSelfFromGrid();
Actor actor2 = new EmptyCritter();
actor2.setColor(actor.getColor());
actor2.setDirection(dir);
if(gr.get(loc)== null) actor2.putSelfInGrid(gr, loc);
}}
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment