|
|
@ -21,8 +21,8 @@ public class Map { |
|
|
|
"wwwwwww.wweeeeeeeeeeww.wwwwwww", |
|
|
|
"wwwwwww.wwewwwwwwwweww.wwwwwww", |
|
|
|
"wwwwwww.wweweeeeeeweww.wwwwwww", |
|
|
|
"eeeeeee.eeeweeeeeeweee.eeeeeee", |
|
|
|
"wwwwwww.wweweeeeeeweww.wwwwwww", |
|
|
|
"eeeeeee.eeew804629weee.eeeeeee", |
|
|
|
"wwwwwww.wwewe1573eweww.wwwwwww", |
|
|
|
"wwwwwww.wweweeeeeeweww.wwwwwww", |
|
|
|
"wwwwwww.wwewwwwwwwweww.wwwwwww", |
|
|
|
"wwwwwww.wweeeeeeeeeeww.wwwwwww", |
|
|
@ -41,13 +41,28 @@ public class Map { |
|
|
|
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" |
|
|
|
}; |
|
|
|
|
|
|
|
public Vector2[] ghostSpawns; |
|
|
|
public String ghostSpawnChars = "0123456789"; |
|
|
|
|
|
|
|
|
|
|
|
public final HashMap<String, String> mapTypes = new HashMap<String,String>(){{ |
|
|
|
this.put("e", "empty"); |
|
|
|
this.put("s", "empty"); |
|
|
|
this.put(".", "dot"); |
|
|
|
this.put("w", "wall"); |
|
|
|
this.put("0", "empty"); |
|
|
|
this.put("1", "empty"); |
|
|
|
this.put("2", "empty"); |
|
|
|
this.put("3", "empty"); |
|
|
|
this.put("4", "empty"); |
|
|
|
this.put("5", "empty"); |
|
|
|
this.put("6", "empty"); |
|
|
|
this.put("7", "empty"); |
|
|
|
this.put("8", "empty"); |
|
|
|
this.put("9", "empty"); |
|
|
|
}}; |
|
|
|
|
|
|
|
|
|
|
|
public Cell[][] cells; |
|
|
|
public Vector2 size; |
|
|
|
|
|
|
@ -60,7 +75,6 @@ public class Map { |
|
|
|
} |
|
|
|
|
|
|
|
public void GenerateMap(String[] mapData) { |
|
|
|
|
|
|
|
int sizeY = mapData.length; |
|
|
|
int sizeX = mapData[0].length(); |
|
|
|
|
|
|
@ -96,4 +110,125 @@ public class Map { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
private void initializeGhostSpawns() { |
|
|
|
int count = 0; |
|
|
|
for (int y = 0; y < mapClassic.length; y++) { |
|
|
|
for (int x = 0; x < mapClassic[y].length(); x++) { |
|
|
|
char cellChar = mapClassic[y].charAt(x); |
|
|
|
if (ghostSpawnChars.indexOf(cellChar) != -1) { |
|
|
|
count++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ghostSpawns = new Vector2[count]; |
|
|
|
count = 0; |
|
|
|
for (int y = 0; y < mapClassic.length; y++) { |
|
|
|
for (int x = 0; x < mapClassic[y].length(); x++) { |
|
|
|
char cellChar = mapClassic[y].charAt(x); |
|
|
|
if (ghostSpawnChars.indexOf(cellChar) != -1) { |
|
|
|
ghostSpawns[count++] = new Vector2(x, mapClassic.length - 1 - y); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String FindPath(Vector2 from, Vector2 to) |
|
|
|
{ |
|
|
|
char[][] tempMap = new char[size.x][size.y]; |
|
|
|
|
|
|
|
for(int x = 0; x < size.x; x++) { |
|
|
|
for(int y = 0; y < size.y; y++) { |
|
|
|
Vector2 pos = new Vector2(x,y); |
|
|
|
Cell cell = GetCell(pos); |
|
|
|
if(cell.type.equals("wall")) { |
|
|
|
tempMap[x][y] = 'w'; |
|
|
|
} |
|
|
|
else { |
|
|
|
tempMap[x][y] = 'e'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tempMap[to.x][to.y] = 't'; |
|
|
|
|
|
|
|
String targetChars = "tudlr"; |
|
|
|
|
|
|
|
boolean done = false; |
|
|
|
|
|
|
|
while(!done) { |
|
|
|
int changes = 0; |
|
|
|
|
|
|
|
for(int x = 0; x < size.x; x++) { |
|
|
|
for(int y = 0; y < size.y; y++) { |
|
|
|
|
|
|
|
if(tempMap[x][y] == 'e') { |
|
|
|
|
|
|
|
Vector2 pos = new Vector2(x,y); |
|
|
|
char newChar = 'x'; |
|
|
|
|
|
|
|
if(targetChars.indexOf(tempMap[x + 1][y]) >= 0) { |
|
|
|
newChar = 'r'; |
|
|
|
} |
|
|
|
else if(targetChars.indexOf(tempMap[x - 1][y]) >= 0) { |
|
|
|
newChar = 'l'; |
|
|
|
} |
|
|
|
else if(targetChars.indexOf(tempMap[x][y + 1]) >= 0) { |
|
|
|
newChar = 'u'; |
|
|
|
} |
|
|
|
else if(targetChars.indexOf(tempMap[x][y - 1]) >= 0) { |
|
|
|
newChar = 'd'; |
|
|
|
} |
|
|
|
|
|
|
|
if(newChar != 'x') { |
|
|
|
tempMap[x][y] = newChar; |
|
|
|
changes++; |
|
|
|
|
|
|
|
if(pos.equals(from)) { |
|
|
|
done = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(changes == 0) { |
|
|
|
done = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(tempMap[from.x][from.y] != 'e') { |
|
|
|
boolean reading = true; |
|
|
|
String path = ""; |
|
|
|
Vector2 currentReadPos = from.Clone(); |
|
|
|
|
|
|
|
while(reading) { |
|
|
|
char currentChar = tempMap[currentReadPos.x][currentReadPos.y]; |
|
|
|
|
|
|
|
if(currentReadPos.equals(to)) { |
|
|
|
reading = false; |
|
|
|
} |
|
|
|
else { |
|
|
|
path += currentChar; |
|
|
|
|
|
|
|
if(currentChar == 'l') { |
|
|
|
currentReadPos = currentReadPos.Add(new Vector2(-1, 0)); |
|
|
|
} |
|
|
|
else if(currentChar == 'r') { |
|
|
|
currentReadPos = currentReadPos.Add(new Vector2(1, 0)); |
|
|
|
} |
|
|
|
else if(currentChar == 'u') { |
|
|
|
currentReadPos = currentReadPos.Add(new Vector2(0, 1)); |
|
|
|
} |
|
|
|
else if(currentChar == 'd') { |
|
|
|
currentReadPos = currentReadPos.Add(new Vector2(0, -1)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return path; |
|
|
|
} |
|
|
|
else { |
|
|
|
//no path was found |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |