-
Notifications
You must be signed in to change notification settings - Fork 3
/
Map2D.java
81 lines (65 loc) · 1.7 KB
/
Map2D.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
package aStarAlgorithm;
import java.awt.Point;
import java.util.ArrayList;
public class Map2D {
private TileObjectAbstract m_map[][];
private int m_width;
private int m_height;
public Map2D(int width, int height){
this.initMap(width, height);
}
public void initMap(int width, int height){
this.setWidth(width);
this.setHeight(height);
this.m_map = new TileObjectAbstract[this.getHeight()][this.getWidth()];
for(int y = 0; y < this.getHeight(); y++){
for(int x = 0; x < this.getWidth(); x++){
this.m_map[y][x] = new TileAssemble.Empty();
}
}
}
public void setMap(TileObjectAbstract newMap[][]){
this.m_map = newMap;
this.setWidth(newMap[0].length);
this.setHeight(newMap.length);
}
public void setTile(int x, int y, TileObjectAbstract mta){
this.m_map[y][x] = mta;
}
public boolean contains(String className) throws ClassNotFoundException{
for(int y = 0; y < this.getHeight(); y++){
for(int x = 0; x < this.getWidth(); x++){
if(Class.forName(className).isInstance(this.getTile(x, y))){
return true;
}
}
}
return false;
}
public TileObjectAbstract getTile(int x, int y){
return this.m_map[y][x];
}
public Point getTile(String className) throws ClassNotFoundException{
Point p = null;
for(int y = 0; y < this.getHeight(); y++){
for(int x = 0; x < this.getWidth(); x++){
if(Class.forName(className).isInstance(this.getTile(x, y))){
return p = new Point(x, y);
}
}
}
return p;
}
protected void setWidth(int width){
this.m_width = width;
}
protected void setHeight(int height){
this.m_height = height;
}
public int getWidth(){
return this.m_width;
}
public int getHeight(){
return this.m_height;
}
}