MazeSolver Phase 1

Read the layout file and display the maze

MazeSolver tab

// MazeSolver

int Cols;  // number across
int Rows;  // number down
float BWidth;  // width of a block
float BHeight; // height of a block

// Starting position
int StartRow;
int StartCol;

// Enumerations
int WALL = 0;
int PATH = 1;
int AVAIL = 2;
int VISITED = 3;
int END = 4;

// Colors
color BLACK = color(0);          // WALL
color WHITE = color(255);        // AVAIL
color GREY = color(170);          // VISITED
color BLUE = color(100,100,255);  // PATH
color RED = color(255,0,0);       // END
color GREEN = color(0,255,0);     // Starting block


// Here are the blocks....
Block[][] blocks;

void setup() {
  size(600,600);
  background(0);
  ReadMaze("simple-dw.txt");
}

void ReadMaze(String filename) {
  String[] lines = loadStrings(filename);
  Cols = lines[0].length();
  Rows = lines.length;
  BWidth = width / Cols;
  BHeight = height / Rows;
  
  // Create blocks
  blocks = new Block[Rows][Cols];

  // Your spotless code here in actually creating 
  //  and displaying the blocks ...

}
Block tab


class Block {
  float xpos, ypos;
  float bwidth, bheight;
  int type;    // WALL, PATH, AVAIL, VISITED, END
  color c;
  
  Block(float x, float y, float in_bwidth, float in_bheight, 
        int in_type, color in_c) {
    xpos = x;
    ypos = y;
    bwidth = in_bwidth;
    bheight = in_bheight;
    type = in_type;
    c = in_c;
  }
  
  void display() {
    stroke(color(0));
    fill(c);
    rect(xpos,ypos,bwidth,bheight);
  }
 
}