Found the annoying issue, had to change run() to start() now it kinda works

This commit is contained in:
Seraina 2022-04-09 17:55:27 +02:00
parent 1de2e739de
commit d3a0c00dea
7 changed files with 22 additions and 13 deletions

View File

@ -19,7 +19,7 @@ public class BudaLogConfig {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false); LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration(); Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.DEBUG); // change level here loggerConfig.setLevel(Level.INFO); // change level here
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig. ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
} }

View File

@ -9,7 +9,7 @@ public class ClientVoteData {
public ClientVoteData() { public ClientVoteData() {
int[] h = new int[6]; int[] h = new int[6];
Arrays.fill(h,Integer.MAX_VALUE); Arrays.fill(h,0);
this.vote = h; this.vote = h;
this.hasVoted = new boolean[6]; this.hasVoted = new boolean[6];
} }

View File

@ -23,6 +23,7 @@ public class GameState {
* contains all Passengers on train, needs to be updated * contains all Passengers on train, needs to be updated
*/ */
private Passenger[] passengerTrain; private Passenger[] passengerTrain;
private ClientVoteData clientVoteData;
@ -41,6 +42,7 @@ public class GameState {
this.nrOfGhosts = nrOfGhosts; this.nrOfGhosts = nrOfGhosts;
this.nrOfUsers = nrOfUsers; this.nrOfUsers = nrOfUsers;
this.train = new Train(nrOfPlayers, nrOfUsers); this.train = new Train(nrOfPlayers, nrOfUsers);
clientVoteData = new ClientVoteData();
Passenger[] passengerTrain = new Passenger[nrOfPlayers]; //Creates an array with Passengers with correlation positions (Train) Passenger[] passengerTrain = new Passenger[nrOfPlayers]; //Creates an array with Passengers with correlation positions (Train)
for (int i = 0; i < nrOfPlayers; i++) { for (int i = 0; i < nrOfPlayers; i++) {
if (i == 3) { if (i == 3) {

View File

@ -21,16 +21,21 @@ public class VoteHandler {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
private ClientVoteData clientVoteData; private static ClientVoteData clientVoteData = new ClientVoteData();
public ClientVoteData getClientVoteData() { public static ClientVoteData getClientVoteData() {
return clientVoteData; return clientVoteData;
} }
public static void setClientVoteData(ClientVoteData clientVoteData) { public static void setClientVoteData(ClientVoteData clientVoteData) {
clientVoteData = clientVoteData; clientVoteData = clientVoteData;
} }
/** /**
* Handles the ghost vote during nighttime: passengers who are ghosts are being asked on who to * Handles the ghost vote during nighttime: passengers who are ghosts are being asked on who to
* ghostify, others are waiting. Results are being collected and the player with most votes is * ghostify, others are waiting. Results are being collected and the player with most votes is

View File

@ -49,8 +49,9 @@ public class HumanPlayer extends Human {
vote = clientVoteData.getVote()[position]; vote = clientVoteData.getVote()[position];
LOGGER.info("Human at Pos: " + position + " has voted for: " + vote); LOGGER.info("Human at Pos: " + position + " has voted for: " + vote);
hasVoted = clientVoteData.getHasVoted()[position]; hasVoted = clientVoteData.getHasVoted()[position];
clientVoteData.setVote(position,Integer.MAX_VALUE); LOGGER.debug(Arrays.toString(clientVoteData.getVote()));
clientVoteData.setHasVoted(position,false); //clientVoteData.setVote(position,Integer.MAX_VALUE);
//clientVoteData.setHasVoted(position,false);
/* /*
* if vote wasn't valid, make sure, the passenger field hasVoted == false, probably redundant but better be safe than sorry * if vote wasn't valid, make sure, the passenger field hasVoted == false, probably redundant but better be safe than sorry
*/ */

View File

@ -113,7 +113,7 @@ public class Passenger {
* When called by NPC nothing should happen, because clientHandler = null * When called by NPC nothing should happen, because clientHandler = null
*/ */
public void getVoteFromGameState(ClientVoteData clientVoteData) { public void getVoteFromGameState(ClientVoteData clientVoteData) {
LOGGER.debug("a NPC called this method hopefully: " + position); //LOGGER.debug("a NPC called this method hopefully: " + position);
} }
} }

View File

@ -76,31 +76,32 @@ public class JServerProtocolParser {
LOGGER.debug(Protocol.listLobbies + " command received from: " + h.getClientUserName()); LOGGER.debug(Protocol.listLobbies + " command received from: " + h.getClientUserName());
break; break;
case Protocol.votedFor: case Protocol.votedFor:
LOGGER.debug("Made it here");
msg = msg.substring(6); msg = msg.substring(6);
int msgIndex = msg.indexOf('$'); int msgIndex = msg.indexOf('$');
int vote = Integer.MAX_VALUE; int vote = Integer.MAX_VALUE;
int position = 0; int position = 0;
ClientVoteData clientVoteData = new ClientVoteData(); LOGGER.debug("Message is " + msg);
LOGGER.debug("Message is " + msg.substring(6));
try { try {
position = Integer.parseInt(msg.substring(0,msgIndex)); position = Integer.parseInt(msg.substring(0,msgIndex));
vote = Integer.parseInt(msg.substring(msgIndex + 1)); vote = Integer.parseInt(msg.substring(msgIndex + 1));
LOGGER.debug("Vote is:" + vote);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("Invalid vote " + e.getMessage()); LOGGER.warn("Invalid vote " + e.getMessage());
} }
LOGGER.debug("Vote is:" + vote);
if(vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid if(vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid
clientVoteData.setVote(position,vote); VoteHandler.getClientVoteData().setVote(position,vote);
LOGGER.debug("Player vote: " + vote); LOGGER.debug("Player vote: " + vote);
clientVoteData.setHasVoted(position,true); VoteHandler.getClientVoteData().setHasVoted(position,true);
} }
VoteHandler.setClientVoteData(clientVoteData);
break; break;
case Protocol.startANewGame: case Protocol.startANewGame:
try { try {
Game game = new Game(h,6,1, ClientHandler.getConnectedClients().size()); Game game = new Game(h,6,1, ClientHandler.getConnectedClients().size());
Thread t = new Thread(game); Thread t = new Thread(game);
game.run(); t.start();
} catch (TrainOverflow e) { } catch (TrainOverflow e) {
LOGGER.warn(e.getMessage()); LOGGER.warn(e.getMessage());
} }