Advertisement
Guest User

aufgabe 9

a guest
Nov 24th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. int obstaclesCounter = 0;
  2. int i;
  3. int j;
  4. putLeaf();
  5. int length = countLength();
  6. turnRight();
  7. int width = countWidth();
  8. removeLeaf();
  9. turnLeft();
  10. for (j = 0; j < width; j++) {
  11. for (i = 0; i < (length - 1); i++) {
  12. if (!mushroomFront() && !treeFront()) {
  13. move();
  14. }
  15. else {
  16. obstaclesCounter++;
  17. goAround();
  18. i++;
  19. }
  20. }
  21. if (i < length) {
  22. goDownBack();
  23. }
  24. else {
  25. goDownFront();
  26. }
  27. }
  28. showMessage("# Hindernisse: %d", obstaclesCounter);
  29. }
  30.  
  31. int countLength() {
  32. int i = 0;
  33. if (treeFront() || mushroomFront()) {
  34. goAround();
  35. i = i + 2;
  36. }
  37. else {
  38. move();
  39. i++;
  40. }
  41.  
  42. while (!onLeaf()) {
  43. if (treeFront() || mushroomFront()) {
  44. goAround();
  45. i = i + 2;
  46. }
  47. else {
  48. move();
  49. i++;
  50. }
  51. }
  52. return i;
  53. }
  54.  
  55. int countWidth() {
  56. int j = 0;
  57. if (treeFront() || mushroomFront()) {
  58. goAround();
  59. j = j + 2;
  60. }
  61. else {
  62. move();
  63. j++;
  64. }
  65.  
  66. while (!onLeaf()) {
  67. if (treeFront() || mushroomFront()) {
  68. goAround();
  69. j = j + 2;
  70. }
  71. else {
  72. move();
  73. j++;
  74. }
  75. }
  76. return j;
  77. }
  78.  
  79. void goAround() {
  80. turnRight();
  81. move();
  82. turnLeft();
  83. move();
  84. move();
  85. turnLeft();
  86. move();
  87. turnRight();
  88. }
  89.  
  90. void goDownBack() {
  91. if (!(treeFront() && mushroomFront())) {
  92. move();
  93. turnRight();
  94. if (!(treeFront() || mushroomFront())) {
  95. move();
  96. turnLeft();
  97. }
  98. else {
  99. turnLeft();
  100. move();
  101. turnRight();
  102. move();
  103. turnLeft();
  104. }
  105. }
  106. else {
  107. turnRight();
  108. move();
  109. turnLeft();
  110. move();
  111. }
  112. }
  113.  
  114. void goDownFront() {
  115. turnRight();
  116. move();
  117. turnLeft();
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement