Advertisement
niflo

Map

Oct 23rd, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package mazegui;
  2.  
  3. import java.awt.Image;
  4. import java.util.Scanner;
  5. import java.io.*;
  6. import javax.swing.ImageIcon;
  7.  
  8.  
  9. public class Map {
  10.  
  11. private Scanner m;
  12. private String Map[] = new String[14];
  13.  
  14.  
  15. private Image grass,
  16. wall;
  17.  
  18. public Map () {
  19.  
  20. ImageIcon img = new ImageIcon("/Users/nikolaj_fl/Desktop/Builder/grass.png");
  21. grass = img.getImage();
  22. img = new ImageIcon("/Users/nikolaj_fl/Desktop/Builder/wall.png");
  23. wall = img.getImage();
  24.  
  25. openFile();
  26. readFile();
  27. closeFile();
  28.  
  29. }
  30.  
  31. public Image getGrass(){
  32. return grass;
  33. }
  34. public Image getWall(){
  35. return wall;
  36.  
  37. }
  38. public String getMap (int x, int y){
  39. String index = Map[y].substring(x, x + 1);
  40. return index;
  41.  
  42. }
  43.  
  44. public void openFile(){
  45.  
  46. try {
  47. m = new Scanner(new File("/Users/nikolaj_fl/Desktop/Builder/map.txt"));
  48. }catch(Exception e){
  49. System.out.println("error loading map");
  50. }
  51. }
  52.  
  53. public void readFile(){
  54.  
  55. while(m.hasNext()){
  56. for(int i = 0; i < 14; i++){
  57. Map[i] = m.next();
  58.  
  59. }
  60. }
  61. }
  62. public void closeFile(){
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement