Guest User

Papp | Easy BlueJ Code

a guest
Oct 23rd, 2019
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Instagram: rxphfy
  2.  
  3. //Roboter (class papp)
  4.  
  5. import java.util.Scanner;
  6. public class papp
  7. {
  8. // Instanzvariablen - ersetzen Sie das folgende Beispiel mit Ihren Variablen
  9. private Circle head;
  10. private Square body;
  11. private Square feet;
  12. public String name;
  13.  
  14. public papp()
  15. {
  16. head = new Circle();
  17. body = new Square();
  18. feet = new Square();
  19. head.changeColor("yellow");
  20. head.makeVisible();
  21. body.makeVisible();
  22. feet.changeColor("blue");
  23. feet.makeVisible();
  24. doMove();
  25. doAsk();
  26. }
  27.  
  28. private void doAsk(){
  29. System.out.println("How do you want your robot to be called?");
  30. Scanner namescan = new Scanner(System.in);
  31. name = namescan.next();
  32. }
  33.  
  34. private void doMove()
  35. {
  36. for (int a=0; a<2; a++){
  37. head.moveRight();
  38. feet.moveDown();
  39. }
  40. head.moveUp();
  41. body.moveDown();
  42. }
  43. public void Move(String direction, int distance)
  44. {
  45. switch (direction) {
  46. case "right":
  47. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  48. for(int a=0; a<distance; a++){
  49. head.slowMoveHorizontal(1);
  50. body.slowMoveHorizontal(1);
  51. feet.slowMoveHorizontal(1);
  52. }
  53. break;
  54. case "left":
  55. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  56. for(int a=0; a<distance; a++){
  57. head.slowMoveHorizontal(-1);
  58. body.slowMoveHorizontal(-1);
  59. feet.slowMoveHorizontal(-1);
  60. }
  61. break;
  62. case "up":
  63. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  64. for(int a=0; a<distance; a++){
  65. head.slowMoveVertical(-1);
  66. body.slowMoveVertical(-1);
  67. feet.slowMoveVertical(-1);
  68. }
  69. break;
  70. case "down":
  71. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  72. for(int a=0; a<distance; a++){
  73. head.slowMoveVertical(1);
  74. body.slowMoveVertical(1);
  75. feet.slowMoveVertical(1);
  76. }
  77.  
  78. break;
  79.  
  80. case "diagonal down right":
  81. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  82. for(int a=0; a<distance; a++){
  83. head.slowMoveVertical(1);
  84. head.slowMoveHorizontal(1);
  85. body.slowMoveVertical(1);
  86. body.slowMoveHorizontal(1);
  87. feet.slowMoveVertical(1);
  88. feet.slowMoveHorizontal(1);
  89. }
  90. break;
  91. case "diagonal down left":
  92. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  93. for(int a=0; a<distance; a++){
  94. head.slowMoveVertical(1);
  95. head.slowMoveHorizontal(-1);
  96. body.slowMoveVertical(1);
  97. body.slowMoveHorizontal(-1);
  98. feet.slowMoveVertical(1);
  99. feet.slowMoveHorizontal(-1);
  100. }
  101. break;
  102.  
  103. case "diagonal up right":
  104. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  105. for(int a=0; a<distance; a++){
  106. head.slowMoveVertical(-1);
  107. head.slowMoveHorizontal(1);
  108. body.slowMoveVertical(-1);
  109. body.slowMoveHorizontal(1);
  110. feet.slowMoveVertical(-1);
  111. feet.slowMoveHorizontal(1);
  112. }
  113. break;
  114.  
  115. case "diagonal up left":
  116. System.out.println(name + " is now moving " + direction + " for " + distance + "px");
  117. for(int a=0; a<distance; a++){
  118. head.slowMoveVertical(-1);
  119. head.slowMoveHorizontal(-1);
  120. body.slowMoveVertical(-1);
  121. body.slowMoveHorizontal(-1);
  122. feet.slowMoveVertical(-1);
  123. feet.slowMoveHorizontal(-1);
  124. }
  125.  
  126. default:
  127. System.out.println("There is only 'right', 'left', 'up','down','diagonal down right','diagonal down left','diagonal up right' and 'diagonal up right' !");
  128. break;
  129.  
  130.  
  131. }
  132. }
  133. }
RAW Paste Data