There seems to be a problem with my code. For some reason my window will not popup for some reason. I will only type in the code that seems to be wrong. No error pops up its just that nothing will happen. I just implemented a random maze generation code in the maps and mapdirector files but nothing happens after i implemented the new code. Please help or at least tell me whats wrong.
Maps.java
import java.util.*;
public class Maps{
private int SizeX = 33;
private int SizeY = 33;
public short RandomMaze[][] = new short[SizeX][SizeY];
private Random r = new Random();
public Maps(){
GenerateMaze(r.nextInt(70) + 30);
}
public void GenerateMaze(int StraightNess){
int CurrentX = 50;
int CurrentY = 50;
boolean TimeUp = false;
boolean tocheckDirection = false;
boolean Moved = false;
boolean ChangeDirection = false;
boolean Done = false;
int Dir = 0;
int LastDirection = r.nextInt(4);
int Open = 2;
int NotOpen = 3;
int North = Open;
int South = Open;
int East = Open;
int West = Open;
short Flr = 0;
short Wall = 1;
long LastDrawTimer = 0;
for(int y = 0;y < RandomMaze.length;y++){
for(int x = 0;x < RandomMaze[y].length;x++){
RandomMaze[y][x] = 1;
}
}
CurrentX = 50;
CurrentY = 50;
while(TimeUp != true){
if(tocheckDirection != true){
Moved = false;
ChangeDirection = true;
if(r.nextInt(100) < StraightNess){
ChangeDirection = false;
Dir = LastDirection;
}
while(Moved != true){
if(ChangeDirection == true){
Dir = r.nextInt(4);
LastDirection = Dir;
}
}
ChangeDirection = true;
switch(Dir){
case 0:
if(North == Open){
Moved = true;
CurrentY--;
}
break;
case 1:
if(South == Open){
Moved = true;
CurrentY++;
}
break;
case 2:
if(East == Open){
Moved = true;
CurrentX++;
}
break;
case 3:
if(West == Open){
Moved = true;
CurrentX--;
}
break;
}
}
RandomMaze[CurrentX][CurrentY] = Flr;
LastDrawTimer = System.currentTimeMillis();
}
North = NotOpen;
South = NotOpen;
East = NotOpen;
West = NotOpen;
if(CurrentY - 2 < 0){
North = NotOpen;
}else if(RandomMaze[CurrentX][CurrentY - 1] == Wall && RandomMaze[CurrentX][CurrentY - 2] == Wall){
if(RandomMaze[CurrentX - 1][CurrentY - 1] == Wall && RandomMaze[CurrentX + 1][CurrentY - 1] == Wall){
North = Open;
}else{
North = NotOpen;
}
}
if(CurrentY + 2 < 0){
South = NotOpen;
}else if(RandomMaze[CurrentX][CurrentY + 1] == Wall && RandomMaze[CurrentX][CurrentY + 2] == Wall){
if(RandomMaze[CurrentX - 1][CurrentY + 1] == Wall && RandomMaze[CurrentX + 1][CurrentY + 1] == Wall){
South = Open;
}else{
South = NotOpen;
}
}
if(CurrentX + 2 < 0){
East = NotOpen;
}else if(RandomMaze[CurrentX + 1][CurrentY] == Wall && RandomMaze[CurrentX + 2][CurrentY] == Wall){
if(RandomMaze[CurrentX + 1][CurrentY - 1] == Wall && RandomMaze[CurrentX + 1][CurrentY + 1] == Wall){
East = Open;
}else{
East = NotOpen;
}
}
if(CurrentX - 2 < 0){
West = NotOpen;
}else if(RandomMaze[CurrentX - 1][CurrentY] == Wall && RandomMaze[CurrentX - 2][CurrentY] == Wall){
if(RandomMaze[CurrentX - 1][CurrentY - 1] == Wall && RandomMaze[CurrentX - 1][CurrentY + 1] == Wall){
West = Open;
}else{
West = NotOpen;
}
}
if(System.currentTimeMillis() - LastDrawTimer > 100){TimeUp = true;}
if(North == NotOpen && South == NotOpen && East == NotOpen && West == NotOpen && TimeUp == false){
Done = false;
while(Done != true){
CurrentX = 50;
CurrentY = 50;
if(RandomMaze[CurrentX][CurrentY] == Flr){Done = true;}
}
}
}
}
MapDirector.java
import java.util.*;
import java.awt.*;
public class MapDirector{
Maps M = new Maps();
Prey prey;
ArrayList<Floor> floor = new ArrayList<Floor>();
ArrayList<Wall> wall = new ArrayList<Wall>();
ArrayList<Wall> wallT = new ArrayList<Wall>();
ArrayList<Exit> exit = new ArrayList<Exit>();
private short Maze1[][] = M.RandomMaze;
private Random r = new Random();
public static boolean WIN = false;
public MapDirector(){
M.GenerateMaze(r.nextInt(70) + 30);
prey = new Prey(50,50,500,270);
for(int y = 0;y < Maze1.length;y++){
for(int x = 0;x < Maze1[y].length;x++){
if(Maze1[y][x] == 0){floor.add(new Floor(x*50,y*46));}
if(Maze1[y][x] == 1){wall.add(new Wall(x*50,y*46,1));wall.add(new Wall(x*50,y*46-4,1));
wall.add(new Wall(x*50,y*46-8,1));wallT.add(new Wall(x*50,y*46-12,1));}
if(Maze1[y][x] == 2){floor.add(new Floor(x*50,y*46));}
}
}
}
public void WallCollision(Wall w){
Rectangle wall = new Rectangle(w.x,w.y,50,50);
Rectangle U = new Rectangle(Prey.x + 20,Prey.y + 10,13,5);
Rectangle D = new Rectangle(Prey.x + 20,Prey.y + 20,13,5);
Rectangle L = new Rectangle(Prey.x + 17,Prey.y + 20,5,5);
Rectangle R = new Rectangle(Prey.x + 30,Prey.y + 20,5,5);
if(U.intersects(wall)){Prey.y += 2;Prey.gy -= 2;}
else if(D.intersects(wall)){Prey.y -= 2;Prey.gy += 2;}
else if(L.intersects(wall)){Prey.x += 2;Prey.gx -= 2;}
else if(R.intersects(wall)){Prey.x -= 2;Prey.gx += 2;}
}
public void Exit(Exit e){
Rectangle exit = new Rectangle(e.x,e.y,50,50);
Rectangle PREY = new Rectangle(Prey.x,Prey.y,50,50);
if(PREY.intersects(exit)){WIN = true;}
}
public void paint(Graphics g,Graphics2D g2d){
g2d = (Graphics2D) g;
g2d.translate(Prey.gx,Prey.gy);
for(Floor f : floor){g2d.drawImage(Floor.floor,f.x,f.y,50,50,null);}
for(Wall w : wall){g2d.drawImage(Wall.wall,w.x,w.y,50,50,null);}
prey.paint(g,g2d);
for(Wall w : wallT){g2d.drawImage(Wall.wall,w.x,w.y,50,50,null);}
}
}