Advertisement
Guest User

mapa

a guest
Nov 28th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1.  
  2. package Main;
  3.  
  4. import java.awt.*;
  5. import java.io.*;
  6. import java.util.*;
  7.  
  8. import javax.swing.*;
  9.  
  10. public class Background {
  11.  
  12.     private BufferedReader br;
  13.     private String map[][];
  14.     private Image path,wall1,wall2;
  15.                  
  16.  
  17.     public Background(){
  18.        
  19.         ImageIcon img= new ImageIcon(".//map//0.png");
  20.         path = img.getImage();
  21.         img= new ImageIcon(".//map//1.png");
  22.         wall1 = img.getImage();
  23.         img= new ImageIcon(".//map//2.png");
  24.         wall2 = img.getImage();
  25.         map = new String[17][13];
  26.        
  27.         openFile();
  28.         readFile();
  29.         closeFile();
  30.     }
  31.    
  32.     public Image getPath(){
  33.         return path;
  34.     }
  35.    
  36.     public Image getWall1(){
  37.         return wall1;
  38.     }
  39.    
  40.     public Image getWall2(){
  41.         return wall2;
  42.     }
  43.    
  44.    
  45.     public String getMap(int x,int y) {
  46.         return map[x][y];
  47.     }
  48.  
  49.      public void openFile() {
  50.             try {
  51.                 br=new BufferedReader(new FileReader("./map/map.txt"));
  52.             }
  53.             catch(Exception e) {
  54.                 System.out.println("Error Loading File!!!!");
  55.                 e.printStackTrace();
  56.             }
  57.         }
  58.        
  59.    
  60.      public void readFile() {
  61.          String line;
  62.          int index = 0;
  63.           try {
  64.             while((line = br.readLine() ) != null){
  65.                     String neco[] = line.split("-");
  66.                    for(int i=0; i<17; i++){
  67.                        map[i][index]=neco[i];
  68.                    }
  69.                    index++;
  70.               }
  71.         } catch (IOException e) {
  72.             // TODO Auto-generated catch block
  73.             e.printStackTrace();
  74.         }
  75.          
  76.      }
  77.      
  78.      
  79.      public void closeFile() {
  80.             try {
  81.                 br.close();
  82.             } catch (IOException e) {
  83.                 // TODO Auto-generated catch block
  84.                 e.printStackTrace();
  85.             }
  86.         }
  87.  
  88.  
  89.    
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement