public   GenerateLevel(String filename) {

	        BufferedReader bufferedReader = null;
	        String line = "";
	        boolean findB = false;
	        boolean findV = false;
	        boolean findS = false;
	       // Level []levels = new Level[9];
	        int noOfLevelsGiven=0; // number of levels given in the file
	        int noOflevels =0; //counter to match number of levels given with number of levels in the mab
	        try {
if(line==null){
    System.out.println("inavlid map ");
    System.exit(0);
}
	            //Construct the BufferedReader object
	            bufferedReader = new BufferedReader(new FileReader(filename));
	            line=bufferedReader.readLine();
                    if(line==null){
    System.out.println("inavlid map number of levels isn't given");
    System.exit(0);
}
	            if(line.substring(0, line.indexOf("=")+1).equals("nlevels=")){
	                noOfLevelsGiven = Integer.parseInt(line.substring(line.indexOf('=')+1,line.length()));
	            }
	            else
	            {
	            	System.out.println("inavlid map number of levels isn't given");
                           System.exit(0);
	            }
	            // count levels to make sure it's valid

	            while (( (line=bufferedReader.readLine())!= null) ){
	                //Process the data, here we just print it out

	            	int stairsNum =0;
	            	int numOfLevel = 0;
	            	int dimension =0;
	            	String x=line.substring(0, line.indexOf("=")+1);
	                if(x.equals("level=")){ //to check level = is written it's also check if the dimension isn't correct if the loop has finished before or after dimension the it will be a part of map
	                	noOflevels++;

	                 numOfLevel =Integer.parseInt(line.substring(line.indexOf("=")+1, line.length()));//the index of the array "leve"

	                	line = bufferedReader.readLine();
	                	if(line.substring(0, line.indexOf("=")+1).equals("dimension=")){
	                	dimension =Integer.parseInt(line.substring(line.indexOf("=")+1, line.length()));//the dimension of 2D array "map"
	                	}
	                	else{
	                		System.out.println("Invalid map dimension isn't given");
	                	}
	                	line = bufferedReader.readLine();
	                	if(line.charAt(0)=='#'){
	                		line=bufferedReader.readLine();
	                	}
	                	//line = bufferedReader.readLine();
	                	if(line.equals("map=")){
	                	char [][] levelMap = new char [dimension][dimension];
	                	Level level = new Level (levelMap);
                               level.setLevelNo(numOfLevel);
	                	String [] stairs =new String [10];
		            	level.setStairs(stairs);
	                	int i=0;
	                	for(i =0 ;i <dimension ;i++){
                                   
	                		line = bufferedReader.readLine();
                                        
	                		if(line==null||line.length()!=dimension){
	                			System.out.println("invalid Map dimension given is greater than it is in the map");
	    	                	System.exit(0);
	                		}
	                		for (int j =0;j<dimension ;j++){
	                			char ele = line.charAt(j);
                                                //Element element = new Element(ele);
	                			levelMap[i][j]=ele;
	                		try{
	                			stairsNum=Integer.parseInt(ele+"");
	                			stairs[stairsNum]=i+" "+j;
	                		}catch(Exception e){

	                		}
	                			if(ele=='B'){
	                				if(findB==false){
	                				findB=true;
	                				}else{
	                					System.out.println("Invalid map 2 B found");
                                                                System.exit(0);
	                				}
	                			}
	                			if(ele=='V'){
	                				if(findV==false){
	                				findV=true;
	                				}else{
	                					System.out.println("Invalid map 2 v found");
                                                                System.exit(0);
	                				}
	                			}

	                			if(ele=='S'){
	                				if(findS==false){
	                				findS=true;

	                				level.hasSta(true);
                                                        level.setStaX(j);
	                				level.setStaY(i);
	                				}else{
	                					System.out.println("2 start found");
                                                                System.exit(0);
	                				}
	                			}

	                		}

	                	}
	                	if(i!=dimension){
	                		System.out.println("invalid Map dimension given is greater than it is in the map");
		                	System.exit(0);
	                	}
	                	levels [numOfLevel]=level; //-1 because it starts from 1 to 10 but the array is from 0 to 9
	                	}else{
	                		System.out.println("invalid Map map isn't M*M or doesn't match the dimensions given");
		                	System.exit(0);
	                	}
	                }else {
	                	System.out.println("invalid Map");
	                	System.exit(0);
	                }

	            }

	        } catch (FileNotFoundException ex) {
	            ex.printStackTrace();
	        } catch (IOException ex) {
	            ex.printStackTrace();
	        } finally {
	            //Close the BufferedReader
	            try {
	                if (bufferedReader != null)
	                    bufferedReader.close();
	            } catch (IOException ex) {
	                ex.printStackTrace();
	            }
	        }
	        if(findB==false||findV==false||findS==false){
	        	System.out.println("invalid Map");
            	System.exit(0);
	        }
	        if(noOflevels!=noOfLevelsGiven){
	        	System.out.println("invalid Map");
            	System.exit(0);
	        }

	    }