diff --git a/Meilenstein III/QA-Concept.pdf b/Meilenstein III/QA-Concept.pdf index f12bbf2..7fe644a 100644 Binary files a/Meilenstein III/QA-Concept.pdf and b/Meilenstein III/QA-Concept.pdf differ diff --git a/build.gradle b/build.gradle index 6832a06..8e8f567 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation 'org.apache.logging.log4j:log4j-api:2.17.1' implementation 'org.apache.logging.log4j:log4j-core:2.17.1' implementation 'org.openjfx:javafx-controls:18' + implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4' testImplementation('org.junit.jupiter:junit-jupiter:5.8.2') } 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 c2723c3..556635c 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 @@ -17,7 +17,7 @@ public class GameFunctions { int nrOfGhosts; // sets how many Ghosts we start witch int nrOfUsers; // safes how many clients are active in this Game Train train; // safes who sits where - Passenger[] passengerTrain; + public Passenger[] passengerTrain; /** * Constructs a GameFunctions instance where nrOfPlayers >= nrOfUsers. Fills passengerTrain with 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 e591a1c..553ad19 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 @@ -5,21 +5,23 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; public class GhostifyHandler { /** - * Changes passenger at position x to ghost. Monitors the times the ghostify method is being - * called. If it's being called for the first time, the ghostified player is being set as the - * original ghost. + * Changes passenger at position x to ghost and returns this ghost. Monitors the times the ghost method is being + * called. If it's being called for the first time, the ghostified player is being set as the original ghost. * * @param p Passenger to be ghostified */ - private static int ghostifyCallCounter = 0; + private static int ghostifyCallCounter = -1; - public void ghostify(Passenger p) { + public GhostPlayer ghost(Passenger p, Game game) { p.setGhost(); - if (ghostifyCallCounter == 0) { - GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true); - } else { - GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); - } + GhostPlayer g; ghostifyCallCounter++; + if (ghostifyCallCounter == 0) { + g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true); + } else { + g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); + } + game.gameFunctions.passengerTrain[g.getPosition()] = g; + 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 c71ad04..1efddc7 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 @@ -1,8 +1,12 @@ 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 ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Handles the event of voting for humans and ghosts. Differentiates between day and night (human @@ -16,19 +20,30 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; *
TODO: Think about if the timer needs to be implemented here or in the Game class
*/
public class VoteHandler {
- public void ghostVote(Passenger[] passengers) {
+ public static final Logger LOGGER = LogManager.getLogger();
+ public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
- // array to collect votes for all players during voting, i.e. votes for player 1 are saved in
+
+ /**
+ * TODO(Alex): Documentation
+ * @param passengers
+ */
+ public void ghostVote(Passenger[] passengers, Game game) {
+
+
+ // array to collect votes for all players during voting, i.e. votes for player 1 (passengers[0]) are saved in
// votesForPlayers[0]
int[] votesForPlayers = new int[6];
// Walk through entire train, ask ghosts to ghostify and humans to wait
- // TODO: 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) {
if (passenger.getIsGhost()) {
+ LOGGER.info("Send msg to Ghost in Position: " + passenger);
passenger.send("Vote on who to ghostify!");
} else {
- passenger.send("Please wait, ghosts are active");
+ passenger.send("Please wait, ghosts are active"); //TODO(Seraina): make sure whatever clients send in this time, except chat is ignored
+ LOGGER.info("Send msg to Human in Position: " + passenger);
}
}
@@ -54,18 +69,28 @@ public class VoteHandler {
currentMax = votesForPlayers[i];
}
}
+ LOGGER.info("Most votes" + currentMax);
// ghostify the player with most votes
+ int ghostPosition = 0;
for (int i = 0; i < votesForPlayers.length; i++) {
if (votesForPlayers[i] == currentMax) { // if player has most votes
- GhostifyHandler gh = new GhostifyHandler();
- gh.ghostify(passengers[i]);
- passengers[i].send(
- "You are now a ghost!"); // TODO: ServerGameInfoHandler might deal with this one
+ ghostPosition = i;
+ LOGGER.info("Most votes for Passenger" + i);
+
}
}
+ GhostifyHandler gh = new GhostifyHandler();
+ Ghost g = gh.ghost(passengers[ghostPosition],game);
+ passengers[ghostPosition] = g;
+ passengers[ghostPosition].send(
+ "You are now a ghost!"); // TODO: ServerGameInfoHandler might deal with this one
}
+ /**
+ * TODO(Alex): Documentation
+ * @param passengers
+ */
public void humanVote(Passenger[] passengers) {
// very similar to ghostVote, differs mostly in the way votes are handled
@@ -104,22 +129,21 @@ public class VoteHandler {
}
}
// deal with voting results
+ int voteIndex = 0;
for (int i = 0; i < votesForPlayers.length; i++) {
if (votesForPlayers[i] == currentMax) { // if player has most votes
- if (!passengers[i].getIsGhost()) { // if player with most votes is human, notify everyone about it
- for (Passenger passenger : passengers) {
- passenger.send(
- "You voted for a human!"); // TODO: ServerGameInfoHandler might be better to use here
- }
- }
- if (passengers[i].getIsGhost()) { // if player is a ghost
- // Now the case "ghost is og" and the case "ghost is not og" need to be handled
- /* TODO: I don't know how to get the information about a ghost being the OG because I'm accessing the players
- via the Passenger class which can't use the getIsOG method from the Ghost class. I (Alex) will try to
- solve this issue but if anyone can help please do!
- */
- }
+ voteIndex = i;
+
}
}
+ if (!passengers[voteIndex].getIsGhost()) { // if player with most votes is human, notify everyone about it
+ for (Passenger passenger : passengers) {
+ passenger.send(
+ "You voted for a human!"); // TODO: ServerGameInfoHandler might be better to use here
+ }
+ }
+ if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
+ if (passengers[voteIndex].i
+ }
}
}
diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Ghost.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Ghost.java
index edd6967..4456946 100644
--- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Ghost.java
+++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Ghost.java
@@ -8,7 +8,7 @@ public class Ghost extends Passenger {
public static final Logger LOGGER = LogManager.getLogger();
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
- protected boolean isOG; //true if the Ghost is the original ghost.
+ protected boolean isOG = false; //true if the Ghost is the original ghost false by default.
public boolean getIsOG() {
return isOG;
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 c2ee282..aa434b7 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
@@ -24,7 +24,9 @@ public class Passenger {
* @param msg the message that is sent to this player.
**/
public void send(String msg) {
- //todo: send protocol message to the respective client OR process messages for NPCS
+ //todo(Seraina): send protocol message to the respective client OR process messages for NPCS
+ int voteRandmom = (int) (Math.random() * 6);
+ this.vote = voteRandmom;
}
/**
diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/CentralServerData.java b/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/CentralServerData.java
new file mode 100644
index 0000000..2c8d7b1
--- /dev/null
+++ b/src/main/java/ch/unibas/dmi/dbis/cs108/sebaschi/CentralServerData.java
@@ -0,0 +1,29 @@
+package ch.unibas.dmi.dbis.cs108.sebaschi;
+
+import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
+import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
+import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
+import java.net.Socket;
+import java.util.Map;
+import java.util.Set;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * This Class Represents an Object containing different Maps, Lists and Sets wherein a server object
+ * can find all needed data. An instance of this object can also be passed to other class-objects uf
+ * they need the same data. This Class is used to query for information in collections.
+ */
+public class CentralServerData {
+
+ public static final Logger LOGGER = LogManager.getLogger();
+ public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
+
+ private Set