Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1.     BufferedReader txt = new BufferedReader( new FileReader( file ) );  
  2.     String line;
  3.     maze = new Cell[size][size];
  4.     int x;
  5.     int y;
  6.     String left = "left";
  7.     String right = "right";
  8.     String top = "top";
  9.     String bottom = "bottom";
  10.    
  11.          while( ( line = txt.readLine() ) != null ){
  12.              
  13.          StringTokenizer t = new StringTokenizer(line, " ");            
  14.             x = Integer.parseInt(t.nextToken());
  15.             y = Integer.parseInt(t.nextToken());
  16.  
  17.            if ( t.hasMoreTokens()){
  18.             String operation = t.nextToken();
  19.            
  20.                 switch( operation ){
  21.                    
  22.                     case "PD":
  23.  
  24.                         maze[x][y] = new Cell();
  25.                         maze[x][y].makeWall(top);
  26.                         maze[x][y].makeWall(left);
  27.                        
  28.                             if ( x != 0 && y != 0){
  29.                                 maze[x][y-1].makeWall(bottom);
  30.                                 maze[x-1][y].makeWall(right);
  31.                             }
  32.                             if ( x == 0 && y != 0 ){
  33.                                 maze[x][y-1].makeWall(bottom);
  34.                             }
  35.                             if ( x != 0 && y == 0 ){
  36.                                 maze[x-1][y].makeWall(right);
  37.                             }
  38.                         break;
  39.                        
  40.                     case "P":
  41.                        
  42.                         maze[x][y] = new Cell();
  43.                         maze[x][y].makeWall(top);
  44.                            
  45.                             if ( x != 0 && y != 0){
  46.                                 maze[x][y-1].makeWall(bottom);
  47.                             }
  48.                            if ( x == 0 && y != 0 ){
  49.                                 maze[x][y-1].makeWall(bottom);
  50.                             }                          
  51.                         break;
  52.                        
  53.                     case "D":
  54.                        
  55.                         maze[x][y] = new Cell();
  56.                         maze[x][y].makeWall(left);
  57.                        
  58.                         if ( x != 0 && y != 0){
  59.                                 maze[x-1][y].makeWall(right);
  60.                             }                          
  61.                             if ( x != 0 && y == 0 ){
  62.                                 maze[x-1][y].makeWall(right);
  63.                             }
  64.                         break;
  65.                 }
  66.            }
  67.            else {
  68.                maze[x][y] = new Cell();
  69.            }
  70.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement