diff --git a/OgGhostWinners.txt b/OgGhostWinners.txt index 47930f7..323edb5 100644 --- a/OgGhostWinners.txt +++ b/OgGhostWinners.txt @@ -6,4 +6,6 @@ serai serai serai serai -serai +Jonas +Jonas +Jonas 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 3d3c6f0..284a506 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 @@ -122,6 +122,10 @@ public class Game implements Runnable { LOGGER.info(gameState.toGhostString()); for (ClientHandler client : lobbyClients) {//begins filling the train with clients + + //send train horn sound to client: + client.sendMsgToClient(Protocol.playSound + "$" + "TH"); + int index = order[i]; if (passengerTrain[index].getIsGhost()) { //if there is a ghost GhostPlayer ghostPlayer = new GhostPlayer(passengerTrain[index].getPosition(), 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 e455f3b..8c5339c 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 @@ -24,11 +24,11 @@ public class NoiseHandler { public int[] noiseNotifier(Passenger predator, Passenger victim, int[] noiseAmount) { if (predator.getPosition() - victim.getPosition() > 0) { // if predator is to the right of victim - for (int i = predator.getPosition() - 1; i > victim.getPosition(); i--) { + for (int i = predator.getPosition() ; i > victim.getPosition(); i--) { //-1 noiseAmount[i]++; } } else { // if predator is to the left of victim - for (int i = predator.getPosition() + 1; i < victim.getPosition(); i++) { + for (int i = predator.getPosition(); i < victim.getPosition(); i++) { //+1 noiseAmount[i]++; } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java index dd556a9..4034172 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/ServerGameInfoHandler.java @@ -121,14 +121,13 @@ public class ServerGameInfoHandler { case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": case ClientGameInfoHandler.noiseNotification: - //todo: jonas: handle bell behaviour correctly. - String outMsg = npc.getName() + ": " + noiseRandomizer(); - //TODO: add likelyhood + if(!npc.getKickedOff()) { - game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); - game.getLobby().getAdmin().sendMsgToClientsInLobby( - Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition - + "$" + npc.getPosition()); + if (Math.random() < GhostNPC.probabilityToRingAlarmIfHeardNoise) { + game.getLobby().getAdmin().sendMsgToClientsInLobby( + Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition + + "$" + npc.getPosition()); + } } break; case ClientGameInfoHandler.ghostVoteRequest: @@ -151,13 +150,13 @@ public class ServerGameInfoHandler { case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": case ClientGameInfoHandler.noiseNotification: //new case where times are not noted. - //todo: jonas: handle bell behaviour correctly. - String outMsg = npc.getName() + ": " + noiseRandomizer(); if(!npc.getKickedOff()) { - game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); - game.getLobby().getAdmin().sendMsgToClientsInLobby( - Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition - + "$" + npc.getPosition()); + if (Math.random() < HumanNPC.probabilityToRingAlarmIfHeardNoise) { + game.getLobby().getAdmin().sendMsgToClientsInLobby( + Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition + + "$" + npc.getPosition()); + } + } break; case ClientGameInfoHandler.humanVoteRequest: diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java index b121302..e31d356 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/Timer.java @@ -26,7 +26,7 @@ public class Timer { /** * The maximum length of the human vote in the day, in seconds */ - public static final int humanVoteTime = 60; + public static final int humanVoteTime = 63; /** * The length of time in seconds after the human vote, as the 'winner' of the vote is announced, 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 e8a6410..a4b95c7 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 @@ -4,6 +4,7 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; +import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -171,8 +172,16 @@ public class VoteHandler { passenger.send( ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game); } + + for (ClientHandler c: game.getLobby().getLobbyClients()) { //send human vote sound to clients + c.sendMsgToClient(Protocol.playSound + "$" + "HV"); + } + } else if (!passengers[voteIndex].getIsOG()) { + for (ClientHandler c: game.getLobby().getLobbyClients()) { //send ghost vote sound to clients + c.sendMsgToClient(Protocol.playSound + "$" + "GV"); + } } - Timer.humanAfterVoteTimer(); + if (passengers[voteIndex].getIsGhost()) { // if player is a ghost if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win System.out.println(ClientGameInfoHandler.gameOverHumansWin); @@ -200,6 +209,8 @@ public class VoteHandler { } } } + Timer.humanAfterVoteTimer(); + LOGGER.info(game.getGameState().toString()); // set hasVoted to false for all passengers for future voting for (Passenger passenger : passengers) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostNPC.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostNPC.java index f0faaab..6eea800 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostNPC.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostNPC.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger; public class GhostNPC extends Ghost { public static final Logger LOGGER = LogManager.getLogger(GhostNPC.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); + public static final double probabilityToRingAlarmIfHeardNoise = 0.5; /** * Creates a new GhostNPC. Should be used at game start or if a HumanNPC is turned into a ghost. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostPlayer.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostPlayer.java index 271ea9d..8b1f961 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostPlayer.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/GhostPlayer.java @@ -1,6 +1,7 @@ package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData; import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler; @@ -14,6 +15,7 @@ public class GhostPlayer extends Ghost { public static final Logger LOGGER = LogManager.getLogger(GhostPlayer.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); + /** * Creates a new GhostPlayer. Should be used at game start or if a HumanPlayer is turned into a * ghost. @@ -48,6 +50,8 @@ public class GhostPlayer extends Ghost { String formattedMsg; if (msg.equals(GuiParameters.updateGameState)) { formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toGhostString(); + } else if (msg.equals(ClientGameInfoHandler.noiseNotification)) { + formattedMsg = Protocol.noiseNotificationProtocol; } else { formattedMsg = ServerGameInfoHandler.format(msg, this, game); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java index 8a8a6f7..f595628 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/HumanNPC.java @@ -10,6 +10,7 @@ public class HumanNPC extends Human { public static final Logger LOGGER = LogManager.getLogger(HumanNPC.class); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); + public static final double probabilityToRingAlarmIfHeardNoise = 0.9; /** * Creates a new HumanNPC. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Spectator.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Spectator.java index 338b8db..7baa834 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Spectator.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Spectator.java @@ -1,8 +1,10 @@ package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler; +import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -29,6 +31,11 @@ public class Spectator extends Passenger{ */ @Override public void send(String msg, Game game) { - clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, game)); + + if (msg.equals(ClientGameInfoHandler.noiseNotification)) { + clientHandler.sendMsgToClient(Protocol.noiseNotificationProtocol); + } else { + clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, game)); + } } } 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 ca96835..ff071f7 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 @@ -105,9 +105,13 @@ public class JClientProtocolParser { case "HV": Sound.voteforhuman(); break; + case "TH": + Sound.trainhorn(); + break; default: LOGGER.warn("Invalid sound request"); } + break; 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 45948d5..831a710 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 @@ -17,6 +17,9 @@ public class Sound { static URL bellURL = Sound.class.getResource("sounds/bell.wav"); static AudioClip bell = new AudioClip(bellURL.toString()); + static URL trainhornURL = Sound.class.getResource("sounds/trainhorn.wav"); + static AudioClip trainhorn = new AudioClip(trainhornURL.toString()); + static URL daynoisesURL = Sound.class.getResource("sounds/daynoises.wav"); static AudioClip daynoises = new AudioClip(daynoisesURL.toString()); @@ -41,6 +44,32 @@ public class Sound { static URL ghost04URL = Sound.class.getResource("sounds/ghost04.wav"); static AudioClip ghost04 = new AudioClip(ghost04URL.toString()); + static URL ghost05URL = Sound.class.getResource("sounds/ghost05.wav"); + static AudioClip ghost05 = new AudioClip(ghost05URL.toString()); + + static URL ghost06URL = Sound.class.getResource("sounds/ghost06.wav"); + static AudioClip ghost06 = new AudioClip(ghost06URL.toString()); + + static URL ghost07URL = Sound.class.getResource("sounds/ghost07.wav"); + static AudioClip ghost07 = new AudioClip(ghost07URL.toString()); + + static URL ghost08URL = Sound.class.getResource("sounds/ghost08.wav"); + static AudioClip ghost08 = new AudioClip(ghost08URL.toString()); + + static URL ghost09URL = Sound.class.getResource("sounds/ghost09.wav"); + static AudioClip ghost09 = new AudioClip(ghost09URL.toString()); + + static URL ghost10URL = Sound.class.getResource("sounds/ghost10.wav"); + static AudioClip ghost10 = new AudioClip(ghost10URL.toString()); + + static URL ghost11URL = Sound.class.getResource("sounds/ghost11.wav"); + static AudioClip ghost11 = new AudioClip(ghost11URL.toString()); + + static URL ghost12URL = Sound.class.getResource("sounds/ghost12.wav"); + static AudioClip ghost12 = new AudioClip(ghost12URL.toString()); + + + static URL musicdayURL = Sound.class.getResource("sounds/music_day.wav"); static AudioClip musicday = new AudioClip(musicdayURL.toString()); @@ -77,6 +106,8 @@ public class Sound { bell.play(defaultvolume - 0.5); } + public static void trainhorn() {trainhorn.play(defaultvolume); } + public static void startDaynoises() { daynoises.setCycleCount(AudioClip.INDEFINITE); daynoises.play(defaultvolume - 0.5); @@ -95,16 +126,28 @@ public class Sound { nightnoises.stop(); } - public static void gameoverghosts() { gameoverghosts.play(defaultvolume); } + public static void gameoverghosts() { + waitForABitThenEndDayMusic(); + voteforghost.stop(); + voteforhuman.stop(); + gameoverghosts.play(defaultvolume - 0.3); } public static void gameoverhumans() { - stopmusicday(); - gameoverhumans.play(defaultvolume); + waitForABitThenEndDayMusic(); + voteforghost.stop(); + voteforhuman.stop(); + gameoverhumans.play(defaultvolume - 0.1); } - public static void voteforghost() { voteforghost.play(defaultvolume); } + public static void voteforghost() { + waitForABitThenEndDayMusic(); + voteforghost.play(defaultvolume - 0.4); + } - public static void voteforhuman() { voteforhuman.play(defaultvolume); } + public static void voteforhuman() { + waitForABitThenEndDayMusic(); + voteforhuman.play(defaultvolume - 0.2); + } public static void musicday() { musicday.play(defaultvolume); @@ -116,8 +159,9 @@ public class Sound { } public static void ghost() { - double playbackspeed = (Math.random() / 5.0) + 0.9; - int ghostsoundnr = random.nextInt(4) + 1; + //double playbackspeed = (Math.random() / 5.0) + 0.9; causes aliasing artefacts :/ + double playbackspeed = 1; + int ghostsoundnr = random.nextInt(12) + 1; System.out.println(ghostsoundnr); AudioClip ghost; switch (ghostsoundnr) { @@ -130,13 +174,57 @@ public class Sound { case 3: ghost = ghost03; break; - default: + case 4: ghost = ghost04; break; + case 5: + ghost = ghost05; + break; + case 6: + ghost = ghost06; + break; + case 7: + ghost = ghost07; + break; + case 8: + ghost = ghost08; + break; + case 9: + ghost = ghost09; + break; + case 10: + ghost = ghost10; + break; + case 11: + ghost = ghost11; + break; + case 12: + ghost = ghost12; + break; + default: + ghost = ghost01; + break; } - ghost.play(0.1, 0.0, playbackspeed, 0.0, 5); + ghost.play(0.08, 0.0, playbackspeed, 0.0, 5); } + /** + * waits for a bit, then ends day music. :) + */ + public static void waitForABitThenEndDayMusic() { + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(1820); + //the time it takes for the vote result sound to ramp up, so the music ends exactly on the "big reveal" + } catch (InterruptedException e) { + e.printStackTrace(); + } + stopmusicday(); + } + }).start(); + } } 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 673cada..e7e4d21 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 @@ -215,7 +215,7 @@ public class Protocol { /** * 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) + * or when ghosts have won (PLSND$GW), or the train horn at the start of the game (PLSND$TH). Not used for ghost sounds. */ public static final String playSound = "PLSND"; diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost05.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost05.wav new file mode 100644 index 0000000..b9aed1b Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost05.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost06.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost06.wav new file mode 100644 index 0000000..6039263 Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost06.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost07.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost07.wav new file mode 100644 index 0000000..9d772da Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost07.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost08.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost08.wav new file mode 100644 index 0000000..30f1628 Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost08.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost09.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost09.wav new file mode 100644 index 0000000..a8f3642 Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost09.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost10.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost10.wav new file mode 100644 index 0000000..6a1c173 Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost10.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost11.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost11.wav new file mode 100644 index 0000000..999a5b8 Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost11.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost12.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost12.wav new file mode 100644 index 0000000..7e06818 Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/ghost12.wav differ diff --git a/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/trainhorn.wav b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/trainhorn.wav new file mode 100644 index 0000000..592b19f Binary files /dev/null and b/src/main/resources/ch/unibas/dmi/dbis/cs108/multiplayer/client/sounds/trainhorn.wav differ