Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Activity_34 here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import info.gridworld.actor.Actor;
- import info.gridworld.actor.Rock;
- import info.gridworld.actor.Critter;
- import info.grid.Location;
- import java.util.ArrayList;
- // Excersise 3
- public class RockHound extends Critter
- {
- public void processActors(ArrayListRui actors)
- {
- for (Actor rui : actors)
- {
- if (rui instanceof Rock)
- rui.removesSelfFromGrid();
- }
- }
- }
- //Excercise 4
- public class BlusterCritter extends Critter
- {
- private int rui;
- public BlusterCritter(int c)
- {
- super();
- rui = c;
- }
- public ArrayListrui getActors()
- {
- ArrayListrui actors = new ArrayListrui();
- Location loc = getLocation();
- for(int r = loc.getRow() - 2; r <= loc.getRow() + 2; r++ )
- for(int c = loc.getCol() - 2; c <= loc.getCol() + 2; c++)
- {
- Location tempLoc = new Location(r,c);
- if(getGrid().isValid(tempLoc))
- {
- Actor a = getGrid().get(tempLoc);
- if(a != null && a != this)
- actor.add(a);
- }
- }
- return actors;
- }
- public void processActors(ArrayListrui actors)
- {
- int count = 0;
- for(Actor rui; actors)
- if(rui instanceof Critter)
- count++;
- if(count < rui)
- lightit();
- else
- darkit();
- }
- private void darkit()
- {
- Color c = getColor();
- int red = c.getRed();
- int green = c.getGreen();
- int blue = c.getBlue();
- if (red > 0) red--;
- if (green > 0) green--;
- if (blue > 0) blue --;
- setColor(new Color(red, green, blue));
- }
- private void lightit()
- {
- Color c = getColor();
- int red = c.getRed();
- int green = c.getGreen();
- int blue = c.getBlue();
- if(red < 100) red++;
- if(green < 100) green++;
- if(blue < 100) blue++;
- setColor(new Color(red, green, blue)
- }
- }
Add Comment
Please, Sign In to add comment