Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
c3096d7088
@ -241,5 +241,11 @@ ToDo:
|
||||
Stand:
|
||||
Server - Client: Connection loss handling funktioniert nun.
|
||||
Lobby: ?
|
||||
Spiellogik:
|
||||
Spiellogik: VoteHandler wurde getestet und tut weitestgehenst was er soll
|
||||
|
||||
ToDo:
|
||||
Spiellogik: - Send() methode von Passenger mit Client-Server verknüpfen(Seraina)
|
||||
- NoiseHandler (Alex)
|
||||
- Game Zyklus implementieren (Seraina)
|
||||
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ public class GameFunctions {
|
||||
for (int i = 0; i < nrOfPlayers; i++) {
|
||||
Human h = new Human();
|
||||
h.setPosition(train.orderOfTrain[i]);
|
||||
passengerTrain[i] = h;
|
||||
passengerTrain[train.orderOfTrain[i]] = h;
|
||||
}
|
||||
this.passengerTrain = passengerTrain;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Ghost;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -16,10 +17,13 @@ public class GhostifyHandler {
|
||||
* @param p Passenger to be ghostified
|
||||
*/
|
||||
|
||||
public GhostPlayer ghost(Passenger p, Game game) {
|
||||
public Ghost ghost(Passenger p, Game game) { //TODO: Adjust for not only players but also npcs
|
||||
LOGGER.debug("Passenger Position " + p.getPosition());
|
||||
p.setGhost();
|
||||
GhostPlayer g;
|
||||
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
||||
Ghost g;
|
||||
g = new Ghost();
|
||||
g.setGhost();
|
||||
g.setPosition(p.getPosition());
|
||||
game.gameFunctions.passengerTrain[g.getPosition()] = g;
|
||||
LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified");
|
||||
return g;
|
||||
|
||||
@ -31,7 +31,7 @@ public class VoteHandler {
|
||||
*
|
||||
* @param passengers: passengers on the train
|
||||
*/
|
||||
public static void ghostVote(Passenger[] passengers, Game game) {
|
||||
public void ghostVote(Passenger[] passengers, Game game) {
|
||||
|
||||
// array to collect votes for all players during voting, i.e. votes for player 1 (passengers[0])
|
||||
// are saved in
|
||||
@ -83,8 +83,10 @@ public class VoteHandler {
|
||||
if (votesForPlayers[i] == currentMax) { // if player at position i has most votes
|
||||
ghostPosition = i;
|
||||
LOGGER.info("Most votes for Passenger " + i);
|
||||
|
||||
}
|
||||
}
|
||||
LOGGER.debug("ghostPosition: " + ghostPosition);
|
||||
GhostifyHandler gh = new GhostifyHandler();
|
||||
Ghost g = gh.ghost(passengers[ghostPosition], game);
|
||||
passengers[ghostPosition] = g;
|
||||
@ -105,7 +107,7 @@ public class VoteHandler {
|
||||
*
|
||||
* @param passengers: train passengers
|
||||
*/
|
||||
public static void humanVote(Passenger[] passengers, Game game) {
|
||||
public void humanVote(Passenger[] passengers, Game game) {
|
||||
|
||||
|
||||
// array to collect votes for all players during voting, i.e. votes for player 1 are saved in
|
||||
@ -170,10 +172,10 @@ public class VoteHandler {
|
||||
if (!passenger.getIsGhost()) {
|
||||
humans++;
|
||||
}
|
||||
}
|
||||
if (humans == 1) {
|
||||
System.out.println("Game over: ghosts win!");
|
||||
}
|
||||
}
|
||||
// Usual case: there is more than one human left and a normal ghost has been voted for -->
|
||||
// kick this ghost off
|
||||
passengers[voteIndex].setKickedOff(true);
|
||||
@ -188,14 +190,22 @@ public class VoteHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just a print Method for testing the VoteHandler
|
||||
* @param array the Passenger array to be visualized
|
||||
*/
|
||||
static void print(Passenger[] array) {
|
||||
System.out.println();
|
||||
String[] print = new String[6];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if(array[i].getIsGhost()) {
|
||||
print[i] = "| ghost |";
|
||||
if (array[i].getKickedOff()) {
|
||||
print[i] = "| kicked off " + array[i].getPosition() + "|";
|
||||
} else {
|
||||
print[i] = "| human |";
|
||||
if (array[i].getIsGhost()) {
|
||||
print[i] = "| ghost " + array[i].getPosition() + "|";
|
||||
} else {
|
||||
print[i] = "| human " + array[i].getPosition() + "|";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,21 +219,30 @@ public class VoteHandler {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Game game = new Game(6,1, 6);
|
||||
VoteHandler voteHandler = new VoteHandler();
|
||||
|
||||
Passenger[] testArray = game.gameFunctions.passengerTrain;
|
||||
Passenger ghost = new Ghost();
|
||||
testArray[3] = ghost;
|
||||
testArray[3].setGhost();
|
||||
testArray[3].setIsOg();
|
||||
testArray[3].setPosition(3);
|
||||
print(testArray);
|
||||
LOGGER.info("NIGHT");
|
||||
ghostVote(testArray,game);
|
||||
voteHandler.ghostVote(testArray,game);
|
||||
print(testArray);
|
||||
|
||||
LOGGER.info("Day");
|
||||
humanVote(testArray, game);
|
||||
voteHandler.humanVote(testArray, game);
|
||||
print(testArray);
|
||||
|
||||
LOGGER.info("NIGHT");
|
||||
voteHandler.ghostVote(testArray,game);
|
||||
print(testArray);
|
||||
|
||||
LOGGER.info("Day");
|
||||
voteHandler.humanVote(testArray, game);
|
||||
print(testArray);
|
||||
} catch (TrainOverflow e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
}
|
||||
|
||||
@ -19,17 +19,23 @@ public class Passenger {
|
||||
protected ClientHandler clientHandler;//the socket for the client associated with this Passenger, for NPCs, this can be null.
|
||||
protected boolean hasVoted; //true if the player gave his vote during voting time
|
||||
protected int vote; //saves the number of the player this passenger voted for during voting (0-5)
|
||||
|
||||
int sendcounter = 0;
|
||||
/**
|
||||
* Sends a protocol message to the respective player or NPC.
|
||||
* @param msg the message that is sent to this player.
|
||||
**/
|
||||
public void send(String msg) {
|
||||
if (msg.equals("Vote on who to ghostify!") || msg.equals("Vote for a ghost to kick off!")) {
|
||||
vote = 1;
|
||||
sendcounter++;
|
||||
if (msg.equals("Vote on who to ghostify!")) {
|
||||
vote = 1*sendcounter;
|
||||
hasVoted = true; // for testing, when is it set to false again?
|
||||
LOGGER.info("Voted for Position " + vote);
|
||||
} else if(msg.equals("Vote for a ghost to kick off!")) {
|
||||
vote = (int) (0.5*sendcounter);
|
||||
hasVoted = true; // for testing, when is it set to false again?
|
||||
LOGGER.info("Voted for Position " + vote);
|
||||
} else {
|
||||
|
||||
LOGGER.debug(msg);
|
||||
}
|
||||
/*if (isPlayer) {
|
||||
|
||||
@ -9,6 +9,9 @@ import java.util.List;
|
||||
*/
|
||||
public class Lobby {
|
||||
|
||||
private static final int MAX_NO_OF_CLIENTS = 6;
|
||||
private static int lobbies;
|
||||
|
||||
/**
|
||||
* The Person who created the game and can configure it and decide to start once enough players
|
||||
* have entered the lobby.
|
||||
@ -18,23 +21,29 @@ public class Lobby {
|
||||
/**
|
||||
* Everyone who's in the lobby.
|
||||
*/
|
||||
private List<ClientHandler> players = new ArrayList<>();
|
||||
|
||||
private static final int MAX_NO_OF_CLIENTS = 6;
|
||||
|
||||
private List<ClientHandler> players = new ArrayList<>(6);
|
||||
|
||||
|
||||
private int numberOfPlayersInLobby;
|
||||
private final int lobbyID = lobbies++;
|
||||
|
||||
|
||||
static {
|
||||
lobbies = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The admin has to be set in the constructor. The admin is final.
|
||||
* Every Lobby needs and admin, so no other constructors are needed.
|
||||
* Constructor. Sets the admin to who created the lobby. Adds the admin to the list of players.
|
||||
* Increases the number of players from 0 to 1.
|
||||
*
|
||||
* @param admin the Client who called CRTGM
|
||||
*/
|
||||
public Lobby(ClientHandler admin) {
|
||||
this.admin = admin;
|
||||
this.players.add(admin);
|
||||
this.numberOfPlayersInLobby = 1;
|
||||
lobbies++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,6 +57,7 @@ public class Lobby {
|
||||
|
||||
/**
|
||||
* Adds a player to the lobby.
|
||||
*
|
||||
* @param player who wants to join the lobby.
|
||||
*/
|
||||
public void addPlayer(ClientHandler player) {
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package ch.unibas.dmi.dbis.cs108.sebaschi;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is just everyone on the server, which games are open to join, who is in session. I.E.
|
||||
* the context of the game just after joining the server, before starting a game and entering into a
|
||||
@ -7,4 +11,15 @@ package ch.unibas.dmi.dbis.cs108.sebaschi;
|
||||
*/
|
||||
public class ServerLobby {
|
||||
|
||||
private static List<Lobby> openLobbies;
|
||||
private static List<ClientHandler> allClients;
|
||||
|
||||
static {
|
||||
openLobbies = new ArrayList<>();
|
||||
allClients = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static List<Lobby> getOpenLobbies() {
|
||||
return openLobbies;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user