TfGuy44
Full Member
Offline
Posts: 209
Re: help with my maze please
Reply #1 - Apr 18th , 2010, 9:26pm
class Grid { float x, y, w, h, v; Grid(float tempX, float tempY, float tempW, float tempH, int tempValue){ v = tempValue; x = tempX; y = tempY; w = tempW; h = tempH; } void display(){ noStroke(); if(v == 0){ fill(55); } if(v == 1){ fill(255, 255, 0); } rectMode(CORNER); rect(x, y, w, h); } } // End of class Grid class Maze { float x, y, w, h; color c; float s; Maze(float tempX, float tempY, float tempW, float tempH, color tempColor, float tempSpeed){ s = tempSpeed; x = tempX; y = tempY; w = tempW; h = tempH; c = tempColor; } void display(){ fill(c); noStroke(); ellipseMode(CORNER); ellipse(x, y, w, h); } void move( String direction ){ if(direction.equals("up")){ for(int n = 0; n < gridlines.length; n++){ if((maze.x == gridlines[n].x)&&(maze.y == gridlines[n].y)){ if(gridlines[n-10].v == 0){ maze.y = maze.y - s; return; } } } } if(direction.equals("down")){ for(int n = 0; n < gridlines.length; n++){ if((maze.x == gridlines[n].x)&&(maze.y == gridlines[n].y)){ if(gridlines[n + 10].v == 0.0){ maze.y = maze.y + s; return; } } } } if(direction.equals("right")){ for(int n = 0; n < gridlines.length; n++){ if((maze.x == gridlines[n].x)&&(maze.y == gridlines[n].y)){ if(gridlines[n+1].v == 0.0){ maze.x = maze.x + s; return; } } } } if(direction.equals("left")){ for(int n = 0; n < gridlines.length; n++){ if((maze.x == gridlines[n].x)&&(maze.y == gridlines[n].y)){ if(gridlines[n-1].v == 0.0){ maze.x = maze.x - s; return; } } } } } // End of move() } // End of class Maze Maze maze; Grid[] gridlines = new Grid [0] ; int[][] mymazegrid = { { 0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,1,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,1,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0 }, { 1,1,1,1,1,1,1,1,1,1 } }; // Grid size int gridW = 15; int gridH = 15; void setup(){ size(320,320); smooth(); background(80,100,100); for(int n = 0; n <= 9; n++){ for(int m = 0; m <= 9; m++){ Grid a = new Grid(n*gridW, m*gridH, gridW, gridH, mymazegrid[n][m] ); gridlines = (Grid[]) append (gridlines, a); } } maze = new Maze (15,15,15,15, color(100,100,100), 15); } // End setup() void draw(){ background(210); for(int n = 0; n < gridlines.length; n++){ gridlines[n].display(); } maze.display(); } // End draw() void keyPressed(){ if( key == CODED ){ if(keyCode == UP){ maze.move("up"); } if(keyCode == DOWN){ maze.move("down"); } if(keyCode == LEFT) { maze.move("left"); } if(keyCode == RIGHT) { maze.move("right"); } } } // End keyPressed()