Bells only start during the day, also ghosts now make noises as originally intended
This commit is contained in:
parent
977f126073
commit
7a81987316
@ -363,3 +363,6 @@ Habe Highscore und Players in Lobbies auf die einfachst mögliche Art mit Textfl
|
||||
- Seraina: Animation von in-game-Hintergrund, GUI
|
||||
- Jonas: Sound design
|
||||
- Alex: Vorbereitung für Programmierung von unit tests mit Mockito
|
||||
|
||||
16.5.2022 - Jonas
|
||||
Have been working on implementing all sound effects over the last couple of days
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
||||
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
|
||||
/**
|
||||
* Handles all communication Client to Server concerning gamestate updates i.e. client a has voted
|
||||
* Maybe unnecessary, everything that is needed might already be implemented in ClientHandler.
|
||||
@ -16,7 +18,7 @@ public class ClientGameInfoHandler {
|
||||
//relevant for game logic:
|
||||
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 = "Someone passed by you ";
|
||||
public static final String noiseNotification = Protocol.noiseNotificationProtocol;
|
||||
public static final String gameOverHumansWin = "Game over, humans win!";
|
||||
public static final String gameOverGhostsWin = "Game over, ghosts win!";
|
||||
|
||||
|
||||
@ -120,6 +120,8 @@ public class ServerGameInfoHandler {
|
||||
case ClientGameInfoHandler.noiseNotification + 3 + " time(s)":
|
||||
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()) {
|
||||
@ -148,6 +150,8 @@ public class ServerGameInfoHandler {
|
||||
case ClientGameInfoHandler.noiseNotification + 3 + " time(s)":
|
||||
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);
|
||||
|
||||
@ -22,7 +22,7 @@ public class Timer {
|
||||
* The length of time in seconds after the ghost vote during which the ghosts visually walk to /
|
||||
* from their victim and the timespan within which humans will hear a noise. After this, the day starts.
|
||||
*/
|
||||
public static final int ghostAfterVoteTime = 4;
|
||||
public static final int ghostAfterVoteTime = 6;
|
||||
/**
|
||||
* The maximum length of the human vote in the day, in seconds
|
||||
*/
|
||||
@ -85,6 +85,14 @@ public class Timer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void humanAfterVoteTimer() {
|
||||
try {
|
||||
Thread.sleep(humanAfterVoteTime *1000);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all ghosts in the game have already voted, returns true if so
|
||||
* @param game the Game the ghosts live in
|
||||
|
||||
@ -95,7 +95,8 @@ public class VoteHandler {
|
||||
}
|
||||
for (int i = 0; i < passengers.length; i++) {
|
||||
if (noiseAmount[i] != 0) { // someone walked by this player
|
||||
passengers[i].send(ClientGameInfoHandler.noiseNotification + noiseAmount[i] + " time(s)", game);
|
||||
//passengers[i].send(ClientGameInfoHandler.noiseNotification + noiseAmount[i] + " time(s)", game); old version, might be useful
|
||||
passengers[i].send(ClientGameInfoHandler.noiseNotification, game);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +172,7 @@ public class VoteHandler {
|
||||
ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game);
|
||||
}
|
||||
}
|
||||
Timer.ghostAfterVoteTimer();
|
||||
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);
|
||||
|
||||
@ -32,7 +32,7 @@ public class HumanNPC extends Human {
|
||||
|
||||
/**
|
||||
* Sends a msg to the ServerGameInfoHandler.humanNpcParser to decide what has to happen now, if
|
||||
* the npc hasn't been kicked off 8(should never happen to a human though)
|
||||
* the npc hasn't been kicked off (should never happen to a human though)
|
||||
*
|
||||
* @param msg the message that is sent to this player.
|
||||
* @param game the game the HumanNPC lives on (in game.gameState.passengerTrain)
|
||||
|
||||
@ -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;
|
||||
@ -47,6 +48,8 @@ public class HumanPlayer extends Human {
|
||||
String formattedMsg;
|
||||
if (msg.equals(GuiParameters.updateGameState)) {
|
||||
formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().humanToString();
|
||||
} else if (msg.equals(ClientGameInfoHandler.noiseNotification)) {
|
||||
formattedMsg = Protocol.noiseNotificationProtocol;
|
||||
} else {
|
||||
formattedMsg = ServerGameInfoHandler.format(msg, this, game);
|
||||
}
|
||||
|
||||
@ -89,6 +89,9 @@ public class JClientProtocolParser {
|
||||
LOGGER.warn(msg.substring(6));
|
||||
}
|
||||
break;
|
||||
case Protocol.noiseNotificationProtocol:
|
||||
Sound.ghost();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Received unknown command: " + msg);
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ public class Sound {
|
||||
ghost = ghost04;
|
||||
break;
|
||||
}
|
||||
ghost.play(defaultvolume, 0.0, playbackspeed, 0.0, 5);
|
||||
ghost.play(defaultvolume - 0.3, 0.0, playbackspeed, 0.0, 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.animation.Animation;
|
||||
import javafx.application.Platform;
|
||||
@ -533,6 +534,15 @@ public class GameController implements Initializable {
|
||||
try {
|
||||
if(!gameStateModel.getKickedOff()[0]) {
|
||||
Animation bell = new BellAnimation(noiseImage5, bells);
|
||||
//wait until it's day:
|
||||
while (!getGameStateModel().getDayClone()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
//just so the alarm isn't rung exactly when the day starts, add random delay
|
||||
Random random = new Random();
|
||||
Thread.sleep(random.nextInt(1000));
|
||||
|
||||
bell.play();
|
||||
ringBellSound();
|
||||
}
|
||||
@ -555,6 +565,14 @@ public class GameController implements Initializable {
|
||||
try {
|
||||
if(!gameStateModel.getKickedOff()[1]) {
|
||||
Animation bell = new BellAnimation(noiseImage4, bells);
|
||||
//wait until it's day:
|
||||
while (!getGameStateModel().getDayClone()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
//just so the alarm isn't rung exactly when the day starts, add random delay
|
||||
Random random = new Random();
|
||||
Thread.sleep(random.nextInt(1000));
|
||||
bell.play();
|
||||
ringBellSound();
|
||||
}
|
||||
@ -576,6 +594,15 @@ public class GameController implements Initializable {
|
||||
try {
|
||||
if(!gameStateModel.getKickedOff()[2]) {
|
||||
Animation bell = new BellAnimation(noiseImage3, bells);
|
||||
//wait until it's day:
|
||||
while (!getGameStateModel().getDayClone()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
//just so the alarm isn't rung exactly when the day starts, add random delay
|
||||
Random random = new Random();
|
||||
Thread.sleep(random.nextInt(1000));
|
||||
|
||||
bell.play();
|
||||
ringBellSound();
|
||||
}
|
||||
@ -597,6 +624,15 @@ public class GameController implements Initializable {
|
||||
try {
|
||||
if(!gameStateModel.getKickedOff()[3]) {
|
||||
Animation bell = new BellAnimation(noiseImage2, bells);
|
||||
//wait until it's day:
|
||||
while (!getGameStateModel().getDayClone()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
//just so the alarm isn't rung exactly when the day starts, add random delay
|
||||
Random random = new Random();
|
||||
Thread.sleep(random.nextInt(1000));
|
||||
|
||||
bell.play();
|
||||
ringBellSound();
|
||||
}
|
||||
@ -618,6 +654,15 @@ public class GameController implements Initializable {
|
||||
try {
|
||||
if(!gameStateModel.getKickedOff()[4]) {
|
||||
Animation bell = new BellAnimation(noiseImage1, bells);
|
||||
//wait until it's day:
|
||||
while (!getGameStateModel().getDayClone()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
//just so the alarm isn't rung exactly when the day starts, add random delay
|
||||
Random random = new Random();
|
||||
Thread.sleep(random.nextInt(1000));
|
||||
|
||||
bell.play();
|
||||
ringBellSound();
|
||||
}
|
||||
@ -639,6 +684,14 @@ public class GameController implements Initializable {
|
||||
try {
|
||||
if(!gameStateModel.getKickedOff()[5]) {
|
||||
Animation bell = new BellAnimation(noiseImage0, bells);
|
||||
//wait until it's day:
|
||||
while (!getGameStateModel().getDayClone()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
//just so the alarm isn't rung exactly when the day starts, add random delay
|
||||
Random random = new Random();
|
||||
Thread.sleep(random.nextInt(1000));
|
||||
bell.play();
|
||||
ringBellSound();
|
||||
}
|
||||
|
||||
@ -207,6 +207,11 @@ public class Protocol {
|
||||
*/
|
||||
public static final String printToGUI = "PTGUI";
|
||||
|
||||
/**
|
||||
* Sent to a client to notify them that they heard a ghost noise, triggering the ghost SFX.
|
||||
*/
|
||||
public static final String noiseNotificationProtocol = "NOISE";
|
||||
|
||||
/**
|
||||
* 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}
|
||||
|
||||
Reference in New Issue
Block a user