gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
a5e8a1574e305c25da47fc73967029f737240d43
[spa2-materijali.git] / PretrazivanjeSaVracanjem / Lavirint / NajboljiPut / Mapa.java
1 public class Mapa {
2 public final static int IZLAZ = -99;
3 public final static int ZID = -11;
4 public final static int ERROR = Integer.MIN_VALUE;
6 private int visina, sirina;
7 private int[][] mat;
8 private boolean[][] pos;
10 public int getSirina() {
11 return sirina;
12 }
14 public int getVisina() {
15 return visina;
16 }
18 public void setPos(int x, int y, boolean b) {
19 if (0 <= x && x < sirina && 0 <= y && y < visina) {
20 pos[x][y] = b;
21 }
22 }
24 public boolean getPos(int x, int y) {
25 if (0 <= x && x < sirina && 0 <= y && y < visina) {
26 return pos[x][y];
27 } else {
28 return true;
29 }
30 }
32 public int getMat(int x, int y) {
33 if (0 <= x && x < sirina && 0 <= y && y < visina) {
34 return mat[x][y];
35 } else {
36 return ERROR;
37 }
38 }
40 public Mapa(int sirina, int visina) {
41 this.sirina = sirina;
42 this.visina = visina;
43 mat = new int[sirina][visina];
44 pos = new boolean[sirina][visina];
45 }
47 public static Mapa ucitajIzFajla(String imeFajla) {
48 if (!Svetovid.testIn(imeFajla)) {
49 return null;
50 }
52 int sirina = Svetovid.in(imeFajla).readInt();
53 int visina = Svetovid.in(imeFajla).readInt();
54 if (sirina >= 0 && visina >= 0) {
55 Mapa res = new Mapa(sirina, visina);
56 for (int j = 0; j < visina; j++)
57 for (int i = 0; i < sirina; i++)
58 res.mat[i][j] = Svetovid.in(imeFajla).readInt();
59 Svetovid.closeIn(imeFajla);
60 return res;
61 } else {
62 Svetovid.closeIn(imeFajla);
63 return null;
64 }
65 }
67 public void stampaj() {
68 if (visina != 0 && sirina != 0) {
69 System.out.println(visina + " " + sirina);
70 for (int j = 0; j < visina; j++) {
71 for (int i = 0; i < sirina; i++) {
72 System.out.print(mat[i][j] + "\t");
73 }
74 System.out.println();
75 }
76 }
77 }
78 }
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner