Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e2bae5383b
@ -172,6 +172,14 @@ public class Game implements Runnable {
|
|||||||
if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) && getOgGhost().getIsPlayer()) {
|
if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) && getOgGhost().getIsPlayer()) {
|
||||||
OgGhostHighScore.addOgGhostWinner(getOgGhost().getName());
|
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);
|
lobby.getAdmin().broadcastAnnouncementToLobby(gameOverCheck);
|
||||||
isOngoing = false;
|
isOngoing = false;
|
||||||
Timer.ghostAfterVoteTimer();
|
Timer.ghostAfterVoteTimer();
|
||||||
|
|||||||
@ -16,13 +16,13 @@ public class Timer {
|
|||||||
/**
|
/**
|
||||||
* The maximum length of the ghost vote in the night, in seconds
|
* The maximum length of the ghost vote in the night, in seconds
|
||||||
*/
|
*/
|
||||||
public static final int ghostVoteTime = 30;
|
public static final int ghostVoteTime = 40;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The length of time in seconds after the ghost vote during which the ghosts visually walk to /
|
* 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.
|
* from their victim and the timespan within which humans will hear a noise. After this, the day starts.
|
||||||
*/
|
*/
|
||||||
public static final int ghostAfterVoteTime = 6;
|
public static final int ghostAfterVoteTime = 8;
|
||||||
/**
|
/**
|
||||||
* The maximum length of the human vote in the day, in seconds
|
* The maximum length of the human vote in the day, in seconds
|
||||||
*/
|
*/
|
||||||
@ -32,7 +32,7 @@ public class Timer {
|
|||||||
* The length of time in seconds after the human vote, as the 'winner' of the vote is announced,
|
* The length of time in seconds after the human vote, as the 'winner' of the vote is announced,
|
||||||
* before the night begins
|
* before the night begins
|
||||||
*/
|
*/
|
||||||
public static final int humanAfterVoteTime = 5;
|
public static final int humanAfterVoteTime = 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The checking interval in seconds
|
* The checking interval in seconds
|
||||||
|
|||||||
@ -91,6 +91,23 @@ public class JClientProtocolParser {
|
|||||||
case Protocol.noiseNotificationProtocol:
|
case Protocol.noiseNotificationProtocol:
|
||||||
Sound.ghost();
|
Sound.ghost();
|
||||||
break;
|
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:
|
default:
|
||||||
System.out.println("Received unknown command: " + msg);
|
System.out.println("Received unknown command: " + msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,14 @@ public class Sound {
|
|||||||
|
|
||||||
public static void gameoverghosts() { gameoverghosts.play(defaultvolume); }
|
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() {
|
public static void musicday() {
|
||||||
musicday.play(defaultvolume);
|
musicday.play(defaultvolume);
|
||||||
@ -127,7 +134,7 @@ public class Sound {
|
|||||||
ghost = ghost04;
|
ghost = ghost04;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ghost.play(defaultvolume - 0.3, 0.0, playbackspeed, 0.0, 5);
|
ghost.play(0.1, 0.0, playbackspeed, 0.0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
|
|||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class adds methods to listen if there is a change in the day&night state and calls methods accordingly
|
* This class adds methods to listen if there is a change in the day and night state and calls methods accordingly
|
||||||
*/
|
*/
|
||||||
public class DayNightChangeListener implements Runnable {
|
public class DayNightChangeListener implements Runnable {
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class DayNightChangeListener implements Runnable {
|
|||||||
chatApp.getGameController().updateRoomLabels();
|
chatApp.getGameController().updateRoomLabels();
|
||||||
gameStateModel.setRoleFromPosition(position);
|
gameStateModel.setRoleFromPosition(position);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game;
|
|||||||
|
|
||||||
import static javafx.scene.AccessibleRole.PARENT;
|
import static javafx.scene.AccessibleRole.PARENT;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.gamelogic.Timer;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Sound;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Sound;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
|
||||||
@ -39,7 +40,7 @@ public class GameController implements Initializable {
|
|||||||
public static final Logger LOGGER = LogManager.getLogger(GameController.class);
|
public static final Logger LOGGER = LogManager.getLogger(GameController.class);
|
||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
static boolean justRangBell = false; //used to track if the bell has been rung recently
|
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
|
static boolean playingDayNoises = true; //true if playing day noises, false if playing night noises
|
||||||
|
|
||||||
private static ClientModel client;
|
private static ClientModel client;
|
||||||
@ -534,17 +535,7 @@ public class GameController implements Initializable {
|
|||||||
try {
|
try {
|
||||||
if(!gameStateModel.getKickedOff()[0]) {
|
if(!gameStateModel.getKickedOff()[0]) {
|
||||||
Animation bell = new BellAnimation(noiseImage5, bells);
|
Animation bell = new BellAnimation(noiseImage5, bells);
|
||||||
//wait until it's day:
|
waitForDayThenRingBell(bell);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -565,16 +556,7 @@ public class GameController implements Initializable {
|
|||||||
try {
|
try {
|
||||||
if(!gameStateModel.getKickedOff()[1]) {
|
if(!gameStateModel.getKickedOff()[1]) {
|
||||||
Animation bell = new BellAnimation(noiseImage4, bells);
|
Animation bell = new BellAnimation(noiseImage4, bells);
|
||||||
//wait until it's day:
|
waitForDayThenRingBell(bell);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -594,17 +576,7 @@ public class GameController implements Initializable {
|
|||||||
try {
|
try {
|
||||||
if(!gameStateModel.getKickedOff()[2]) {
|
if(!gameStateModel.getKickedOff()[2]) {
|
||||||
Animation bell = new BellAnimation(noiseImage3, bells);
|
Animation bell = new BellAnimation(noiseImage3, bells);
|
||||||
//wait until it's day:
|
waitForDayThenRingBell(bell);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -624,17 +596,7 @@ public class GameController implements Initializable {
|
|||||||
try {
|
try {
|
||||||
if(!gameStateModel.getKickedOff()[3]) {
|
if(!gameStateModel.getKickedOff()[3]) {
|
||||||
Animation bell = new BellAnimation(noiseImage2, bells);
|
Animation bell = new BellAnimation(noiseImage2, bells);
|
||||||
//wait until it's day:
|
waitForDayThenRingBell(bell);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -654,17 +616,7 @@ public class GameController implements Initializable {
|
|||||||
try {
|
try {
|
||||||
if(!gameStateModel.getKickedOff()[4]) {
|
if(!gameStateModel.getKickedOff()[4]) {
|
||||||
Animation bell = new BellAnimation(noiseImage1, bells);
|
Animation bell = new BellAnimation(noiseImage1, bells);
|
||||||
//wait until it's day:
|
waitForDayThenRingBell(bell);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -684,16 +636,7 @@ public class GameController implements Initializable {
|
|||||||
try {
|
try {
|
||||||
if(!gameStateModel.getKickedOff()[5]) {
|
if(!gameStateModel.getKickedOff()[5]) {
|
||||||
Animation bell = new BellAnimation(noiseImage0, bells);
|
Animation bell = new BellAnimation(noiseImage0, bells);
|
||||||
//wait until it's day:
|
waitForDayThenRingBell(bell);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -734,6 +677,34 @@ public class GameController implements Initializable {
|
|||||||
ChatApp.setGameController(this);
|
ChatApp.setGameController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void waitForDayThenRingBell(Animation bell) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
//wait until it's day:
|
||||||
|
int timeoutCounter = 0; //otherwise this thread can get stuck in a loop if player leaves server
|
||||||
|
if (!getGameStateModel().getDayClone()) { //used to ring bell immediately if it's already day
|
||||||
|
while (!getGameStateModel().getDayClone()
|
||||||
|
&& timeoutCounter < Timer.ghostAfterVoteTime * 15) {
|
||||||
|
Thread.sleep(100);
|
||||||
|
timeoutCounter++;
|
||||||
|
}
|
||||||
|
//just so the alarm isn't rung exactly when the day starts, also add random delay
|
||||||
|
Thread.sleep(1000);
|
||||||
|
Random random = new Random();
|
||||||
|
Thread.sleep(random.nextInt(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
bell.play();
|
||||||
|
ringBellSound();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* plays bell sound, but only if it hasn't been played recently, to avoid artefacts due to
|
* plays bell sound, but only if it hasn't been played recently, to avoid artefacts due to
|
||||||
* overlapping sounds
|
* overlapping sounds
|
||||||
|
|||||||
@ -212,6 +212,13 @@ public class Protocol {
|
|||||||
*/
|
*/
|
||||||
public static final String noiseNotificationProtocol = "NOISE";
|
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
|
* 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}
|
* {@code POSOF$position}
|
||||||
|
|||||||
Reference in New Issue
Block a user