Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
1d9ee624fe
@ -40,6 +40,7 @@ public class GameFunctions {
|
||||
h.setPosition(train.orderOfTrain[i]);
|
||||
passengerTrain[i] = h;
|
||||
}
|
||||
this.passengerTrain = passengerTrain;
|
||||
}
|
||||
|
||||
public int getNrOfGhosts() {
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class GhostifyHandler {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
/**
|
||||
* Changes passenger at position x to ghost and returns this ghost. Monitors the times the ghost method is being
|
||||
* called. If it's being called for the first time, the ghostified player is being set as the original ghost.
|
||||
*
|
||||
* @param p Passenger to be ghostified
|
||||
*/
|
||||
private static int ghostifyCallCounter = -1;
|
||||
|
||||
public GhostPlayer ghost(Passenger p, Game game) {
|
||||
p.setGhost();
|
||||
GhostPlayer g;
|
||||
ghostifyCallCounter++;
|
||||
if (ghostifyCallCounter == 0) {
|
||||
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true);
|
||||
} else {
|
||||
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
||||
}
|
||||
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
||||
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 void ghostVote(Passenger[] passengers, Game game) {
|
||||
public static 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
|
||||
@ -42,13 +42,13 @@ public class VoteHandler {
|
||||
// TODO(Seraina): Messages in for-loop should probably be handled by ServerGameInfoHandler
|
||||
for (Passenger passenger : passengers) {
|
||||
if (passenger.getIsGhost()) {
|
||||
LOGGER.info("Send msg to Ghost in Position: " + passenger);
|
||||
|
||||
passenger.send("Vote on who to ghostify!");
|
||||
} else {
|
||||
passenger.send(
|
||||
"Please wait, ghosts are active"); // TODO(Seraina): make sure whatever clients send in
|
||||
// this time, except chat is ignored
|
||||
LOGGER.info("Send msg to Human in Position: " + passenger);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,14 +75,14 @@ public class VoteHandler {
|
||||
currentMax = votesForPlayer;
|
||||
}
|
||||
}
|
||||
LOGGER.info("Most votes" + currentMax);
|
||||
LOGGER.info("Most votes: " + currentMax + " vote");
|
||||
|
||||
// ghostify the player with most votes
|
||||
int ghostPosition = 0;
|
||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||
if (votesForPlayers[i] == currentMax) { // if player at position i has most votes
|
||||
ghostPosition = i;
|
||||
LOGGER.info("Most votes for Passenger" + i);
|
||||
LOGGER.info("Most votes for Passenger " + i);
|
||||
}
|
||||
}
|
||||
GhostifyHandler gh = new GhostifyHandler();
|
||||
@ -105,7 +105,8 @@ public class VoteHandler {
|
||||
*
|
||||
* @param passengers: train passengers
|
||||
*/
|
||||
public void humanVote(Passenger[] passengers, Game game) {
|
||||
public static void humanVote(Passenger[] passengers, Game game) {
|
||||
|
||||
|
||||
// array to collect votes for all players during voting, i.e. votes for player 1 are saved in
|
||||
// votesForPlayers[0]
|
||||
@ -147,7 +148,7 @@ public class VoteHandler {
|
||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
||||
voteIndex = i;
|
||||
LOGGER.info("Player " + voteIndex + "has the most votes");
|
||||
LOGGER.info("Player " + voteIndex + " has the most votes");
|
||||
}
|
||||
}
|
||||
if (!passengers[voteIndex]
|
||||
@ -177,13 +178,57 @@ public class VoteHandler {
|
||||
// kick this ghost off
|
||||
passengers[voteIndex].setKickedOff(true);
|
||||
for (Passenger passenger : passengers) {
|
||||
passenger.send("Player " + voteIndex + "has been kicked off!");
|
||||
passenger.send("Player " + voteIndex + " has been kicked off!");
|
||||
}
|
||||
}
|
||||
}
|
||||
// set hasVoted to false for all passengers for future votings
|
||||
// set hasVoted to false for all passengers for future voting
|
||||
for (Passenger passenger : passengers) {
|
||||
passenger.setHasVoted(false);
|
||||
}
|
||||
}
|
||||
|
||||
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 |";
|
||||
} else {
|
||||
print[i] = "| human |";
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
System.out.print(print[i]);
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Game game = new Game(6,1, 6);
|
||||
|
||||
Passenger[] testArray = game.gameFunctions.passengerTrain;
|
||||
Passenger ghost = new Ghost();
|
||||
testArray[3] = ghost;
|
||||
testArray[3].setGhost();
|
||||
testArray[3].setIsOg();
|
||||
print(testArray);
|
||||
LOGGER.info("NIGHT");
|
||||
ghostVote(testArray,game);
|
||||
print(testArray);
|
||||
|
||||
LOGGER.info("Day");
|
||||
humanVote(testArray, game);
|
||||
print(testArray);
|
||||
|
||||
} catch (TrainOverflow e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,9 +26,9 @@ public class Passenger {
|
||||
**/
|
||||
public void send(String msg) {
|
||||
if (msg.equals("Vote on who to ghostify!") || msg.equals("Vote for a ghost to kick off!")) {
|
||||
vote = (int) (Math.random() * 6);
|
||||
vote = 1;
|
||||
hasVoted = true; // for testing, when is it set to false again?
|
||||
LOGGER.info("Voted for Position" + vote);
|
||||
LOGGER.info("Voted for Position " + vote);
|
||||
} else {
|
||||
LOGGER.debug(msg);
|
||||
}
|
||||
@ -76,6 +76,10 @@ public class Passenger {
|
||||
hasVoted = voted;
|
||||
}
|
||||
|
||||
public void setIsOg() {
|
||||
isOG = true;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package ch.unibas.dmi.dbis.cs108.sebaschi;
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
|
||||
import java.net.Socket;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -11,7 +12,7 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* This Class Represents an Object containing different Maps, Lists and Sets wherein a server object
|
||||
* can find all needed data. An instance of this object can also be passed to other class-objects uf
|
||||
* can find all needed data. An instance of this object can also be passed to other class-objects if
|
||||
* they need the same data. This Class is used to query for information in collections.
|
||||
*/
|
||||
public class CentralServerData {
|
||||
@ -19,11 +20,11 @@ public class CentralServerData {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
private Set<Client> clientsOnServer;
|
||||
private Set<ClientHandler> clientsOnServer;
|
||||
private Set<Game> activeGames;
|
||||
private Set<Game> gamesOpenToJoin;
|
||||
|
||||
private Map<Client, Socket> clientSocketMap;
|
||||
private Map<Socket, Client> socketClientMap;
|
||||
private Map<Game, Client> gameClientMap;
|
||||
private Map<ClientHandler, Socket> clientSocketMap;
|
||||
private Map<Socket, ClientHandler> socketClientMap;
|
||||
private Map<Game, ClientHandler> gameClientMap;
|
||||
}
|
||||
|
||||
@ -1,5 +1,57 @@
|
||||
package ch.unibas.dmi.dbis.cs108.sebaschi;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Lobby one is in after a client sends the CRTGM command. THe Server
|
||||
*/
|
||||
public class Lobby {
|
||||
|
||||
/**
|
||||
* The Person who created the game and can configure it and decide to start once enough players
|
||||
* have entered the lobby.
|
||||
*/
|
||||
private final ClientHandler admin;
|
||||
|
||||
/**
|
||||
* Everyone who's in the lobby.
|
||||
*/
|
||||
private List<ClientHandler> players = new ArrayList<>();
|
||||
|
||||
private static final int MAX_NO_OF_CLIENTS = 6;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The admin has to be set in the constructor. The admin is final.
|
||||
* Every Lobby needs and admin, so no other constructors are needed.
|
||||
* @param admin the Client who called CRTGM
|
||||
*/
|
||||
public Lobby(ClientHandler admin) {
|
||||
this.admin = admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter
|
||||
*
|
||||
* @return the admin of the lobby.
|
||||
*/
|
||||
public ClientHandler getAdmin() {
|
||||
return this.admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the lobby.
|
||||
* @param player who wants to join the lobby.
|
||||
*/
|
||||
public void addPlayer(ClientHandler player) {
|
||||
players.add(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user