OG Ghost position is now truly randomized

This commit is contained in:
Seraina 2022-04-15 19:38:42 +02:00
parent 853f33479f
commit 82a4e42b3c
5 changed files with 26 additions and 28 deletions

View File

@ -71,7 +71,7 @@ public class Game implements Runnable {
int i = 0;
HashSet<ClientHandler> lobbyClients = lobby.getLobbyClients();
String gameOverCheck = "";
int[] order = gameState.getTrain().orderOfTrain;
int[] order = gameState.getTrain().getOrderOfTrain();
Passenger[] passengerTrain = gameState.getPassengerTrain();

View File

@ -52,16 +52,17 @@ 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) { //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();
g.setPosition(train.orderOfTrain[i]);
g.setPosition(train.getOrderOfTrain()[i]);
g.setGhost();
g.setIsOG(true);
passengerTrain[train.orderOfTrain[i]] = g;
passengerTrain[train.getOrderOfTrain()[i]] = g;
} else {
Human h = new Human();
h.setPosition(train.orderOfTrain[i]);
passengerTrain[train.orderOfTrain[i]] = h;
h.setPosition(train.getOrderOfTrain()[i]);
passengerTrain[train.getOrderOfTrain()[i]] = h;
}
}
@ -88,6 +89,10 @@ public class GameState {
return nrOfGhosts;
}
public ClientVoteData getClientVoteData() {
return clientVoteData;
}
/**
*
*

View File

@ -8,8 +8,8 @@ public class Train {
public static final Logger LOGGER = LogManager.getLogger(Train.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
int[] orderOfTrain; //gives the random order in which the passengers enter the train
int positionOfGhost; // useful for randomization of og ghost position
private int[] orderOfTrain; //gives the random order in which the passengers enter the train
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
@ -46,7 +46,15 @@ public class Train {
}
LOGGER.debug("The userTrain order is: " + Arrays.toString(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;
}
/**

View File

@ -21,21 +21,6 @@ public class VoteHandler {
public static final Logger LOGGER = LogManager.getLogger(VoteHandler.class);
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
* 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");
}
int currentMax = voteEvaluation(passengers, votesForPlayers, clientVoteData, game);
int currentMax = voteEvaluation(passengers, votesForPlayers, game.getGameState().getClientVoteData(), game);
LOGGER.debug("Most votes: " + currentMax + " vote");
@ -157,7 +142,7 @@ public class VoteHandler {
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
int voteIndex = 0;

View File

@ -298,9 +298,9 @@ public class ClientHandler implements Runnable {
}
LOGGER.debug("Vote is:" + vote);
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);
VoteHandler.getClientVoteData().setHasVoted(position,true); //TODO: move clientVoteData to gamestate
getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position,true); //TODO: move clientVoteData to gamestate
}
}