Found the annoying issue, had to change run() to start() now it kinda works
This commit is contained in:
parent
1de2e739de
commit
d3a0c00dea
@ -19,7 +19,7 @@ public class BudaLogConfig {
|
||||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
Configuration config = ctx.getConfiguration();
|
||||
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.
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ public class ClientVoteData {
|
||||
|
||||
public ClientVoteData() {
|
||||
int[] h = new int[6];
|
||||
Arrays.fill(h,Integer.MAX_VALUE);
|
||||
Arrays.fill(h,0);
|
||||
this.vote = h;
|
||||
this.hasVoted = new boolean[6];
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ public class GameState {
|
||||
* contains all Passengers on train, needs to be updated
|
||||
*/
|
||||
private Passenger[] passengerTrain;
|
||||
private ClientVoteData clientVoteData;
|
||||
|
||||
|
||||
|
||||
@ -41,6 +42,7 @@ public class GameState {
|
||||
this.nrOfGhosts = nrOfGhosts;
|
||||
this.nrOfUsers = nrOfUsers;
|
||||
this.train = new Train(nrOfPlayers, nrOfUsers);
|
||||
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) {
|
||||
|
||||
@ -21,16 +21,21 @@ public class VoteHandler {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void setClientVoteData(ClientVoteData clientVoteData) {
|
||||
clientVoteData = clientVoteData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@ -49,8 +49,9 @@ public class HumanPlayer extends Human {
|
||||
vote = clientVoteData.getVote()[position];
|
||||
LOGGER.info("Human at Pos: " + position + " has voted for: " + vote);
|
||||
hasVoted = clientVoteData.getHasVoted()[position];
|
||||
clientVoteData.setVote(position,Integer.MAX_VALUE);
|
||||
clientVoteData.setHasVoted(position,false);
|
||||
LOGGER.debug(Arrays.toString(clientVoteData.getVote()));
|
||||
//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
|
||||
*/
|
||||
|
||||
@ -113,7 +113,7 @@ public class Passenger {
|
||||
* When called by NPC nothing should happen, because clientHandler = null
|
||||
*/
|
||||
public void getVoteFromGameState(ClientVoteData clientVoteData) {
|
||||
LOGGER.debug("a NPC called this method hopefully: " + position);
|
||||
//LOGGER.debug("a NPC called this method hopefully: " + position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -76,31 +76,32 @@ public class JServerProtocolParser {
|
||||
LOGGER.debug(Protocol.listLobbies + " command received from: " + h.getClientUserName());
|
||||
break;
|
||||
case Protocol.votedFor:
|
||||
LOGGER.debug("Made it here");
|
||||
msg = msg.substring(6);
|
||||
int msgIndex = msg.indexOf('$');
|
||||
int vote = Integer.MAX_VALUE;
|
||||
int position = 0;
|
||||
ClientVoteData clientVoteData = new ClientVoteData();
|
||||
LOGGER.debug("Message is " + msg.substring(6));
|
||||
LOGGER.debug("Message is " + msg);
|
||||
try {
|
||||
position = Integer.parseInt(msg.substring(0,msgIndex));
|
||||
vote = Integer.parseInt(msg.substring(msgIndex + 1));
|
||||
LOGGER.debug("Vote is:" + vote);
|
||||
} catch (Exception e) {
|
||||
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
|
||||
clientVoteData.setVote(position,vote);
|
||||
VoteHandler.getClientVoteData().setVote(position,vote);
|
||||
LOGGER.debug("Player vote: " + vote);
|
||||
clientVoteData.setHasVoted(position,true);
|
||||
VoteHandler.getClientVoteData().setHasVoted(position,true);
|
||||
}
|
||||
VoteHandler.setClientVoteData(clientVoteData);
|
||||
break;
|
||||
case Protocol.startANewGame:
|
||||
try {
|
||||
|
||||
Game game = new Game(h,6,1, ClientHandler.getConnectedClients().size());
|
||||
Thread t = new Thread(game);
|
||||
game.run();
|
||||
t.start();
|
||||
} catch (TrainOverflow e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user