diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java index ac7156a..3d3c6f0 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Game.java @@ -172,6 +172,14 @@ public class Game implements Runnable { if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) && getOgGhost().getIsPlayer()) { OgGhostHighScore.addOgGhostWinner(getOgGhost().getName()); } + + //send command to play game over sound: + if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin)) { + lobby.getAdmin().sendMsgToClientsInLobby(Protocol.playSound + "$" + "GW"); + } else { + lobby.getAdmin().sendMsgToClientsInLobby(Protocol.playSound + "$" + "HW"); + } + lobby.getAdmin().broadcastAnnouncementToLobby(gameOverCheck); isOngoing = false; Timer.ghostAfterVoteTimer(); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java index ba867ee..ca96835 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/JClientProtocolParser.java @@ -91,6 +91,23 @@ public class JClientProtocolParser { case Protocol.noiseNotificationProtocol: Sound.ghost(); break; + case Protocol.playSound: + switch (msg.substring(6)) { + case "GW": + Sound.gameoverghosts(); + break; + case "HW": + Sound.gameoverhumans(); + break; + case "GV": + Sound.voteforghost(); + break; + case "HV": + Sound.voteforhuman(); + break; + default: + LOGGER.warn("Invalid sound request"); + } default: System.out.println("Received unknown command: " + msg); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Sound.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Sound.java index 6067c6a..45948d5 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Sound.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Sound.java @@ -97,7 +97,14 @@ public class Sound { public static void gameoverghosts() { gameoverghosts.play(defaultvolume); } - public static void gameoverhumans() { gameoverhumans.play(defaultvolume); } + public static void gameoverhumans() { + stopmusicday(); + gameoverhumans.play(defaultvolume); + } + + public static void voteforghost() { voteforghost.play(defaultvolume); } + + public static void voteforhuman() { voteforhuman.play(defaultvolume); } public static void musicday() { musicday.play(defaultvolume); @@ -127,7 +134,7 @@ public class Sound { ghost = ghost04; break; } - ghost.play(defaultvolume - 0.3, 0.0, playbackspeed, 0.0, 5); + ghost.play(0.1, 0.0, playbackspeed, 0.0, 5); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java index 797c718..833db14 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/GameController.java @@ -40,7 +40,7 @@ public class GameController implements Initializable { public static final Logger LOGGER = LogManager.getLogger(GameController.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); static boolean justRangBell = false; //used to track if the bell has been rung recently - static final int minimumBellTime = 1000; //minimal time that has to pass between bells, in ms + static final int minimumBellTime = 100; //minimal time that has to pass between bells, in ms static boolean playingDayNoises = true; //true if playing day noises, false if playing night noises private static ClientModel client; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java index 44c3061..673cada 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java @@ -212,6 +212,13 @@ public class Protocol { */ public static final String noiseNotificationProtocol = "NOISE"; + /** + * Used to tell the client to play a sound, namely the sounds for when humans have voted for a human (PLSND$HV), + * when humans have voted for a ghost (PLSND$GV), when humans have won (i.e. have voted for the OG - PLSND$HW) + * or when ghosts have won (PLSND$GW) + */ + public static final String playSound = "PLSND"; + /** * Sends an information to client at which position in the train from the game (0 to 5) they sit, as soon as the game starts * {@code POSOF$position}