Made the whole thing a bit more orderly, added several loggers

This commit is contained in:
Seraina 2022-04-09 11:53:43 +02:00
parent d45d64a9c7
commit 46f75d3292
4 changed files with 14 additions and 7 deletions

View File

@ -103,9 +103,11 @@ public class Game implements Runnable {
i = 0;
while (true) { //ToDo: was ist die Abbruchbedingung? VoteHandler muss das schicken.
if (!isDay) {
LOGGER.info("NIGHT");
voteHandler.ghostVote(gameState.getPassengerTrain(), this);
setDay(true);
} else {
LOGGER.info("DAY");
gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this);
}
if (gameOverCheck.equals("Game over: ghosts win!") || gameOverCheck.equals(

View File

@ -110,7 +110,7 @@ public class GameState {
StringBuilder stringBuilder = new StringBuilder();
String[] print = new String[6];
for (int i = 0; i < array.length; i++) {
print[i] = "| " + array[i].getName() + ": " + array[i].getPosition() + "|";
print[i] = "| " + array[i].getName() + ": " + array[i].getPosition() + "|";
}
for (int i = 0; i < array.length; i++) {

View File

@ -40,14 +40,13 @@ public class VoteHandler {
int[] votesForPlayers = new int[6];
// Walk through entire train, ask ghosts to ghostify and humans to wait
// TODO(Seraina): Messages in for-loop should probably be handled by ServerGameInfoHandler
for (Passenger passenger : passengers) {
if (passenger.getIsGhost()) {
passenger.send("Vote on who to ghostify!", game);
} else {
passenger.send(
"Please wait, ghosts are active", game); // TODO(Seraina): make sure whatever clients send in
"Please wait, ghosts are active", game);
// this time, except chat is ignored
}
@ -56,14 +55,16 @@ public class VoteHandler {
try { // waits 20 seconds before votes get collected
Thread.sleep(30*1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
}
for (Passenger passenger : passengers) {
// collecting the votes - distribute them among the vote counters for all players
// Note: Each voting collects votes for all players even though some might not be concerned
// (i.e. ghosts during ghost vote). Those players will then get 0 votes so it doesn't matter.
// TODO: Perhaps the vote results should be handled by ClientGameInfoHandler
passenger.getVoteFromClientHandler();
if (passenger.getHasVoted()) {
for (int i = 0; i < votesForPlayers.length; i++) {
if (passenger.getVote() == i) {
@ -135,7 +136,7 @@ public class VoteHandler {
try { // waits 20 seconds before votes get collected
Thread.sleep(30*1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
}
for (Passenger passenger : passengers) {
@ -143,8 +144,10 @@ public class VoteHandler {
// TODO: Perhaps the vote results should be handled by ClientGameInfoHandler
if (passenger.getHasVoted()) {
for (int i = 0; i < votesForPlayers.length; i++) {
LOGGER.info("Passenger: " + passenger.getPosition() + " voted for: " + passenger.getVote() );
if (passenger.getVote() == i) {
votesForPlayers[i]++;
}
}
}
@ -156,7 +159,6 @@ public class VoteHandler {
for (int votesForPlayer : votesForPlayers) {
if (votesForPlayer > currentMax) {
currentMax = votesForPlayer;
LOGGER.info("Max amount of votes: " + currentMax);
}
}
// deal with voting results
@ -164,9 +166,9 @@ public class VoteHandler {
for (int i = 0; i < votesForPlayers.length; i++) {
if (votesForPlayers[i] == currentMax) { // if player has most votes
voteIndex = i;
LOGGER.info("Player " + voteIndex + " has the most votes");
}
}
LOGGER.info("Player " + voteIndex + " has the most votes");
if (!passengers[voteIndex]
.getIsGhost()) { // if player with most votes is human, notify everyone about it
for (Passenger passenger : passengers) {

View File

@ -109,6 +109,9 @@ public class Passenger {
return clientHandler;
}
/**
* When called by NPC nothing should happen, because clientHandler = null
*/
public void getVoteFromClientHandler() {
}