Reformatted my Code and cleaned it up a little
This commit is contained in:
parent
478bd71409
commit
18acef0a2e
@ -5,7 +5,7 @@ int spielerzahl = 6; //Default setting
|
|||||||
|
|
||||||
Fill train -> Randomize
|
Fill train -> Randomize
|
||||||
/**
|
/**
|
||||||
Creats an array of random numbers 1 - spielerzahl
|
Creates an array of random numbers 1 - spielerzahl
|
||||||
**/
|
**/
|
||||||
int[] fillTrain(int spielerzahl) //... arbitrary amount of users, gives Array I think^^
|
int[] fillTrain(int spielerzahl) //... arbitrary amount of users, gives Array I think^^
|
||||||
if spielerzahl < #users
|
if spielerzahl < #users
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.Klassenstruktur.Passenger;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
/**Can be extended for optional Game-settings**/
|
|
||||||
|
/**
|
||||||
|
* Can be extended for optional Game-settings
|
||||||
|
**/
|
||||||
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
|
||||||
@ -14,22 +13,24 @@ public class Game {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 NPCs)
|
||||||
*/
|
*/
|
||||||
Game (int nrOfPlayers, int nrOfGhosts, int nrOfUsers) throws TrainOverflow { //ToDo: Who handles Exception how and where
|
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);
|
this.gameFunctions = new GameFunctions(nrOfPlayers, nrOfGhosts, nrOfUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try{
|
try {
|
||||||
Game game1 = new Game(6,1,1);
|
Game game1 = new Game(6, 1, 1);
|
||||||
for(int j = 0; j< game1.nrOfPlayers; j++) {
|
for (int j = 0; j < game1.nrOfPlayers; j++) {
|
||||||
System.out.println(game1.gameFunctions.passengerTrain[j].getPosition());
|
System.out.println(game1.gameFunctions.passengerTrain[j].getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +41,4 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
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.Human;
|
||||||
import ch.unibas.dmi.dbis.cs108.Klassenstruktur.Passenger;
|
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
|
||||||
@ -13,19 +15,22 @@ public class GameFunctions {
|
|||||||
Passenger[] passengerTrain;
|
Passenger[] passengerTrain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a GameFunctions instance where nrOfPlayers >= nrOfUsers. Fills passengerTrain with only humans
|
* Constructs a GameFunctions instance where nrOfPlayers >= nrOfUsers. Fills passengerTrain with
|
||||||
|
* only humans
|
||||||
|
*
|
||||||
* @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 NPCs)
|
||||||
* @throws TrainOverflow if nrOfPlayers < nrOfUsers
|
* @throws TrainOverflow if nrOfPlayers < nrOfUsers
|
||||||
*/
|
*/
|
||||||
GameFunctions (int nrOfPlayers, int nrOfGhosts, int nrOfUsers) throws TrainOverflow { //ToDo: where will Exception be handeled?
|
GameFunctions(int nrOfPlayers, int nrOfGhosts, int nrOfUsers)
|
||||||
|
throws TrainOverflow { //ToDo: where will Exception be handled?
|
||||||
this.nrOfPlayers = nrOfPlayers;
|
this.nrOfPlayers = nrOfPlayers;
|
||||||
this.nrOfGhosts = nrOfGhosts;
|
this.nrOfGhosts = nrOfGhosts;
|
||||||
this.nrOfUsers = nrOfUsers;
|
this.nrOfUsers = nrOfUsers;
|
||||||
this.train = new Train(nrOfPlayers,nrOfUsers);
|
this.train = new Train(nrOfPlayers, nrOfUsers);
|
||||||
Passenger[] passengerTrain = new Passenger[nrOfPlayers]; //Creates an array with Passengers with correlation positions (Train)
|
Passenger[] passengerTrain = new Passenger[nrOfPlayers]; //Creates an array with Passengers with correlation positions (Train)
|
||||||
for(int i = 0; i < nrOfPlayers;i++) {
|
for (int i = 0; i < nrOfPlayers; i++) {
|
||||||
Human h = new Human();
|
Human h = new Human();
|
||||||
h.setPosition(train.orderOfTrain[i]);
|
h.setPosition(train.orderOfTrain[i]);
|
||||||
passengerTrain[i] = h;
|
passengerTrain[i] = h;
|
||||||
@ -48,12 +53,9 @@ public class GameFunctions {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Passenger voteEval(){
|
public Passenger voteEval() {
|
||||||
return new Passenger();
|
return new Passenger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,19 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.Klassenstruktur.Passenger;
|
|
||||||
|
|
||||||
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;
|
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
|
||||||
* Puts the ghost approx in the middle of this order.
|
* 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 NPCs)
|
||||||
* @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)
|
||||||
*/
|
*/
|
||||||
Train (int nrOfPlayers, int nrOfUsers) throws TrainOverflow {
|
Train(int nrOfPlayers, int nrOfUsers) throws TrainOverflow {
|
||||||
|
|
||||||
if (nrOfPlayers < nrOfUsers) {
|
if (nrOfPlayers < nrOfUsers) {
|
||||||
throw new TrainOverflow(); //ToDo: What kind of Exception must be thrown here and who handles it how?
|
throw new TrainOverflow(); //ToDo: What kind of Exception must be thrown here and who handles it how?
|
||||||
@ -41,11 +39,12 @@ public class Train {
|
|||||||
|
|
||||||
}
|
}
|
||||||
this.orderOfTrain = userTrain;
|
this.orderOfTrain = userTrain;
|
||||||
this.positionOfGhost = (int) (nrOfPlayers/2);
|
this.positionOfGhost = nrOfPlayers / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the key is to be found in an array
|
* Checks if the key is to be found in an array
|
||||||
|
*
|
||||||
* @param array the array to be searched
|
* @param array the array to be searched
|
||||||
* @param key the value searched for
|
* @param key the value searched for
|
||||||
* @return true if and only if key is found
|
* @return true if and only if key is found
|
||||||
@ -62,12 +61,12 @@ public class Train {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int[] a = {1,2,3,4,5};
|
int[] a = {1, 2, 3, 4, 5};
|
||||||
System.out.println(isInArray(a,0));
|
System.out.println(isInArray(a, 0));
|
||||||
//Test
|
//Test
|
||||||
try {
|
try {
|
||||||
Train t = new Train(6,1);
|
Train t = new Train(6, 1);
|
||||||
for(int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
System.out.print("|" + t.orderOfTrain[i] + "|");
|
System.out.print("|" + t.orderOfTrain[i] + "|");
|
||||||
}
|
}
|
||||||
System.out.println(" Ghost:" + t.positionOfGhost);
|
System.out.println(" Ghost:" + t.positionOfGhost);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
package ch.unibas.dmi.dbis.cs108.Spiellogikentwurf;
|
||||||
|
|
||||||
public class TrainOverflow extends Exception{
|
public class TrainOverflow extends Exception {
|
||||||
|
|
||||||
private static final String message = "Too many users are logged on";
|
private static final String message = "Too many users are logged on";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user