diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameFunctions.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameFunctions.java index 6d521ef..0ca27de 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameFunctions.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GameFunctions.java @@ -38,7 +38,7 @@ public class GameFunctions { for (int i = 0; i < nrOfPlayers; i++) { Human h = new Human(); h.setPosition(train.orderOfTrain[i]); - passengerTrain[i] = h; + passengerTrain[train.orderOfTrain[i]] = h; } this.passengerTrain = passengerTrain; } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java index f95a887..f3ea707 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java @@ -1,6 +1,7 @@ package ch.unibas.dmi.dbis.cs108.gamelogic; import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Ghost; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; import org.apache.logging.log4j.LogManager; @@ -16,10 +17,13 @@ public class GhostifyHandler { * @param p Passenger to be ghostified */ - public GhostPlayer ghost(Passenger p, Game game) { + public Ghost ghost(Passenger p, Game game) { //TODO: Adjust for not only players but also npcs + LOGGER.debug("Passenger Position " + p.getPosition()); p.setGhost(); - GhostPlayer g; - g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); + Ghost g; + g = new Ghost(); + g.setGhost(); + g.setPosition(p.getPosition()); game.gameFunctions.passengerTrain[g.getPosition()] = g; LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified"); return g; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java index 2264ba7..f1b5c74 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java @@ -83,8 +83,10 @@ public class VoteHandler { if (votesForPlayers[i] == currentMax) { // if player at position i has most votes ghostPosition = i; LOGGER.info("Most votes for Passenger " + i); + } } + LOGGER.debug("ghostPosition: " + ghostPosition); GhostifyHandler gh = new GhostifyHandler(); Ghost g = gh.ghost(passengers[ghostPosition], game); passengers[ghostPosition] = g; @@ -170,9 +172,9 @@ public class VoteHandler { if (!passenger.getIsGhost()) { humans++; } - if (humans == 1) { - System.out.println("Game over: ghosts win!"); - } + } + if (humans == 1) { + System.out.println("Game over: ghosts win!"); } // Usual case: there is more than one human left and a normal ghost has been voted for --> // kick this ghost off @@ -192,10 +194,14 @@ public class VoteHandler { System.out.println(); String[] print = new String[6]; for (int i = 0; i < array.length; i++) { - if(array[i].getIsGhost()) { - print[i] = "| ghost |"; + if (array[i].getKickedOff()) { + print[i] = "| kicked off " + array[i].getPosition() + "|"; } else { - print[i] = "| human |"; + if (array[i].getIsGhost()) { + print[i] = "| ghost " + array[i].getPosition() + "|"; + } else { + print[i] = "| human " + array[i].getPosition() + "|"; + } } } @@ -215,6 +221,7 @@ public class VoteHandler { testArray[3] = ghost; testArray[3].setGhost(); testArray[3].setIsOg(); + testArray[3].setPosition(3); print(testArray); LOGGER.info("NIGHT"); ghostVote(testArray,game); @@ -224,6 +231,13 @@ public class VoteHandler { humanVote(testArray, game); print(testArray); + LOGGER.info("NIGHT"); + ghostVote(testArray,game); + print(testArray); + + LOGGER.info("Day"); + humanVote(testArray, game); + print(testArray); } catch (TrainOverflow e) { LOGGER.warn(e.getMessage()); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java index 7e19bc2..aa52c83 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java @@ -19,17 +19,23 @@ public class Passenger { protected ClientHandler clientHandler;//the socket for the client associated with this Passenger, for NPCs, this can be null. protected boolean hasVoted; //true if the player gave his vote during voting time protected int vote; //saves the number of the player this passenger voted for during voting (0-5) - + int sendcounter = 0; /** * Sends a protocol message to the respective player or NPC. * @param msg the message that is sent to this player. **/ public void send(String msg) { - if (msg.equals("Vote on who to ghostify!") || msg.equals("Vote for a ghost to kick off!")) { - vote = 1; + sendcounter++; + if (msg.equals("Vote on who to ghostify!")) { + vote = 1*sendcounter; + hasVoted = true; // for testing, when is it set to false again? + LOGGER.info("Voted for Position " + vote); + } else if(msg.equals("Vote for a ghost to kick off!")) { + vote = (int) (0.5*sendcounter); hasVoted = true; // for testing, when is it set to false again? LOGGER.info("Voted for Position " + vote); } else { + LOGGER.debug(msg); } /*if (isPlayer) {