updated player / npc classes to work with ClientHandlers

This commit is contained in:
Jonas 2022-03-22 15:24:53 +01:00
parent 66b34dce60
commit c928119bbc
5 changed files with 17 additions and 11 deletions

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;
}
}