Merge remote-tracking branch 'origin/master'

This commit is contained in:
Seraina 2022-03-18 11:08:34 +01:00
commit 6b4f14d294
7 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,9 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
public class Ghost extends Passenger {
protected boolean isOG; //true if the Ghost is the original ghost.
public boolean getIsOG() {
return isOG;
}
}

View File

@ -0,0 +1,22 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
public class GhostNPC extends Ghost{
/**
* Creates a new GhostNPC. Should be used at game start or if a HumanNPC is turned into a ghost.
* @param position position on the train
* @param name player name. if null, then a default name is used.
* @param isOG true if the ghost is the original ghost.
*/
public GhostNPC(int position, String name, boolean isOG) {
this.isOG = isOG;
this.position = position;
this.sock = null;
isGhost = true;
isPlayer = false;
kickedOff = false;
if (name == null) {
this.name = "Robot Nr. " + position;
} else this.name = name;
}
}

View File

@ -0,0 +1,29 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
import java.net.Socket;
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) {
this.position = position;
this.sock = sock;
this.isOG = isOG;
isGhost = true;
isPlayer = true;
kickedOff = false;
if (name == null) {
this.name = "Human Nr. " + position;
} else this.name = name;
}
public void send(String msg) {
//todo: pass message along to client.
}
}

View File

@ -0,0 +1,4 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
public class Human extends Passenger {
}

View File

@ -0,0 +1,5 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
public class HumanNPC extends Human {
}

View File

@ -0,0 +1,4 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
public class HumanPlayer extends Human{
}

View File

@ -0,0 +1,58 @@
package ch.unibas.dmi.dbis.cs108.Klassenstruktur;
import java.net.Socket;
public class Passenger {
protected int position; //the player's Cabin number (1 to 6)
protected String name; //the player's Name
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...
/**
* Sends a protocol message to the respective player.
* @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
}
/**
* sets the name of this passenger.
* @param name the new name for this passenger.
*/
public void setName(String name) {
this.name = name;
}
/**
* sets the kickedOff status of this Passenger
* @param kickedOff should be set to true if the passenger has been kicked off.
*/
public void setKickedOff(boolean kickedOff) {
this.kickedOff = kickedOff;
}
public int getPosition() {
return position;
}
public String getName() {
return name;
}
public Boolean getIsGhost() {
return isGhost;
}
public Boolean getKickedOff() {
return kickedOff;
}
public Boolean getIsPlayer() {
return isPlayer;
}
}