Integrated noise handling so it would run, some bugs still to work out
This commit is contained in:
parent
062304719f
commit
850e09e0af
@ -58,6 +58,10 @@ public class Game implements Runnable {
|
||||
return nrOfUsers;
|
||||
}
|
||||
|
||||
public ClientHandler getClientHandler() {
|
||||
return clientHandler;
|
||||
}
|
||||
|
||||
public boolean getIsDay() {return isDay;}
|
||||
|
||||
public void setDay(boolean day) {
|
||||
|
||||
@ -48,7 +48,7 @@ public class GameState {
|
||||
clientVoteData = new ClientVoteData();
|
||||
Passenger[] passengerTrain = new Passenger[nrOfPlayers]; //Creates an array with Passengers with correlation positions (Train)
|
||||
for (int i = 0; i < nrOfPlayers; i++) {
|
||||
if (i == 3) {
|
||||
if (i == 3) { //TODO: randomize via Train.ghostposition
|
||||
Ghost g = new Ghost();
|
||||
g.setPosition(train.orderOfTrain[i]);
|
||||
g.setGhost();
|
||||
|
||||
@ -6,6 +6,7 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostNPC;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
||||
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;
|
||||
|
||||
@ -50,7 +51,7 @@ public class ServerGameInfoHandler {
|
||||
switch (msg) {
|
||||
case ClientGameInfoHandler.noiseNotification:
|
||||
//TODO(Seraina & Alex): noise handling
|
||||
npc.noise();
|
||||
game.getClientHandler().broadcastChatMessage(ClientGameInfoHandler.noiseNotification);
|
||||
break;
|
||||
case ClientGameInfoHandler.ghostVoteRequest:
|
||||
npc.vote(game);
|
||||
@ -68,7 +69,7 @@ public class ServerGameInfoHandler {
|
||||
public static void humanNpcParser(HumanNPC npc, String msg, Game game) {
|
||||
switch (msg) {
|
||||
case ClientGameInfoHandler.noiseNotification:
|
||||
npc.noise();
|
||||
game.getClientHandler().broadcastChatMessage(ClientGameInfoHandler.noiseNotification);
|
||||
break;
|
||||
case ClientGameInfoHandler.humanVoteRequest:
|
||||
npc.vote();
|
||||
|
||||
@ -113,6 +113,11 @@ public class VoteHandler {
|
||||
passengers[ghostPosition] = g;
|
||||
passengers[ghostPosition].send(
|
||||
ClientGameInfoHandler.youGotGhostyfied, game); // TODO: ServerGameInfoHandler might deal with this one
|
||||
try { // waits 20 seconds before votes get collected
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||
}
|
||||
|
||||
/* 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
|
||||
|
||||
@ -69,9 +69,6 @@ public class GhostNPC extends Ghost {
|
||||
* Decides what to do when a noise ist heard, currently just always broadcasts it
|
||||
* TODO: Make NPC smarter
|
||||
*/
|
||||
public void noise() {
|
||||
clientHandler.broadcastChatMessage("I heard some noise tonight");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class HumanNPC extends Human {
|
||||
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
@ -31,7 +32,8 @@ public class HumanNPC extends Human {
|
||||
|
||||
/**
|
||||
* Sends a msg to the ServerGameInfoHandler.humanNpcParser to decide what has to happen now
|
||||
* @param msg the message that is sent to this player.
|
||||
*
|
||||
* @param msg the message that is sent to this player.
|
||||
* @param game the game the HumanNPC lives on (in game.gameState.passengerTrain)
|
||||
*/
|
||||
@Override
|
||||
@ -41,16 +43,13 @@ public class HumanNPC extends Human {
|
||||
|
||||
/**
|
||||
* Currently returns a random integer for voting
|
||||
*
|
||||
* @return integer between 0 and 5
|
||||
*/
|
||||
public void vote(){
|
||||
int randomNr = (int) (Math.random()*6);
|
||||
public void vote() {
|
||||
int randomNr = (int) (Math.random() * 6);
|
||||
vote = randomNr;
|
||||
hasVoted = true;
|
||||
LOGGER.info("HumanNPC at Position: " + this.getPosition() + " has voted for: " + vote);
|
||||
}
|
||||
|
||||
public void noise() {
|
||||
clientHandler.broadcastChatMessage("I heard some noise tonight");
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ public class ClientHandler implements Runnable {
|
||||
if(vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid
|
||||
VoteHandler.getClientVoteData().setVote(position,vote);
|
||||
LOGGER.debug("Player vote: " + vote);
|
||||
VoteHandler.getClientVoteData().setHasVoted(position,true);
|
||||
VoteHandler.getClientVoteData().setHasVoted(position,true); //TODO: move clientVoteData to gamestate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user