Browse Source

Merge branch 'player'

remotes/origin/visualizer
fdai7910 11 months ago
parent
commit
a3762599f2
  1. 12
      src/main/java/pacmanGame/Cell.java
  2. 26
      src/main/java/pacmanGame/GameManager.java
  3. 1
      src/main/java/pacmanGame/Player.java
  4. 5
      src/main/java/pacmanGame/VisualizerPlainText.java

12
src/main/java/pacmanGame/Cell.java

@ -4,6 +4,7 @@ public class Cell {
public Vector2 pos;
public String type;
public final Map map;
public GameManager gameManager;
public Cell(Vector2 pos, String type, Map map) {
this.pos = pos;
@ -17,11 +18,15 @@ public class Cell {
}
public void triggerPill() {
//todo: code
this.type = "empty";
gameManager.score += 100;
int timeStopPillEffect = gameManager.time + 200;
gameManager.ghostIsEdible = true;
}
public void triggerFruit() {
//todo: code
this.type = "empty";
map.gameManager.score += 505;
}
public void triggerItem() {
@ -35,8 +40,7 @@ public class Cell {
triggerFruit();
}
else {
System.out.println("cell contains no item!");
//System.out.println("cell contains no item!");
}
}
}

26
src/main/java/pacmanGame/GameManager.java

@ -7,6 +7,7 @@ public class GameManager {
public Visualizer visualizer;
public Player player;
public int score = 0;
public Boolean ghostIsEdible = false;
public GameManager() {
setupGame();
@ -28,8 +29,22 @@ public class GameManager {
if(time%5 == 0) {
player.Move();
}
if(time == 300) {
spawnCherry();
}
if (time == 600) {
destroyCherry();
}
time++;
}
public void spawnCherry() {
map.GetCell(map.playerSpawn).type = "cherry";
}
public void destroyCherry() {
map.GetCell(map.playerSpawn).type = "empty";
}
public void ProcessInput(char inputChar) {
if(inputChar == 27) {
@ -59,4 +74,15 @@ public class GameManager {
}
return false;
}
public void updatePlayerCell() {
map.GetCell(player.position).triggerItem();
}
public void makeGhostEdible(int timeStopPillEffect) {
ghostIsEdible = true;
if(time == timeStopPillEffect) {
ghostIsEdible = false;
}
}
}

1
src/main/java/pacmanGame/Player.java

@ -24,6 +24,7 @@ public class Player {
if(!newPosIsWall) {
position = newPosition;
}
gameManager.updatePlayerCell();
}
public void processInput(char inputchar) {

5
src/main/java/pacmanGame/VisualizerPlainText.java

@ -11,6 +11,7 @@ public class VisualizerPlainText implements Visualizer {
this.put("empty", " ");
this.put("dot", ". ");
this.put("wall", "[]");
this.put("cherry", "OO");
}};
public final String ghostSprite = "AA";
@ -27,7 +28,7 @@ public class VisualizerPlainText implements Visualizer {
@Override
public void Update() {
output = "";
output = "Score: " + gameManager.score + "\n";
Map map = gameManager.map;
for(int y = 0; y < map.size.y; y++) {
@ -55,7 +56,7 @@ public class VisualizerPlainText implements Visualizer {
output += sprites.get(cell.type);
}
else {
System.out.println("unknown type" + cell.type);
System.out.println("unknown type " + cell.type);
}
}
output += "\n";

Loading…
Cancel
Save