Browse Source

added findCellByString method to Map

remotes/origin/player
fdai7910 11 months ago
parent
commit
7380944cfc
  1. 94
      src/main/java/pacmanGame/Map.java

94
src/main/java/pacmanGame/Map.java

@ -5,54 +5,35 @@ import java.util.HashMap;
public class Map {
public final GameManager gameManager;
public static String[] mapClassic = {
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"ww............ww............ww",
"ww.wwww.wwwww.ww.wwwww.wwww.ww",
"wwpwwww.wwwww.ww.wwwww.wwwwpww",
"ww.wwww.wwwww.ww.wwwww.wwww.ww",
"ww..........................ww",
"ww.wwww.ww.wwwwwwww.ww.wwww.ww",
"ww.wwww.ww.wwwwwwww.ww.wwww.ww",
"ww......ww....ww....ww......ww",
"wwwwwww.wwwwwewwewwwww.wwwwwww",
"wwwwwww.wwwwwewwewwwww.wwwwwww",
"wwwwwww.wweeeeeeeeeeww.wwwwwww",
"wwwwwww.wwewwwwwwwweww.wwwwwww",
"wwwwwww.wweweeeeeeweww.wwwwwww",
"eeeeeee.eeeweeeeeeweee.eeeeeee",
"wwwwwww.wweweeeeeeweww.wwwwwww",
"wwwwwww.wweweeeeeeweww.wwwwwww",
"wwwwwww.wwewwwwwwwweww.wwwwwww",
"wwwwwww.wweeeeeeeeeeww.wwwwwww",
"wwwwwww.wwewwwwwwwweww.wwwwwww",
"ww............ww............ww",
"ww.wwww.wwwww.ww.wwwww.wwww.ww",
"ww.wwww.wwwww.ww.wwwww.wwww.ww",
"wwp..ww.......s........ww..pww",
"wwww.ww.ww.wwwwwwww.ww.ww.wwww",
"wwww.ww.ww.wwwwwwww.ww.ww.wwww",
"ww......ww....ww....ww......ww",
"ww.wwwwwwwwww.ww.wwwwwwwwww.ww",
"ww.wwwwwwwwww.ww.wwwwwwwwww.ww",
"ww..........................ww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
};
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("p", "pill");
}};
public static String[] mapClassic = { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", "wwpwwww.wwwww.ww.wwwww.wwwwpww",
"ww.wwww.wwwww.ww.wwwww.wwww.ww", "ww..........................ww", "ww.wwww.ww.wwwwwwww.ww.wwww.ww",
"ww.wwww.ww.wwwwwwww.ww.wwww.ww", "ww......ww....ww....ww......ww", "wwwwwww.wwwwwewwewwwww.wwwwwww",
"wwwwwww.wwwwwewwewwwww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww",
"wwwwwww.wweweeeeeeweww.wwwwwww", "Teeeeee.eeeweeeeeeweee.eeeeeet", "wwwwwww.wweweeeeeeweww.wwwwwww",
"wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww",
"wwwwwww.wwewwwwwwwweww.wwwwwww", "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww",
"ww.wwww.wwwww.ww.wwwww.wwww.ww", "wwp..ww.......s........ww..pww", "wwww.ww.ww.wwwwwwww.ww.ww.wwww",
"wwww.ww.ww.wwwwwwww.ww.ww.wwww", "ww......ww....ww....ww......ww", "ww.wwwwwwwwww.ww.wwwwwwwwww.ww",
"ww.wwwwwwwwww.ww.wwwwwwwwww.ww", "ww..........................ww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" };
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("p", "pill");
this.put("T", "tpLeft");
this.put("t", "tpRight");
}
};
public Cell[][] cells;
public Vector2 size;
public Vector2 playerSpawn = new Vector2(2,2);
public Vector2 playerSpawn = new Vector2(2, 2);
public char playerSpawnChar = 's';
public Map(String[] mapData, GameManager gameManager) {
@ -69,9 +50,9 @@ public class Map {
cells = new Cell[size.x][size.y];
for(int x = 0; x < size.x; x++) {
for(int y = 0; y < size.y; y++) {
Vector2 cellPos = new Vector2(x,y);
for (int x = 0; x < size.x; x++) {
for (int y = 0; y < size.y; y++) {
Vector2 cellPos = new Vector2(x, y);
char cellChar = mapData[size.y - 1 - y].charAt(x);
@ -79,7 +60,7 @@ public class Map {
cells[x][y] = new Cell(cellPos, cellType, this);
if(cellChar == playerSpawnChar) {
if (cellChar == playerSpawnChar) {
playerSpawn = cellPos.Clone();
}
}
@ -87,14 +68,25 @@ public class Map {
}
public Cell GetCell(Vector2 pos) {
if(pos.isWithin(size)) {
if (pos.isWithin(size)) {
return cells[pos.x][pos.y];
}
else {
} else {
return cells[0][0];
}
}
public Cell findCellByString(String target) {
for (int x = 0; x < size.x; x++) {
for (int y = 0; y < size.y; y++) {
if (cells[x][y].type == target) {
return cells[x][y];
}
}
}
return null;
}
}
Loading…
Cancel
Save