Browse Source

refactoring: Making the ghost spawns readable

remotes/origin/ghostsbehaviour
fdai7753 11 months ago
parent
commit
41abb93e7b
  1. 8
      src/main/java/pacmanGame/GameManager.java
  2. 2
      src/main/java/pacmanGame/Ghost.java
  3. 34
      src/main/java/pacmanGame/Map.java

8
src/main/java/pacmanGame/GameManager.java

@ -15,14 +15,14 @@ public class GameManager {
}
public void setupGame(){
ghosts = new Ghost[4];
for (int i = 0; i < ghosts.length; i++) {
ghosts[i] = new Ghost(this, i);
}
map = new Map(Map.mapClassic, this);
visualizer = new VisualizerPlainText(this);
player = new Player(this);
player.Spawn();
ghosts = new Ghost[4];
for (int i = 0; i < ghosts.length; i++) {
ghosts[i] = new Ghost(this, i);
}
}
public void Update() {
visualizer.Update();

2
src/main/java/pacmanGame/Ghost.java

@ -21,6 +21,6 @@ public class Ghost {
}
public void spawn() {
//this.position = gameManager.map;
}
}

34
src/main/java/pacmanGame/Map.java

@ -68,10 +68,11 @@ public class Map {
public Vector2 playerSpawn = new Vector2(2,2);
public char playerSpawnChar = 's';
public Map(String[] mapData, GameManager gameManager) {
GenerateMap(mapData);
this.gameManager = gameManager;
GenerateMap(mapData);
}
public void GenerateMap(String[] mapData) {
@ -82,6 +83,8 @@ public class Map {
cells = new Cell[size.x][size.y];
ghostSpawns = new Vector2[10];
for(int x = 0; x < size.x; x++) {
for(int y = 0; y < size.y; y++) {
Vector2 cellPos = new Vector2(x,y);
@ -92,6 +95,12 @@ public class Map {
cells[x][y] = new Cell(cellPos, cellType, this);
for(int i = 0; i < gameManager.ghosts.length; i++) {
if(cellChar == ghostSpawnChars.charAt(i)) {
ghostSpawns[i] = cellPos.Clone();
}
}
if(cellChar == playerSpawnChar) {
playerSpawn = cellPos.Clone();
}
@ -110,28 +119,7 @@ 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];

Loading…
Cancel
Save