OG Ghost position is now truly randomized
This commit is contained in:
parent
853f33479f
commit
82a4e42b3c
@ -71,7 +71,7 @@ public class Game implements Runnable {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
HashSet<ClientHandler> lobbyClients = lobby.getLobbyClients();
|
HashSet<ClientHandler> lobbyClients = lobby.getLobbyClients();
|
||||||
String gameOverCheck = "";
|
String gameOverCheck = "";
|
||||||
int[] order = gameState.getTrain().orderOfTrain;
|
int[] order = gameState.getTrain().getOrderOfTrain();
|
||||||
Passenger[] passengerTrain = gameState.getPassengerTrain();
|
Passenger[] passengerTrain = gameState.getPassengerTrain();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -52,16 +52,17 @@ public class GameState {
|
|||||||
clientVoteData = new ClientVoteData();
|
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) { //TODO: randomize via Train.ghostposition
|
if (i == train.getPositionOfGhost()) { //TODO: randomize via Train.ghostposition
|
||||||
|
LOGGER.info("OG position: " + train.getOrderOfTrain()[i]);
|
||||||
Ghost g = new Ghost();
|
Ghost g = new Ghost();
|
||||||
g.setPosition(train.orderOfTrain[i]);
|
g.setPosition(train.getOrderOfTrain()[i]);
|
||||||
g.setGhost();
|
g.setGhost();
|
||||||
g.setIsOG(true);
|
g.setIsOG(true);
|
||||||
passengerTrain[train.orderOfTrain[i]] = g;
|
passengerTrain[train.getOrderOfTrain()[i]] = g;
|
||||||
} else {
|
} else {
|
||||||
Human h = new Human();
|
Human h = new Human();
|
||||||
h.setPosition(train.orderOfTrain[i]);
|
h.setPosition(train.getOrderOfTrain()[i]);
|
||||||
passengerTrain[train.orderOfTrain[i]] = h;
|
passengerTrain[train.getOrderOfTrain()[i]] = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +89,10 @@ public class GameState {
|
|||||||
return nrOfGhosts;
|
return nrOfGhosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientVoteData getClientVoteData() {
|
||||||
|
return clientVoteData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|||||||
@ -8,8 +8,8 @@ public class Train {
|
|||||||
public static final Logger LOGGER = LogManager.getLogger(Train.class);
|
public static final Logger LOGGER = LogManager.getLogger(Train.class);
|
||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
int[] orderOfTrain; //gives the random order in which the passengers enter the train
|
private int[] orderOfTrain; //gives the random order in which the passengers enter the train
|
||||||
int positionOfGhost; // useful for randomization of og ghost position
|
private int positionOfGhost; // useful for randomization of og ghost position
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Train with orderOfTrain of the size nrOfPlayers, filled with a Random order of the
|
* Constructs a Train with orderOfTrain of the size nrOfPlayers, filled with a Random order of the
|
||||||
@ -46,7 +46,15 @@ public class Train {
|
|||||||
}
|
}
|
||||||
LOGGER.debug("The userTrain order is: " + Arrays.toString(userTrain));
|
LOGGER.debug("The userTrain order is: " + Arrays.toString(userTrain));
|
||||||
this.orderOfTrain = userTrain;
|
this.orderOfTrain = userTrain;
|
||||||
this.positionOfGhost = nrOfPlayers / 2;
|
this.positionOfGhost = (int) ((Math.random() * ((nrOfPlayers)) + 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getOrderOfTrain() {
|
||||||
|
return orderOfTrain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPositionOfGhost() {
|
||||||
|
return positionOfGhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -21,21 +21,6 @@ public class VoteHandler {
|
|||||||
public static final Logger LOGGER = LogManager.getLogger(VoteHandler.class);
|
public static final Logger LOGGER = LogManager.getLogger(VoteHandler.class);
|
||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
private static ClientVoteData clientVoteData = new ClientVoteData();
|
|
||||||
|
|
||||||
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
|
* 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
|
||||||
@ -72,7 +57,7 @@ public class VoteHandler {
|
|||||||
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentMax = voteEvaluation(passengers, votesForPlayers, clientVoteData, game);
|
int currentMax = voteEvaluation(passengers, votesForPlayers, game.getGameState().getClientVoteData(), game);
|
||||||
|
|
||||||
LOGGER.debug("Most votes: " + currentMax + " vote");
|
LOGGER.debug("Most votes: " + currentMax + " vote");
|
||||||
|
|
||||||
@ -157,7 +142,7 @@ public class VoteHandler {
|
|||||||
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentMax = voteEvaluation(passengers, votesForPlayers, clientVoteData, game);
|
int currentMax = voteEvaluation(passengers, votesForPlayers, game.getGameState().getClientVoteData(), game);
|
||||||
|
|
||||||
// deal with voting results
|
// deal with voting results
|
||||||
int voteIndex = 0;
|
int voteIndex = 0;
|
||||||
|
|||||||
@ -298,9 +298,9 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
LOGGER.debug("Vote is:" + vote);
|
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
|
||||||
VoteHandler.getClientVoteData().setVote(position,vote);
|
getLobby().getGame().getGameState().getClientVoteData().setVote(position,vote);
|
||||||
LOGGER.debug("Player vote: " + vote);
|
LOGGER.debug("Player vote: " + vote);
|
||||||
VoteHandler.getClientVoteData().setHasVoted(position,true); //TODO: move clientVoteData to gamestate
|
getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position,true); //TODO: move clientVoteData to gamestate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user