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:13] frchrismake_a_maze [2019/08/17 11:35] frchris
Line 4: Line 4:
  
 ====== 3 Ways to Make Walls ====== ====== 3 Ways to Make Walls ======
-  - World.placeNSWall(), World.placeEWWall() have three parameters (sometimes called arguments).  You need to tell these methods three integers,  For a East-West Street: the number of the street, the number of the Avenue, and the length of the wall (either going East or North, depending on the direction. Once you get the hang of reading the [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/kareltherobot/World.html|API]] of a class you can quickly use or build upon other people's code (or even your own).+  - World.placeNSWall(), World.placeEWWall() have three parameters (sometimes called arguments).  You need to tell these methods three integers,  For a East-West Street: the number of the street, the number of the Avenue, and the length of the wall (either going East or North, depending on the direction. Once you get the hang of reading the [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/kareltherobot/World.html|API]] of a class you can quickly use or build upon other people's code (or even your own). <code java>import kareltherobot.*; 
 +public class Walls implements Directions { 
 + public static void task() { 
 + Robot karel = new Robot(1, 2, East, 0); 
 + karel.move();     
 + karel.move();    
 + karel.pickBeeper();                     
 + karel.move();    
 + karel.turnLeft();    
 + karel.move(); 
 + karel.move();    
 + karel.putBeeper();   
 + karel.move(); 
 + karel.turnOff(); 
 + 
 +
 + // Main entry point 
 + public static void main(String[] args) { 
 + World.setDelay(150); 
 + World.setSize(8, 9); 
 + //World.readWorld("first.kwld");   
 + World.placeBeepers(1, 4, 1); 
 + World.placeEWWall(3, 1, 3); 
 + World.placeNSWall(1,6, 5); 
 + World.placeEWWall(6, 1, 6); 
 + World.setVisible(); 
 + task(); 
 +
 +}</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 file a name, and add it to your project and use the call <code java> World.readWorld("second.kwld"); </code>
make_a_maze.txt · Last modified: 2021/09/05 13:16 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki