Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void walkTillWall() {
- // Berechne die neue Position
- int neuX = (posX + deltaX + columns) % columns;
- int neuY = (posY + deltaY + rows) % rows;
- // Gehe auf die neue Position wenn möglich
- while ( world[neuY][neuX] != '#') {
- world[posY][posX] = pencil;
- posX = neuX;
- posY = neuY;
- }
- }
- public static void go() {
- // Berechne die neue Position
- int neuX = (posX + deltaX + columns) % columns;
- int neuY = (posY + deltaY + rows) % rows;
- // Gehe auf die neue Position wenn möglich
- if ( world[neuY][neuX] != '#') {
- world[posY][posX] = pencil;
- posX = neuX;
- posY = neuY;
- }
- }
- public static void execute(String cmds) {
- int pos;
- char command;
- // Durchlaufe cmds zeichenweise
- for ( pos = 0; pos < cmds.length(); pos = pos + 1 ) {
- command = cmds.charAt(pos);
- // Führe alle Kommandos aus
- switch(command) {
- case 'l':
- turnLeft();
- break;
- case 'r':
- turnRight();
- break;
- case 'v':
- go();
- break;
- case 'p':
- pencil();
- break;
- //stern soll nur ausgefuehrt werden, wenn ein zeichen davor ein 'v' benutzt wurde
- case '*':
- if(cmds.charAt(pos-1) == 'v') {
- walkTillWall();
- }
- break;
- }
- // Zeige den neuen Zustand und warte
- showWorld();
- wait(duration);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement