-
Notifications
You must be signed in to change notification settings - Fork 3
/
MapTemp.java
93 lines (75 loc) · 1.93 KB
/
MapTemp.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
package aStarAlgorithm;
import java.awt.Point;
import java.util.ArrayList;
public class MapTemp {
// private ArrayList m_objectsOnMap;
private TileObjectAbstract m_map[][];
private int m_width;
private int m_height;
// public Map(){
// this.m_objectsOnMap = new ArrayList();
// }
public MapTemp(int width, int height){
this.initMap(width, height);
}
// public void initMap(){
// this.m_objectsOnMap.clear();
// }
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;
}
public TileObjectAbstract[][] getMap(){
return this.m_map;
}
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;
}
}