diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java index 9317836..ba803e8 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ClientGameInfoHandler.java @@ -16,7 +16,7 @@ public class ClientGameInfoHandler { //relevant: public static final String ghostVoteRequest = "Vote on who to ghostify!"; public static final String humanVoteRequest = "Vote for a ghost to kick off!"; - public static final String noiseNotification = "You heard some noise"; + public static final String noiseNotification = "Someone passed by you "; public static final String gameOverHumansWin = "Game over: humans win!"; public static final String gameOverGhostsWin = "Game over: ghosts win!"; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/NoiseHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/NoiseHandler.java index cdda0ee..9579dea 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/NoiseHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/NoiseHandler.java @@ -8,30 +8,32 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; * and broadcasts noise message to them (via ServerGameInfoHandler) */ public class NoiseHandler { - /** - * Notifies passengers in the train about a ghost walking by them. Differentiates between two + /** Updates the amount of times passengers on the train heard ghosts walk by them. Differentiates between two * cases: if the active ghost (predator) is to the right of his victim, the Passenger array is * being walked through from right to left (from the predator's position back to the victim's * position), otherwise the other way around. One call of noiseNotifier only deals with one * predator infecting a victim, so if there are already multiple ghosts in the game, the method * should be called for each of them individually. - * + * @param passengers passengers of the train the game is played in * @param predator ghost that has infected a human player during this night (called upon as - * passenger for convenience reasons) + * passenger for convenience reasons) * @param victim human player who has been turned into a ghost this night + * @param noiseAmount array containing information about how many times each passenger heard a noise this night * @param game current game instance + * @return updated array with info on who heard how many noises */ - public void noiseNotifier(Passenger[] passengers, Passenger predator, Passenger victim, Game game) { + public int[] noiseNotifier(Passenger[] passengers, Passenger predator, Passenger victim, int[] noiseAmount, Game game) { if (predator.getPosition() - victim.getPosition() > 0) { // if predator is to the right of victim for (int i = predator.getPosition() - 1; i > victim.getPosition(); i--) { - passengers[i].send(ClientGameInfoHandler.noiseNotification, game); + noiseAmount[i]++; } } else { // if predator is to the left of victim for (int i = predator.getPosition() + 1; i < victim.getPosition(); i++) { - passengers[i].send(ClientGameInfoHandler.noiseNotification, game); + noiseAmount[i]++; } } + return noiseAmount; } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java index 457dee1..1c7472d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java @@ -88,14 +88,25 @@ public class VoteHandler { } /* notify passengers the ghosts passed by - for each ghost that ghostified a player, an instance of NoiseHandler - is being created and the passengers this ghost passed by are being notified. The player who's just been ghostified - is ignored since he didn't participate in this night's ghostification. */ + is being created and the array containing the information about the amount of times each passenger heard a ghost + walk by is being updated. Finally, each passenger receives information about how often he heard something during + this night. The player who's just been ghostified is ignored since he didn't participate in this night's + ghostification. */ + + int[] noiseAmount = new int[6]; for (int i = 0; i < passengers.length; i++) { if (passengers[i].getIsGhost() && i != ghostPosition) { NoiseHandler n = new NoiseHandler(); - n.noiseNotifier(passengers, passengers[i], g, game); + noiseAmount = n.noiseNotifier(passengers, passengers[i], g, noiseAmount, game); } } + for (int i = 0; i < passengers.length; i++) { + if (!passengers[i].getIsGhost() && noiseAmount[i] != 0) { // passenger is human and someone walked by him + passengers[i].send(ClientGameInfoHandler.noiseNotification + noiseAmount[i] + " time(s)", game); + } + } + + // no humans left in the game --> everyone has been ghostified, ghosts win int humanCounter = 0; for(Passenger passenger : passengers) { if(!passenger.getIsGhost()) { //if it is a human @@ -108,7 +119,7 @@ public class VoteHandler { } LOGGER.info(game.getGameState().toString()); - // set hasVoted to false for all passengers for future votings + // set hasVoted to false for all passengers for future voting for (Passenger passenger : passengers) { passenger.setHasVoted(false); passenger.setVote(Integer.MAX_VALUE);