Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1.   public static void walkTillWall() {
  2.     // Berechne die neue Position
  3.     int neuX = (posX + deltaX + columns) % columns;
  4.     int neuY = (posY + deltaY + rows) % rows;
  5.  
  6.     // Gehe auf die neue Position wenn möglich
  7.     while ( world[neuY][neuX] != '#') {
  8.       world[posY][posX] = pencil;
  9.       posX = neuX;
  10.       posY = neuY;
  11.     }
  12.   }
  13.  
  14.   public static void go() {
  15.     // Berechne die neue Position
  16.     int neuX = (posX + deltaX + columns) % columns;
  17.     int neuY = (posY + deltaY + rows) % rows;
  18.  
  19.     // Gehe auf die neue Position wenn möglich
  20.     if ( world[neuY][neuX] != '#') {
  21.       world[posY][posX] = pencil;
  22.       posX = neuX;
  23.       posY = neuY;
  24.     }
  25.   }
  26.  
  27.  public static void execute(String cmds) {
  28.     int pos;
  29.     char command;
  30.  
  31.     // Durchlaufe cmds zeichenweise
  32.     for ( pos = 0; pos < cmds.length(); pos = pos + 1 ) {
  33.       command = cmds.charAt(pos);
  34.  
  35.       // Führe alle Kommandos aus
  36.       switch(command) {
  37.         case 'l':
  38.           turnLeft();
  39.           break;
  40.         case 'r':
  41.           turnRight();
  42.           break;
  43.         case 'v':
  44.           go();
  45.           break;
  46.         case 'p':
  47.           pencil();
  48.           break;
  49.         //stern soll nur ausgefuehrt werden, wenn ein zeichen davor ein 'v' benutzt wurde
  50.         case '*':
  51.           if(cmds.charAt(pos-1) == 'v') {
  52.             walkTillWall();
  53.           }
  54.           break;
  55.       }
  56.  
  57.       // Zeige den neuen Zustand und warte
  58.       showWorld();
  59.       wait(duration);
  60.     }
  61.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement