Added adjustments for the testing of voteHandler

- main methode
- a print methode, that prints out a Passenger array
This commit is contained in:
Seraina 2022-04-08 11:10:05 +02:00
parent efdd1167d2
commit 913d0781de
3 changed files with 55 additions and 6 deletions

View File

@ -40,6 +40,7 @@ public class GameFunctions {
h.setPosition(train.orderOfTrain[i]); h.setPosition(train.orderOfTrain[i]);
passengerTrain[i] = h; passengerTrain[i] = h;
} }
this.passengerTrain = passengerTrain;
} }
public int getNrOfGhosts() { public int getNrOfGhosts() {

View File

@ -31,7 +31,7 @@ public class VoteHandler {
* *
* @param passengers: passengers on the train * @param passengers: passengers on the train
*/ */
public void ghostVote(Passenger[] passengers, Game game) { public static void ghostVote(Passenger[] passengers, Game game) {
// array to collect votes for all players during voting, i.e. votes for player 1 (passengers[0]) // array to collect votes for all players during voting, i.e. votes for player 1 (passengers[0])
// are saved in // are saved in
@ -42,13 +42,13 @@ public class VoteHandler {
// TODO(Seraina): Messages in for-loop should probably be handled by ServerGameInfoHandler // 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()) {
LOGGER.info("Send msg to Ghost in Position: " + passenger);
passenger.send("Vote on who to ghostify!"); passenger.send("Vote on who to ghostify!");
} else { } else {
passenger.send( passenger.send(
"Please wait, ghosts are active"); // TODO(Seraina): make sure whatever clients send in "Please wait, ghosts are active"); // TODO(Seraina): make sure whatever clients send in
// this time, except chat is ignored // this time, except chat is ignored
LOGGER.info("Send msg to Human in Position: " + passenger);
} }
} }
@ -100,7 +100,7 @@ public class VoteHandler {
* *
* @param passengers: train passengers * @param passengers: train passengers
*/ */
public void humanVote(Passenger[] passengers) { public static void humanVote(Passenger[] passengers) {
// array to collect votes for all players during voting, i.e. votes for player 1 are saved in // array to collect votes for all players during voting, i.e. votes for player 1 are saved in
// votesForPlayers[0] // votesForPlayers[0]
@ -177,4 +177,48 @@ public class VoteHandler {
} }
} }
} }
static void print(Passenger[] array) {
System.out.println();
String[] print = new String[6];
for (int i = 0; i < array.length; i++) {
if(array[i].getIsGhost()) {
print[i] = "| ghost |";
} else {
print[i] = "| human |";
}
}
for (int i = 0; i < array.length; i++) {
System.out.print(print[i]);
}
System.out.println();
}
public static void main(String[] args) {
try {
Game game = new Game(6,1, 6);
Passenger[] testArray = game.gameFunctions.passengerTrain;
Passenger ghost = new Ghost();
testArray[3] = ghost;
testArray[3].setGhost();
testArray[3].setIsOg();
print(testArray);
LOGGER.info("NIGHT");
ghostVote(testArray,game);
print(testArray);
LOGGER.info("Day");
humanVote(testArray);
print(testArray);
} catch (TrainOverflow e) {
LOGGER.warn(e.getMessage());
}
}
} }

View File

@ -26,9 +26,9 @@ public class Passenger {
**/ **/
public void send(String msg) { public void send(String msg) {
if (msg.equals("Vote on who to ghostify!") || msg.equals("Vote for a ghost to kick off!")) { if (msg.equals("Vote on who to ghostify!") || msg.equals("Vote for a ghost to kick off!")) {
vote = (int) (Math.random() * 6); vote = 1;
hasVoted = true; // for testing, when is it set to false again? hasVoted = true; // for testing, when is it set to false again?
LOGGER.info("Voted for Position" + vote); LOGGER.info("Voted for Position " + vote);
} else { } else {
LOGGER.debug(msg); LOGGER.debug(msg);
} }
@ -76,6 +76,10 @@ public class Passenger {
hasVoted = true; hasVoted = true;
} }
public void setIsOg() {
isOG = true;
}
public int getPosition() { public int getPosition() {
return position; return position;
} }