User Tools

Site Tools


make_a_maze

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
make_a_maze [2019/08/17 11:22] frchrismake_a_maze [2019/08/22 18:52] frchris
Line 1: Line 1:
 +====== Make a Maze ======
 +Make a Maze with 4 to 6 walls and one beeper.  Place the Robot in the start position, and the beeper in the end position. 
 +
 +You can post your .java file in [[https://drive.google.com/open?id=10dAqaHXdDkvM9kT7neze5SXVaUXAaqQe|Google classroom]].  
 +
 +Make your plan and exchange it with another student.  He has to make your maze, and you have to make his.  Help one another.  Start with simplified task that turns off right after the robot is made.  After the maze is correct, you can finish the task by adding the ''move()'' and ''turnLeft()'' methods for the robot to run the maze.
 + 
 Walls or obstacles are pared of the World class and can be placed in a NS or a EW direction, and have length.  Here is a link to the API which shows all the constructors and methods that belong to the [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/kareltherobot/World.html|World]] class. Walls or obstacles are pared of the World class and can be placed in a NS or a EW direction, and have length.  Here is a link to the API which shows all the constructors and methods that belong to the [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/kareltherobot/World.html|World]] class.
  
 World.setSize(int numberOfStreets, int numberOfAvenues) will change the size of the World. World.setSize(int numberOfStreets, int numberOfAvenues) will change the size of the World.
 +
 +It is actually easier to see the available methods and their parameters in the [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/index.html|API]]
  
 ====== 3 Ways to Make Walls ====== ====== 3 Ways to Make Walls ======
Line 7: Line 16:
 public class Walls implements Directions { public class Walls implements Directions {
  public static void task() {  public static void task() {
- Robot karel = new Robot(1, 2, East, 0); + Robot robby = new Robot(1, 2, East, 0); 
- karel.move();     + robby.move();     
- karel.move();    + robby.move();    
- karel.pickBeeper();                     + robby.pickBeeper();                     
- karel.move();    + robby.move();    
- karel.turnLeft();    + robby.turnLeft();    
- karel.move(); + robby.move(); 
- karel.move();    + robby.move();    
- karel.putBeeper();   + robby.putBeeper();   
- karel.move(); + robby.move(); 
- karel.turnOff();+ robby.turnOff();
  
  }  }
Line 24: Line 33:
  World.setDelay(150);  World.setDelay(150);
  World.setSize(8, 9);  World.setSize(8, 9);
- //World.readWorld("first.kwld");   
  World.placeBeepers(1, 4, 1);  World.placeBeepers(1, 4, 1);
  World.placeEWWall(3, 1, 3);  World.placeEWWall(3, 1, 3);
Line 33: Line 41:
  }  }
 }</code> }</code>
 +  - You can make a long string and send it all at once to the World.  :<code java>public static void main(String[] args) { 
 + String hurdles = "streets 8\n" +  
 + "avenues 9\n" +  
 + "eastwestwalls 3 1 3\n" +  
 + "northsouthwalls 1 6 5\n" +  
 + "eastwestwalls 6 1 6\n" +  
 + "beepers 1 4 1"; 
 + World.getWorld(hurdles); 
 + World.setVisible(); 
 +        task(); 
 + }</code> 
 +  - You can place a text file with string commands like this: <code> KarelWorld 
 +streets 8 
 +avenues 9 
 +beepers 1 4 1 
 +eastwestwalls 3 1 3 
 +northsouthwalls 1 6 5 
 +eastwestwalls 6 1 6</code>Give the text a file a name (like ''maze.txt'') , and add it to your project and use the call <code java> World.readWorld("maze.txt"); </code>This way has extra steps, but once you make this text file, you can easily send your maze to someone else and have them figure out a way to navigate it.  You can actually use the first method, and then use the method call ''World.saveWorld("myMaze.txt");'' to make this text file.  
make_a_maze.txt · Last modified: 2021/09/05 13:16 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki