From 8c8bf20c02d147c39fe8d9a90a861a107e2fb290 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:23:08 +0100 Subject: [PATCH] added randomFruit function to GameManager --- src/main/java/pacmanGame/GameManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 544b401..7f11a92 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -31,10 +31,10 @@ public class GameManager { player.Move(); } if(time == 300) { - spawnCherry(); + spawnFruit(); } if (time == 600) { - destroyCherry(); + destroyFruit(); } if(ghostIsEdible) { if(time == timeStopPillEffect) @@ -43,13 +43,19 @@ public class GameManager { time++; } - public void spawnCherry() { - map.GetCell(map.playerSpawn).type = "cherry"; + public void spawnFruit() { + map.GetCell(map.playerSpawn).type = randomFruit(); } - public void destroyCherry() { + public void destroyFruit() { map.GetCell(map.playerSpawn).type = "empty"; } + + public String randomFruit() { + String fruitTypes[] = {"cherry"}; + int randomNumber = (int) (Math. random() * fruitTypes.length); + return fruitTypes[randomNumber]; + } public void ProcessInput(char inputChar) { if(inputChar == 27) {