Made the whole thing a bit more orderly, added several loggers
This commit is contained in:
parent
d45d64a9c7
commit
46f75d3292
@ -103,9 +103,11 @@ public class Game implements Runnable {
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (true) { //ToDo: was ist die Abbruchbedingung? VoteHandler muss das schicken.
|
while (true) { //ToDo: was ist die Abbruchbedingung? VoteHandler muss das schicken.
|
||||||
if (!isDay) {
|
if (!isDay) {
|
||||||
|
LOGGER.info("NIGHT");
|
||||||
voteHandler.ghostVote(gameState.getPassengerTrain(), this);
|
voteHandler.ghostVote(gameState.getPassengerTrain(), this);
|
||||||
setDay(true);
|
setDay(true);
|
||||||
} else {
|
} else {
|
||||||
|
LOGGER.info("DAY");
|
||||||
gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this);
|
gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this);
|
||||||
}
|
}
|
||||||
if (gameOverCheck.equals("Game over: ghosts win!") || gameOverCheck.equals(
|
if (gameOverCheck.equals("Game over: ghosts win!") || gameOverCheck.equals(
|
||||||
|
|||||||
@ -110,7 +110,7 @@ public class GameState {
|
|||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
String[] print = new String[6];
|
String[] print = new String[6];
|
||||||
for (int i = 0; i < array.length; i++) {
|
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++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
|||||||
@ -40,14 +40,13 @@ public class VoteHandler {
|
|||||||
int[] votesForPlayers = new int[6];
|
int[] votesForPlayers = new int[6];
|
||||||
|
|
||||||
// Walk through entire train, ask ghosts to ghostify and humans to wait
|
// 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) {
|
for (Passenger passenger : passengers) {
|
||||||
if (passenger.getIsGhost()) {
|
if (passenger.getIsGhost()) {
|
||||||
|
|
||||||
passenger.send("Vote on who to ghostify!", game);
|
passenger.send("Vote on who to ghostify!", game);
|
||||||
} else {
|
} else {
|
||||||
passenger.send(
|
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
|
// this time, except chat is ignored
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -56,14 +55,16 @@ public class VoteHandler {
|
|||||||
try { // waits 20 seconds before votes get collected
|
try { // waits 20 seconds before votes get collected
|
||||||
Thread.sleep(30*1000);
|
Thread.sleep(30*1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (Passenger passenger : passengers) {
|
for (Passenger passenger : passengers) {
|
||||||
// collecting the votes - distribute them among the vote counters for all players
|
// 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
|
// 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.
|
// (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
|
// TODO: Perhaps the vote results should be handled by ClientGameInfoHandler
|
||||||
|
passenger.getVoteFromClientHandler();
|
||||||
if (passenger.getHasVoted()) {
|
if (passenger.getHasVoted()) {
|
||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
if (passenger.getVote() == i) {
|
if (passenger.getVote() == i) {
|
||||||
@ -135,7 +136,7 @@ public class VoteHandler {
|
|||||||
try { // waits 20 seconds before votes get collected
|
try { // waits 20 seconds before votes get collected
|
||||||
Thread.sleep(30*1000);
|
Thread.sleep(30*1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Passenger passenger : passengers) {
|
for (Passenger passenger : passengers) {
|
||||||
@ -143,8 +144,10 @@ public class VoteHandler {
|
|||||||
// TODO: Perhaps the vote results should be handled by ClientGameInfoHandler
|
// TODO: Perhaps the vote results should be handled by ClientGameInfoHandler
|
||||||
if (passenger.getHasVoted()) {
|
if (passenger.getHasVoted()) {
|
||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
|
LOGGER.info("Passenger: " + passenger.getPosition() + " voted for: " + passenger.getVote() );
|
||||||
if (passenger.getVote() == i) {
|
if (passenger.getVote() == i) {
|
||||||
votesForPlayers[i]++;
|
votesForPlayers[i]++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +159,6 @@ public class VoteHandler {
|
|||||||
for (int votesForPlayer : votesForPlayers) {
|
for (int votesForPlayer : votesForPlayers) {
|
||||||
if (votesForPlayer > currentMax) {
|
if (votesForPlayer > currentMax) {
|
||||||
currentMax = votesForPlayer;
|
currentMax = votesForPlayer;
|
||||||
LOGGER.info("Max amount of votes: " + currentMax);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// deal with voting results
|
// deal with voting results
|
||||||
@ -164,9 +166,9 @@ public class VoteHandler {
|
|||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
||||||
voteIndex = i;
|
voteIndex = i;
|
||||||
LOGGER.info("Player " + voteIndex + " has the most votes");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOGGER.info("Player " + voteIndex + " has the most votes");
|
||||||
if (!passengers[voteIndex]
|
if (!passengers[voteIndex]
|
||||||
.getIsGhost()) { // if player with most votes is human, notify everyone about it
|
.getIsGhost()) { // if player with most votes is human, notify everyone about it
|
||||||
for (Passenger passenger : passengers) {
|
for (Passenger passenger : passengers) {
|
||||||
|
|||||||
@ -109,6 +109,9 @@ public class Passenger {
|
|||||||
return clientHandler;
|
return clientHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When called by NPC nothing should happen, because clientHandler = null
|
||||||
|
*/
|
||||||
public void getVoteFromClientHandler() {
|
public void getVoteFromClientHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user