Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Instagram: rxphfy
- //Roboter (class papp)
- import java.util.Scanner;
- public class papp
- {
- // Instanzvariablen - ersetzen Sie das folgende Beispiel mit Ihren Variablen
- private Circle head;
- private Square body;
- private Square feet;
- public String name;
- public papp()
- {
- head = new Circle();
- body = new Square();
- feet = new Square();
- head.changeColor("yellow");
- head.makeVisible();
- body.makeVisible();
- feet.changeColor("blue");
- feet.makeVisible();
- doMove();
- doAsk();
- }
- private void doAsk(){
- System.out.println("How do you want your robot to be called?");
- Scanner namescan = new Scanner(System.in);
- name = namescan.next();
- }
- private void doMove()
- {
- for (int a=0; a<2; a++){
- head.moveRight();
- feet.moveDown();
- }
- head.moveUp();
- body.moveDown();
- }
- public void Move(String direction, int distance)
- {
- switch (direction) {
- case "right":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveHorizontal(1);
- body.slowMoveHorizontal(1);
- feet.slowMoveHorizontal(1);
- }
- break;
- case "left":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveHorizontal(-1);
- body.slowMoveHorizontal(-1);
- feet.slowMoveHorizontal(-1);
- }
- break;
- case "up":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveVertical(-1);
- body.slowMoveVertical(-1);
- feet.slowMoveVertical(-1);
- }
- break;
- case "down":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveVertical(1);
- body.slowMoveVertical(1);
- feet.slowMoveVertical(1);
- }
- break;
- case "diagonal down right":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveVertical(1);
- head.slowMoveHorizontal(1);
- body.slowMoveVertical(1);
- body.slowMoveHorizontal(1);
- feet.slowMoveVertical(1);
- feet.slowMoveHorizontal(1);
- }
- break;
- case "diagonal down left":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveVertical(1);
- head.slowMoveHorizontal(-1);
- body.slowMoveVertical(1);
- body.slowMoveHorizontal(-1);
- feet.slowMoveVertical(1);
- feet.slowMoveHorizontal(-1);
- }
- break;
- case "diagonal up right":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveVertical(-1);
- head.slowMoveHorizontal(1);
- body.slowMoveVertical(-1);
- body.slowMoveHorizontal(1);
- feet.slowMoveVertical(-1);
- feet.slowMoveHorizontal(1);
- }
- break;
- case "diagonal up left":
- System.out.println(name + " is now moving " + direction + " for " + distance + "px");
- for(int a=0; a<distance; a++){
- head.slowMoveVertical(-1);
- head.slowMoveHorizontal(-1);
- body.slowMoveVertical(-1);
- body.slowMoveHorizontal(-1);
- feet.slowMoveVertical(-1);
- feet.slowMoveHorizontal(-1);
- }
- default:
- System.out.println("There is only 'right', 'left', 'up','down','diagonal down right','diagonal down left','diagonal up right' and 'diagonal up right' !");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement