Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
51d969e298
Binary file not shown.
@ -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')
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
* <p>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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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<Client> clientsOnServer;
|
||||
private Set<Game> activeGames;
|
||||
private Set<Game> gamesOpenToJoin;
|
||||
|
||||
private Map<Client, Socket> clientSocketMap;
|
||||
private Map<Socket, Client> socketClientMap;
|
||||
private Map<Game, Client> gameClientMap;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package ch.unibas.dmi.dbis.cs108.sebaschi;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Ghost;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.util.Set;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Class that shall contain all non-game logik information relevant to a game session needed for
|
||||
* client-server and client-client communication.
|
||||
*/
|
||||
public class GameSessionData {
|
||||
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
CentralServerData globalData;
|
||||
|
||||
Set<Passenger> passengers;
|
||||
Set<BufferedOutputStream> clientOutputStreams;
|
||||
Set<Ghost> ghosts;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package ch.unibas.dmi.dbis.cs108.sebaschi;
|
||||
|
||||
/**
|
||||
* This class is just everyone on the server, which games are open to join, who is in session. I.E.
|
||||
* the context of the game just after joining the server, before starting a game and entering into a
|
||||
* lobby.
|
||||
*/
|
||||
public class ServerLobby {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user