-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaze.java
111 lines (101 loc) · 2.6 KB
/
Maze.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.*;
public class Maze {
private Cell[][] map;
private int width;
private int height;
/**
* Constructor
* @param height
* @param width
* @param cells
*/
public Maze(int height, int width, Cell[][] cells ){
this.height = height;
this.width = width;
this.map = cells;
}
/**
*
* @return maze height
*/
public int getHeight() {
return height;
}
/**
*
* @return maze width
*/
public int getWidth() {
return width;
}
/**
*
* @return harta labirintului
*/
public Cell[][] getMap() {
return map;
}
/**
* Determina pozitia portalului de intrare in labirint
* @param start
*/
public void getEntrance(Direction start){
for (int i = 0; i < this.height; i++) {
for (int j = 0; j < this.width; j++){
Cell c = this.map[i][j];
if(c instanceof EntranceCell){
start.row = i;
start.col = j;
break;
}
}
}
}
/**
* Daca in pozitia dir exista un perete se arunca exceptia
* CannotMoveIntoWallsException
* @param dir
* @throws Exception CannotMoveIntoWallsException
*/
public void checkWall(Direction dir) throws Exception{
if (map[dir.row][dir.col] instanceof WallCell)
throw new CannotMoveIntoWallsException();
}
/**
* Daca pozitia dir se afla in afara labirintului se arunca exceptia
* HeroOutOfGroundException
* @param dir
* @throws Exception HeroOutOfGroundException
*/
public void checkLimits(Direction dir) throws Exception{
if (dir.row < 0 || dir.row >= this.height || dir.col < 0 || dir.col >=
this.width)
throw new HeroOutOfGroundException();
}
/**
* Verific daca pozitia dir se afla in labirint
* @param dir
* @return true/false
*/
public boolean isInMaze(Direction dir){
try {
checkLimits(dir);
return true;
} catch (Exception e) {
return false;
}
}
/**
* Verific daca in pozitia dir se afla in labirint un perete
* @param dir
* @return true/false
*/
public boolean isNotWall(Direction dir) {
try {
checkWall(dir);
return true;
} catch (Exception e) {
return false;
}
}
}