Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sebastian Lenzlinger 2022-03-22 15:47:14 +01:00
commit ccf36dff19
7 changed files with 22 additions and 12 deletions

View File

@ -1,2 +1,2 @@
rootProject.name = 'example-project'
rootProject.name = 'Night Train to Budapest'

View File

@ -11,7 +11,7 @@ public class GhostNPC extends Ghost{
public GhostNPC(int position, String name, boolean isOG) {
this.isOG = isOG;
this.position = position;
this.sock = null;
this.clientHandler = null;
isGhost = true;
isPlayer = false;
kickedOff = false;

View File

@ -1,5 +1,7 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
import ch.unibas.dmi.dbis.cs108.Multiplayer.Server.ClientHandler;
import java.net.Socket;
public class GhostPlayer extends Ghost{
@ -8,12 +10,11 @@ public class GhostPlayer extends Ghost{
* Creates a new GhostPlayer. Should be used at game start or if a HumanPlayer is turned into a ghost.
* @param position position on the train
* @param name name. if null, then a default name is used.
* @param sock the socket for the player.
* @param isOG true if the ghost is the original ghost.
*/
public GhostPlayer(int position, String name, Socket sock, boolean isOG) {
public GhostPlayer(int position, String name, ClientHandler clientHandler, boolean isOG) {
this.position = position;
this.sock = sock;
this.clientHandler = clientHandler;
this.isOG = isOG;
isGhost = true;
isPlayer = true;

View File

@ -9,7 +9,7 @@ public class HumanNPC extends Human {
*/
public HumanNPC(int position, String name) {
this.position = position;
this.sock = null;
this.clientHandler = null;
isGhost = false;
isPlayer = false;
kickedOff = false;

View File

@ -1,5 +1,7 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
import ch.unibas.dmi.dbis.cs108.Multiplayer.Server.ClientHandler;
import java.net.Socket;
public class HumanPlayer extends Human{
@ -7,11 +9,10 @@ public class HumanPlayer extends Human{
* Creates a new GhostPlayer. Should be used at game start or if a HumanPlayer is turned into a ghost.
* @param position position on the train
* @param name name. if null, then a default name is used.
* @param sock the socket for the player.
*/
public HumanPlayer(int position, String name, Socket sock, boolean isOG) {
public HumanPlayer(int position, String name, ClientHandler clientHandler, boolean isOG) {
this.position = position;
this.sock = sock;
this.clientHandler = clientHandler;
isGhost = false;
isPlayer = true;
kickedOff = false;

View File

@ -1,5 +1,7 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
import ch.unibas.dmi.dbis.cs108.Multiplayer.Server.ClientHandler;
import java.net.Socket;
public class Passenger {
@ -8,9 +10,7 @@ public class Passenger {
protected Boolean isGhost; //boolean regarding if the player is a ghost. Could probably be removed since ghost is a subclass but I'm keeping it in.
protected Boolean isPlayer; //same here
protected Boolean kickedOff; //true if the player has been voted off.
protected Socket sock; //the socket for the client associated with this Passenger, for NPCs, this can be null.
//todo: maybe this should be a thread or some class instead of a socket? depends on client-server structure...
protected ClientHandler clientHandler; //the socket for the client associated with this Passenger, for NPCs, this can be null.
/**
* Sends a protocol message to the respective player.
@ -56,4 +56,8 @@ public class Passenger {
public Boolean getIsPlayer() {
return isPlayer;
}
public ClientHandler getClientHandler() {
return clientHandler;
}
}

View File

@ -47,6 +47,10 @@ public class ClientHandler implements Runnable{
}
}
public String getClientUserName() {
return clientUserName;
}
public void broadcastMessage(String msg) {
for (ClientHandler client : clientHandlers) {
try {