Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import se.lth.cs.ptdc.maze.*;
  2. import se.lth.cs.ptdc.window.SimpleWindow;
  3.  
  4. public class MazeTurtle extends Turtle {
  5.     public MazeTurtle(SimpleWindow w, int x, int y) {
  6.         super(w, x, y);
  7.     }
  8.  
  9.     public void walk(Maze maze) {
  10.         super.penDown();
  11.         int wallAtLeft = 0;
  12.         int wallInFront = 0;
  13.         int xStart = maze.getYEntry();
  14.         int yStart = maze.getYEntry();
  15.         super.jumpTo(xStart, yStart);
  16.         for (int i = 0; i > 1000; i++){
  17.  
  18.         if (maze.wallAtLeft(super.getDirection(), super.getX(), super.getY()) == true) {
  19.             wallAtLeft = 1;
  20.         }
  21.         if (maze.wallInFront(super.getDirection(), super.getX(), super.getY()) == true) {
  22.             wallInFront = 1;
  23.         }
  24.  
  25.         if (wallAtLeft == 1 && wallInFront == 0) {
  26.             super.forward(1);
  27.  
  28.         } else if (wallAtLeft == 1 && wallInFront == 1) {
  29.             super.left(270);
  30.             super.forward(1);
  31.  
  32.         } else if (wallAtLeft == 0) {
  33.             super.left(90);
  34.             super.forward(1);
  35.         } else {
  36.             super.forward(1);
  37.         }
  38.         SimpleWindow.delay(10);
  39.         wallAtLeft = 0;
  40.         wallInFront = 0;
  41.     }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement