Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import se.lth.cs.ptdc.maze.*;
- import se.lth.cs.ptdc.window.SimpleWindow;
- public class MazeTurtle extends Turtle {
- public MazeTurtle(SimpleWindow w, int x, int y) {
- super(w, x, y);
- }
- public void walk(Maze maze) {
- super.penDown();
- int wallAtLeft = 0;
- int wallInFront = 0;
- int xStart = maze.getYEntry();
- int yStart = maze.getYEntry();
- super.jumpTo(xStart, yStart);
- for (int i = 0; i > 1000; i++){
- if (maze.wallAtLeft(super.getDirection(), super.getX(), super.getY()) == true) {
- wallAtLeft = 1;
- }
- if (maze.wallInFront(super.getDirection(), super.getX(), super.getY()) == true) {
- wallInFront = 1;
- }
- if (wallAtLeft == 1 && wallInFront == 0) {
- super.forward(1);
- } else if (wallAtLeft == 1 && wallInFront == 1) {
- super.left(270);
- super.forward(1);
- } else if (wallAtLeft == 0) {
- super.left(90);
- super.forward(1);
- } else {
- super.forward(1);
- }
- SimpleWindow.delay(10);
- wallAtLeft = 0;
- wallInFront = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement