Added an array full of Passengers, set them all to human by default
This commit is contained in:
parent
a6ca3da263
commit
ce250f638d
@ -5,7 +5,7 @@ import ch.unibas.dmi.dbis.cs108.Multiplayer.Server.ClientHandler;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class Passenger {
|
public class Passenger {
|
||||||
protected int position; //the player's Cabin number (1 to 6)
|
protected int position; //the player's Cabin number (0 to 5)
|
||||||
protected String name; //the player's Name
|
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 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 isPlayer; //same here
|
||||||
@ -20,6 +20,14 @@ public class Passenger {
|
|||||||
//todo: send protocol message to the respective client OR process messages for NPCS
|
//todo: send protocol message to the respective client OR process messages for NPCS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the Position of this passenger
|
||||||
|
* @param position the position of this passenger
|
||||||
|
*/
|
||||||
|
public void setPosition(int position) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the name of this passenger.
|
* sets the name of this passenger.
|
||||||
* @param name the new name for this passenger.
|
* @param name the new name for this passenger.
|
||||||
|
|||||||
@ -9,21 +9,37 @@ public class Game {
|
|||||||
protected int nrOfPlayers; //sets the length of the train
|
protected int nrOfPlayers; //sets the length of the train
|
||||||
protected int nrOfGhosts; // sets how many Ghosts we start witch
|
protected int nrOfGhosts; // sets how many Ghosts we start witch
|
||||||
protected int nrOfUsers; // safes how many clients are active in this Game
|
protected int nrOfUsers; // safes how many clients are active in this Game
|
||||||
Train train; // safes who sits where ToDo: Figure out who and where and if this needs to be changed i.e. when a client looses connection. (Schon gelöst mit timer?)
|
protected GameFunctions gameFunctions;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Game instance where
|
* Constructs a Game instance where:
|
||||||
* @param nrOfPlayers is the length of the Train
|
* @param nrOfPlayers is the length of the Train
|
||||||
* @param nrOfGhosts is the number of OG Ghosts you want to start with and
|
* @param nrOfGhosts is the number of OG Ghosts you want to start with and
|
||||||
* @param nrOfUsers is the number of active users at the time (non NPC's)
|
* @param nrOfUsers is the number of active users at the time (non NPC's)
|
||||||
*/
|
*/
|
||||||
Game (int nrOfPlayers, int nrOfGhosts, int nrOfUsers) {
|
Game (int nrOfPlayers, int nrOfGhosts, int nrOfUsers) throws TrainOverflow { //ToDo: Who handles Exception how and where
|
||||||
this.nrOfPlayers = nrOfPlayers;
|
this.nrOfPlayers = nrOfPlayers;
|
||||||
this.nrOfGhosts = nrOfGhosts;
|
this.nrOfGhosts = nrOfGhosts;
|
||||||
this.nrOfUsers = nrOfUsers;
|
this.nrOfUsers = nrOfUsers;
|
||||||
|
this.gameFunctions = new GameFunctions(nrOfPlayers,nrOfGhosts,nrOfUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try{
|
||||||
|
Game game1 = new Game(6,1,1);
|
||||||
|
for(int j = 0; j< game1.nrOfPlayers; j++) {
|
||||||
|
System.out.println(game1.gameFunctions.passengerTrain[j].getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (TrainOverflow e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,35 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.Klassenstruktur.Ghost;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.Klassenstruktur.Human;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.Klassenstruktur.Passenger;
|
||||||
|
|
||||||
public class GameFunctions {
|
public class GameFunctions {
|
||||||
/**Can be extended for optional Game-settings**/
|
/**Can be extended for optional Game-settings**/
|
||||||
int nrOfPlayers; //sets the length of the train
|
int nrOfPlayers; //sets the length of the train
|
||||||
int nrOfGhosts; // sets how many Ghosts we start witch
|
int nrOfGhosts; // sets how many Ghosts we start witch
|
||||||
int nrOfUsers; // safes how many clients are active in this Game
|
int nrOfUsers; // safes how many clients are active in this Game
|
||||||
|
Train train; // safes who sits where
|
||||||
|
Passenger[] passengerTrain;
|
||||||
|
|
||||||
GameFunctions (int nrOfPlayers, int nrOfGhosts, int nrOfUsers) {
|
/**
|
||||||
|
* Constructs a GameFunctions instance where nrOfPlayers >= nrOfUsers. Fills passengerTrain with only humans
|
||||||
|
* @param nrOfPlayers is the length of the Train
|
||||||
|
* @param nrOfGhosts is the number of OG Ghosts you want to start with and
|
||||||
|
* @param nrOfUsers is the number of active users at the time (non NPC's)
|
||||||
|
* @throws TrainOverflow if nrOfPlayers < nrOfUsers
|
||||||
|
*/
|
||||||
|
GameFunctions (int nrOfPlayers, int nrOfGhosts, int nrOfUsers) throws TrainOverflow { //ToDo: where will Exception be handeled?
|
||||||
this.nrOfPlayers = nrOfPlayers;
|
this.nrOfPlayers = nrOfPlayers;
|
||||||
this.nrOfGhosts = nrOfGhosts;
|
this.nrOfGhosts = nrOfGhosts;
|
||||||
this.nrOfUsers = nrOfUsers;
|
this.nrOfUsers = nrOfUsers;
|
||||||
|
this.train = new Train(nrOfPlayers,nrOfUsers);
|
||||||
|
Passenger[] passengerTrain = new Passenger[nrOfPlayers]; //Creates an array with Passengers with correlation positions (Train)
|
||||||
|
for(int i = 0; i < nrOfPlayers;i++) {
|
||||||
|
Human h = new Human();
|
||||||
|
h.setPosition(train.orderOfTrain[i]);
|
||||||
|
passengerTrain[i] = h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNrOfGhosts() {
|
public int getNrOfGhosts() {
|
||||||
@ -24,5 +44,16 @@ public class GameFunctions {
|
|||||||
return nrOfUsers;
|
return nrOfUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ghostyfy(int position) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Passenger voteEval(){
|
||||||
|
return new Passenger();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,11 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class Train {
|
public class Train {
|
||||||
int[] orderOfTrain; //gives the random order in which the passengers enter the train
|
int[] orderOfTrain; //gives the random order in which the passengers enter the train
|
||||||
|
int positionOfGhost;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Train with orderOfTrain of the size nrOfPlayers, filled with a Random order of the numbers 0-5
|
* Constructs a Train with orderOfTrain of the size nrOfPlayers, filled with a Random order of the numbers 0-5.
|
||||||
|
* Puts the ghost approx in the middle of this order.
|
||||||
* @param nrOfPlayers sets how many Players fit in the Train
|
* @param nrOfPlayers sets how many Players fit in the Train
|
||||||
* @param nrOfUsers sets how many of the Players are Users (vs NPC's)
|
* @param nrOfUsers sets how many of the Players are Users (vs NPC's)
|
||||||
* @throws TrainOverflow if you want to play with to many users (Train is to small)
|
* @throws TrainOverflow if you want to play with to many users (Train is to small)
|
||||||
@ -39,6 +41,7 @@ public class Train {
|
|||||||
|
|
||||||
}
|
}
|
||||||
this.orderOfTrain = userTrain;
|
this.orderOfTrain = userTrain;
|
||||||
|
this.positionOfGhost = (int) (nrOfPlayers/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,6 +67,11 @@ public class Train {
|
|||||||
//Test
|
//Test
|
||||||
try {
|
try {
|
||||||
Train t = new Train(6,1);
|
Train t = new Train(6,1);
|
||||||
|
for(int i = 0; i < 6; i++) {
|
||||||
|
System.out.print("|" + t.orderOfTrain[i] + "|");
|
||||||
|
}
|
||||||
|
System.out.println(" Ghost:" + t.positionOfGhost);
|
||||||
|
|
||||||
} catch (TrainOverflow e) {
|
} catch (TrainOverflow e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user