Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. /* PERMITTED COMMANDS
  2. move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
  3. JAVA
  4. if, while, for
  5.  
  6. To use this code in Greenfoot copy everything below to */
  7.  
  8. class MyClara extends Clara {
  9. void run() {
  10. int b = 0;
  11. //Clara uses AI() function, along with the variable b, which helps her to
  12. //change the lane and her direction( East or West ). She starts with facing
  13. //towards East and then store 1 as a value in b, so when next time loop
  14. //executes turns towards West, changing the value of b to 0. This loop
  15. //continues until their is a tree infront of her.
  16. while(!treeFront())
  17. {
  18. AI();
  19. if (b == 0)
  20. {
  21. if(!treeRight())
  22. {
  23. turnRight();
  24. move();
  25. turnRight();
  26. b = 1;
  27. }
  28. }
  29. else if (b == 1)
  30. {
  31. if(!treeLeft())
  32. {
  33. turnLeft();
  34. move();
  35. turnLeft();
  36. b = 0;
  37. }
  38. }
  39. }
  40.  
  41. }
  42.  
  43. //Using this function clara moves until their is a tree infront of her, along
  44. //with executing IQ() function.
  45. void AI()
  46. {
  47. while(!treeFront())
  48. {
  49. IQ();
  50. move();
  51. }
  52. IQ();
  53. }
  54.  
  55. //This function is for clara to remove leaf if their is one underneath her and if
  56. //not, she is places a leaf undernath her.
  57. void IQ()
  58. {
  59. if(!onLeaf())
  60. {
  61. putLeaf();
  62. }
  63. else
  64. {
  65. removeLeaf();
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement