went over all classes and added docs where is appropriate and needed

This commit is contained in:
Seraina 2022-04-18 21:57:33 +02:00
parent d25b6c405d
commit 55147ce1cf
21 changed files with 66 additions and 64 deletions

View File

@ -8,7 +8,7 @@ import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.core.config.LoggerConfig;
/** /**
* *A Class that lets us set the RootLogger Level of all Classes in this Project
*/ */
public class BudaLogConfig { public class BudaLogConfig {

View File

@ -7,6 +7,11 @@ import java.net.InetAddress;
public class NightTrainToBudapest { public class NightTrainToBudapest {
/**
* The main Method of the jar build of this project. calls either the main method of the server or
* the main method of the client
* @param args the arguments are either client <hostadress>:<port> [<username>] or server <port>
*/
public static void main(String[] args) { public static void main(String[] args) {
try { try {
String clientOrServer = args[0]; String clientOrServer = args[0];

View File

@ -1,6 +1,5 @@
package ch.unibas.dmi.dbis.cs108.gamelogic; package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
/** /**
* Handles all communication Client to Server concerning gamestate updates i.e. client a has voted * Handles all communication Client to Server concerning gamestate updates i.e. client a has voted

View File

@ -81,7 +81,7 @@ public class Game implements Runnable {
LOGGER.info(gameState.toString()); LOGGER.info(gameState.toString());
for (ClientHandler client : lobbyClients) { for (ClientHandler client : lobbyClients) {//begins filling the train with clients
int index = order[i]; int index = order[i];
if (passengerTrain[index].getIsGhost()) { //if there is a ghost if (passengerTrain[index].getIsGhost()) { //if there is a ghost
GhostPlayer ghostPlayer = new GhostPlayer(passengerTrain[index].getPosition(), GhostPlayer ghostPlayer = new GhostPlayer(passengerTrain[index].getPosition(),
@ -94,7 +94,7 @@ public class Game implements Runnable {
} }
i++; i++;
} }
while (i < order.length) { while (i < order.length) {//fills the rest of the train with npcs
int index = order[i]; int index = order[i];
if (passengerTrain[index].getIsGhost()) { //if they are a ghost if (passengerTrain[index].getIsGhost()) { //if they are a ghost
GhostNPC ghostNPC = new GhostNPC(passengerTrain[index].getPosition(), "NPC" + passengerTrain[index].getPosition(),passengerTrain[index].getIsOG()); GhostNPC ghostNPC = new GhostNPC(passengerTrain[index].getPosition(), "NPC" + passengerTrain[index].getPosition(),passengerTrain[index].getIsOG());
@ -109,7 +109,7 @@ public class Game implements Runnable {
LOGGER.info(gameState.toString()); LOGGER.info(gameState.toString());
i = 0; i = 0;
while (isOngoing == true) { while (isOngoing == true) {//game cycle
if (!isDay) { if (!isDay) {
LOGGER.info("NIGHT"); LOGGER.info("NIGHT");
gameOverCheck = voteHandler.ghostVote(gameState.getPassengerTrain(), this); gameOverCheck = voteHandler.ghostVote(gameState.getPassengerTrain(), this);

View File

@ -7,8 +7,6 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Human;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import java.util.Arrays;
import java.util.HashSet;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -1,6 +1,6 @@
package ch.unibas.dmi.dbis.cs108.gamelogic; package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Ghost;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
/** /**

View File

@ -1,12 +1,10 @@
package ch.unibas.dmi.dbis.cs108.gamelogic; package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Ghost;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostNPC; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostNPC;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -75,8 +75,5 @@ public class Train {
return false; return false;
} }
public static void main(String[] args) {
System.out.println("Hallo");
}
} }

View File

@ -1,7 +1,6 @@
package ch.unibas.dmi.dbis.cs108.gamelogic; package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; 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 ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -1,7 +1,6 @@
package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -2,9 +2,7 @@ package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.GameState;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -77,10 +75,4 @@ public class GhostNPC extends Ghost {
} }
} }
/**
* Decides what to do when a noise ist heard, currently just always broadcasts it
* TODO: Make NPC smarter
*/
} }

View File

@ -1,7 +1,6 @@
package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -3,7 +3,6 @@ package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -23,7 +22,11 @@ public class Spectator extends Passenger{
isSpectator = true; isSpectator = true;
} }
/**
* Sends a message to the Client assosiated with this Spectator via ServerGameInfoHandler.spectatorFormat
* @param msg the message that is sent to this player.
* @param game the game the Passenger lives on
*/
@Override @Override
public void send(String msg, Game game) { public void send(String msg, Game game) {
clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, this, game)); clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, this, game));

View File

@ -62,7 +62,6 @@ public class Client {
sendMsgToServer(Protocol.clientLogin + "$" + systemName); sendMsgToServer(Protocol.clientLogin + "$" + systemName);
this.chatApp = new ChatApp(new ClientModel(systemName, this)); this.chatApp = new ChatApp(new ClientModel(systemName, this));
this.chatGui = new GUI(this.chatApp); this.chatGui = new GUI(this.chatApp);
chatGui.setName(systemName);
clientPinger = new ClientPinger(this, this.socket); clientPinger = new ClientPinger(this, this.socket);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -205,6 +204,10 @@ public class Client {
} }
} }
/**
* The main Method used for testing in IDE
* @param args not used in this main
*/
public static void main(String[] args) { public static void main(String[] args) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
String hostname; String hostname;
@ -239,6 +242,12 @@ public class Client {
} }
/**
* The main-method used for the jar build of this project
* @param address the IP address of the Server (can be localhost)
* @param port the port for the connection
* @param username the username of this client
*/
public static void main(InetAddress address, int port, String username) { public static void main(InetAddress address, int port, String username) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
Socket socket; Socket socket;

View File

@ -31,7 +31,6 @@ public class JClientProtocolParser {
} }
switch (header) { switch (header) {
case Protocol.pingFromServer: case Protocol.pingFromServer:
c.sendMsgToServer(Protocol.pingBack); c.sendMsgToServer(Protocol.pingBack);
break; break;
case Protocol.pingBack: case Protocol.pingBack:

View File

@ -11,16 +11,13 @@ public class GUI implements Runnable {
public static final Logger LOGGER = LogManager.getLogger(GUI.class); public static final Logger LOGGER = LogManager.getLogger(GUI.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
ChatApp chatApp; private ChatApp chatApp;
private String name;
public GUI(ChatApp chatApp) { public GUI(ChatApp chatApp) {
this.chatApp = chatApp; this.chatApp = chatApp;
} }
public void setName(String name) {
this.name = name;
}
/** /**
* When an object implementing interface {@code Runnable} is used to create a thread, starting the * When an object implementing interface {@code Runnable} is used to create a thread, starting the
@ -32,11 +29,9 @@ public class GUI implements Runnable {
* @see Thread#run() * @see Thread#run()
*/ */
@Override @Override
public void run() { public void run() {
LOGGER.info("here"); LOGGER.info("here");
//String name =
Application.launch(this.chatApp.getClass()); Application.launch(this.chatApp.getClass());
} }
} }

View File

@ -1,7 +1,6 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import java.net.URL; import java.net.URL;
import java.util.Objects; import java.util.Objects;
@ -25,19 +24,28 @@ public class ChatApp extends Application {
public ChatApp() { public ChatApp() {
super(); super();
LOGGER.info("Empty ChatApp constructor got called: "); LOGGER.info("Empty ChatApp constructor got called: ");
} }
public ChatApp(ClientModel clientModel) { public ChatApp(ClientModel clientM) {
this.clientModel = clientModel; clientModel = clientM;
this.chatController = new ChatController(clientModel); chatController = new ChatController(clientM);
} }
public static void setChatController( /**
ChatController chatC) { * Sets the ChatController for the Application, needs to be static, but only one application can
* be launched per programm
*
* @param chatC the ChatController to be linked to this chatApp
*/
public static void setChatController(ChatController chatC) {
chatController = chatC; chatController = chatC;
} }
/**
* Sets the non-static ClientModel field of this class
*
* @param cModel the non static ClientModel to be added
*/
public void setcModel(ClientModel cModel) { public void setcModel(ClientModel cModel) {
this.cModel = cModel; this.cModel = cModel;
} }
@ -54,6 +62,11 @@ public class ChatApp extends Application {
return clientModel; return clientModel;
} }
public ChatController getChatController() {
return chatController;
}
/** /**
* The main entry point for all JavaFX applications. The start method is called after the init * The main entry point for all JavaFX applications. The start method is called after the init
* method has returned, and after the system is ready for the application to begin running. * method has returned, and after the system is ready for the application to begin running.
@ -69,11 +82,9 @@ public class ChatApp extends Application {
*/ */
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
LOGGER.info("made it here");
this.setcModel(clientModel); this.setcModel(clientModel);
URL resource = ChatApp.class.getResource( URL resource = ChatApp.class.getResource(
"splitPaneChatView.fxml"); "splitPaneChatView.fxml");
LOGGER.info("1");
if (resource == null) { if (resource == null) {
System.out.println("File wasnt found"); System.out.println("File wasnt found");
} }
@ -82,23 +93,16 @@ public class ChatApp extends Application {
Parent root = FXMLLoader.load( Parent root = FXMLLoader.load(
Objects.requireNonNull(ChatApp.class.getResource( Objects.requireNonNull(ChatApp.class.getResource(
"splitPaneChatView.fxml"))); "splitPaneChatView.fxml")));
LOGGER.info("2");
// TODO bin chatController.getChatPaneRoot() border to root border for rezising // TODO bin chatController.getChatPaneRoot() border to root border for rezising
Scene scene = new Scene(root); Scene scene = new Scene(root);
LOGGER.info("3");
scene.setRoot(root); scene.setRoot(root);
LOGGER.info("4");
primaryStage.setScene(scene); primaryStage.setScene(scene);
LOGGER.info("5");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
primaryStage.setResizable(true); primaryStage.setResizable(true);
LOGGER.info("6");
primaryStage.setTitle("Chat"); primaryStage.setTitle("Chat");
LOGGER.info("7");
primaryStage.show(); primaryStage.show();
LOGGER.info("8");
} }
@ -107,7 +111,4 @@ public class ChatApp extends Application {
launch(args); launch(args);
} }
public ChatController getChatController() {
return chatController;
}
} }

View File

@ -22,7 +22,6 @@ import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.Background; import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -53,7 +52,10 @@ public class ChatController implements Initializable {
private static final String chatToAll = Protocol.chatMsgToAll; private static final String chatToAll = Protocol.chatMsgToAll;
private static final String chatToLobby = Protocol.chatMsgToLobby; private static final String chatToLobby = Protocol.chatMsgToLobby;
public ChatController() { //TODO: why does this get called /**
* Needs to stay, because it gets called in initialisation
*/
public ChatController() {
super(); super();
whisperTargetChosen = new SimpleBooleanProperty(); whisperTargetChosen = new SimpleBooleanProperty();
cmd = Protocol.chatMsgToLobby + "$"; cmd = Protocol.chatMsgToLobby + "$";
@ -154,13 +156,15 @@ public class ChatController implements Initializable {
} }
/** /**
* @return the client who's chat controller this is * @return the ClientModel whose chat controller this is
*/ */
public static ClientModel getClient() { public static ClientModel getClient() {
return client; return client;
} }
/** /**
* Sets the ClientModel of this ChatController
*
* @param client who's gui controller this should be * @param client who's gui controller this should be
*/ */
public void setClient(ClientModel client) { public void setClient(ClientModel client) {
@ -172,7 +176,7 @@ public class ChatController implements Initializable {
} }
/** /**
* The client calls this method to foreward a chat message to the chat gui * The client calls this method to forward a chat message to the chat gui
* *
* @param msg the message to be displayed * @param msg the message to be displayed
*/ */

View File

@ -3,7 +3,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -2,11 +2,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.server;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.GameState;
import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow;
import ch.unibas.dmi.dbis.cs108.gamelogic.VoteHandler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;

View File

@ -43,6 +43,9 @@ public class Server {
} }
} }
/**
* closes the Server socket of this server
*/
public void closeServerSocket() { public void closeServerSocket() {
try { try {
if (serverSocket != null) { if (serverSocket != null) {
@ -53,6 +56,10 @@ public class Server {
} }
} }
/**
* The main method used for testing
* @param args not used in this method
*/
public static void main(String[] args) { public static void main(String[] args) {
ServerSocket serverSocket = null; ServerSocket serverSocket = null;
gamePort = 1873; gamePort = 1873;
@ -65,6 +72,10 @@ public class Server {
server.startServer(); server.startServer();
} }
/**
* The main method of the Server that is used for the jar build of this project
* @param port the port the server will open on
*/
public static void main(int port) { public static void main(int port) {
gamePort = port; gamePort = port;
ServerSocket serverSocket = null; ServerSocket serverSocket = null;