Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void readMap(String fileName) {
- FileReader fr;
- int layerCounter = 0;
- int lineLength = 0;
- String mapString = "";
- String newLine = "";
- int charCounter = 0;
- boolean notFinishedReading = true;
- try {//Try catch to catch any IO errors
- fr = new FileReader(fileName);//File reader to read in the file
- BufferedReader br = new BufferedReader(fr);//Buffered reader to read in line by line
- setMapName(br.readLine());//First line is the map name
- setGoldRequired(Integer.parseInt(br.readLine()));//Second line is the gold required
- while(notFinishedReading == true) {
- newLine = br.readLine();//Reads next line of files
- if(newLine != null) {//Ensures that the whole map has not been read already
- lineLength = newLine.length();//Length of each line
- mapString = mapString + newLine;//Writes map onto one string
- layerCounter = layerCounter + 1;//Counts how many lines were taken in
- }
- else {//If map is read
- notFinishedReading = false;//Stop looping
- }
- }
- map = new char[layerCounter][lineLength];//Set map to have new limits to match new map
- for(int i = 0; i < layerCounter; i++) {//Nested loops to
- for(int j = 0; j < lineLength; j++) {
- map[i][j] = mapString.charAt(charCounter);
- charCounter++;
- }
- }
- setMap(map);
- br.close();
- fr.close();
- } catch (IOException e) {//In case of IO error
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement