Guest User

Untitled

a guest
Apr 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. /**
  2. * Write a description of class Activity_34 here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import info.gridworld.actor.Actor;
  8. import info.gridworld.actor.Rock;
  9. import info.gridworld.actor.Critter;
  10. import info.grid.Location;
  11. import java.util.ArrayList;
  12. // Excersise 3
  13. public class RockHound extends Critter
  14. {
  15. public void processActors(ArrayListRui actors)
  16. {
  17. for (Actor rui : actors)
  18. {
  19. if (rui instanceof Rock)
  20. rui.removesSelfFromGrid();
  21. }
  22. }
  23. }
  24.  
  25. //Excercise 4
  26.  
  27. public class BlusterCritter extends Critter
  28. {
  29. private int rui;
  30.  
  31. public BlusterCritter(int c)
  32. {
  33. super();
  34. rui = c;
  35. }
  36. public ArrayListrui getActors()
  37. {
  38. ArrayListrui actors = new ArrayListrui();
  39.  
  40. Location loc = getLocation();
  41. for(int r = loc.getRow() - 2; r <= loc.getRow() + 2; r++ )
  42. for(int c = loc.getCol() - 2; c <= loc.getCol() + 2; c++)
  43. {
  44. Location tempLoc = new Location(r,c);
  45. if(getGrid().isValid(tempLoc))
  46. {
  47. Actor a = getGrid().get(tempLoc);
  48. if(a != null && a != this)
  49. actor.add(a);
  50. }
  51. }
  52. return actors;
  53. }
  54. public void processActors(ArrayListrui actors)
  55. {
  56. int count = 0;
  57. for(Actor rui; actors)
  58. if(rui instanceof Critter)
  59. count++;
  60. if(count < rui)
  61. lightit();
  62. else
  63. darkit();
  64. }
  65. private void darkit()
  66. {
  67. Color c = getColor();
  68. int red = c.getRed();
  69. int green = c.getGreen();
  70. int blue = c.getBlue();
  71.  
  72. if (red > 0) red--;
  73. if (green > 0) green--;
  74. if (blue > 0) blue --;
  75.  
  76. setColor(new Color(red, green, blue));
  77. }
  78. private void lightit()
  79. {
  80. Color c = getColor();
  81. int red = c.getRed();
  82. int green = c.getGreen();
  83. int blue = c.getBlue();
  84.  
  85. if(red < 100) red++;
  86. if(green < 100) green++;
  87. if(blue < 100) blue++;
  88.  
  89. setColor(new Color(red, green, blue)
  90. }
  91. }
Add Comment
Please, Sign In to add comment