Cherry-picked my own commit from master, because I messed up the branch creation, recommitting it on this one
This commit is contained in:
parent
ba03095647
commit
f058eabb75
@ -13,18 +13,21 @@ public class ClientGameInfoHandler {
|
||||
* All messages that are used in VoteHandler
|
||||
* TODO(Seraina-Alex): Adjust strings to be more meaningful
|
||||
*/
|
||||
//relevant:
|
||||
//relevant for game logic:
|
||||
public static final String ghostVoteRequest = "Vote on who to ghostify!";
|
||||
public static final String humanVoteRequest = "Vote for a ghost to kick off!";
|
||||
public static final String noiseNotification = "Someone passed by you ";
|
||||
public static final String gameOverHumansWin = "Game over: humans win!";
|
||||
public static final String gameOverGhostsWin = "Game over: ghosts win!";
|
||||
|
||||
//just messages
|
||||
//relevant for gui
|
||||
public static final String itsNightTime = "Please wait, ghosts are active";
|
||||
public static final String itsDayTime = "Please wait, humans are active";
|
||||
|
||||
//just messages
|
||||
|
||||
public static final String youGotGhostyfied = "You are now a ghost!";
|
||||
public static final String youGotKickedOff = "Bye bye - you've been kicked off";
|
||||
public static final String itsDayTime = "Please wait, humans are active";
|
||||
public static final String humansVotedFor = "Humans voted for: ";
|
||||
public static final String isAHuman = " but they're a human!";
|
||||
public static final String gotKickedOff = " is a Ghost and got kicked off";
|
||||
|
||||
@ -162,27 +162,17 @@ public class GameState {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String[] print = new String[6];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].getKickedOff()) {
|
||||
print[i] = "| " + array[i].getName() + ", kicked off: " + array[i].getPosition() + " |";
|
||||
if(array[i].getIsSpectator()) {
|
||||
print[i] = array[i].getName() + ":s:" + array[i].getKickedOff();
|
||||
} else if (array[i].getIsGhost()) {
|
||||
print[i] = array[i].getName() + ":g:" + array[i].getKickedOff();
|
||||
} else {
|
||||
if (array[i].getIsPlayer()) {
|
||||
if (array[i].getIsGhost()) {
|
||||
print[i] = "| " + array[i].getName() + "(ghostPlayer): " + array[i].getPosition() + " |";
|
||||
} else {
|
||||
print[i] = "| " + array[i].getName() + "(humanPlayer): " + array[i].getPosition() + " |";
|
||||
}
|
||||
} else {
|
||||
if (array[i].getIsGhost()) {
|
||||
print[i] = "| " + array[i].getName() + "(ghostNPC): " + array[i].getPosition() + " |";
|
||||
} else {
|
||||
print[i] = "| " + array[i].getName() + "(humanNPC): " + array[i].getPosition() + " |";
|
||||
}
|
||||
}
|
||||
print[i] = "| " + array[i].getName() + ":h:" + array[i].getKickedOff();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
stringBuilder.append(print[i]);
|
||||
stringBuilder.append("$").append(print[i]);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
@ -198,11 +188,11 @@ public class GameState {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String[] print = new String[6];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
print[i] = "| " + array[i].getName() + ": " + array[i].getPosition() + " |";
|
||||
print[i] = array[i].getName() + "::" + array[i].getKickedOff();
|
||||
}
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
stringBuilder.append(print[i]);
|
||||
stringBuilder.append("$").append(print[i]);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ public class VoteHandler {
|
||||
|
||||
//Timer.ghostVoteTimer(game);
|
||||
try {
|
||||
Thread.sleep(10*1000);
|
||||
Thread.sleep(20*1000);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||
}
|
||||
@ -155,7 +155,7 @@ public class VoteHandler {
|
||||
}
|
||||
|
||||
try { // waits 60 seconds before votes get collected
|
||||
Thread.sleep(10*1000);
|
||||
Thread.sleep(20*1000);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn("Thread " + Thread.currentThread() + " was interrupted");
|
||||
}
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GUI;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
||||
|
||||
|
||||
@ -32,6 +35,8 @@ public class Client {
|
||||
|
||||
private ChatApp chatApp;
|
||||
private GUI chatGui;
|
||||
private GameStateModel gameStateModel;
|
||||
private GameController gameController;
|
||||
|
||||
/**
|
||||
* Saves the position of the client, gets refreshed everytime the client gets a vote request.
|
||||
@ -63,6 +68,8 @@ public class Client {
|
||||
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
||||
this.chatGui = new GUI(this.chatApp);
|
||||
clientPinger = new ClientPinger(this, this.socket);
|
||||
this.gameStateModel = new GameStateModel();
|
||||
this.gameController = new GameController(ChatApp.getClientModel(),gameStateModel);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -124,6 +131,16 @@ public class Client {
|
||||
//LOGGER.debug("just checked next line");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts infromation about names and positions and roles from string and adds it to
|
||||
* the GameStateModel
|
||||
* @param msg
|
||||
*/
|
||||
public void gameStateModelSetter(String msg) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts a thread which listens for incoming chat messages / other messages that the user has to
|
||||
@ -290,4 +307,38 @@ public class Client {
|
||||
public void sendToChat(String substring) {
|
||||
chatApp.getChatController().addChatMsgToView(substring);
|
||||
}
|
||||
|
||||
/**
|
||||
* funnels a message to the gui, where depending on the message different functions/controls/methods
|
||||
* of the gui are targeted. The message contains information on what to do, which are extracted
|
||||
* @param msg a message of the form {@code parameter$msg}
|
||||
*
|
||||
*/
|
||||
public void sendToGUI(String msg) {
|
||||
int indexFirstDollar = msg.indexOf('$');
|
||||
String header = "";
|
||||
try {
|
||||
header = msg.substring(0,indexFirstDollar);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
LOGGER.info(e.getMessage());
|
||||
}
|
||||
|
||||
switch (header) {
|
||||
case ClientGameInfoHandler.itsNightTime:
|
||||
gameStateModel.setDayClone(false);
|
||||
break;
|
||||
case ClientGameInfoHandler.itsDayTime:
|
||||
gameStateModel.setDayClone(true);
|
||||
break;
|
||||
|
||||
default:
|
||||
gameController.addMessageToNotificationText(msg); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import java.io.OutputStreamWriter;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -48,7 +49,7 @@ public class JClientProtocolParser {
|
||||
break;
|
||||
case Protocol.serverRequestsGhostVote:
|
||||
LOGGER.debug("Ghost received Vote request");
|
||||
System.out.println("Ghost Vote:");
|
||||
//c.sendToGUI(ClientGameInfoHandler.ghostVoteRequest);
|
||||
c.positionSetter(msg.substring(6));
|
||||
break;
|
||||
case Protocol.serverRequestsHumanVote:
|
||||
|
||||
@ -11,6 +11,12 @@ public class GameStateModel {
|
||||
*/
|
||||
private boolean isDayClone;
|
||||
|
||||
/**
|
||||
* can take the values h/g/s for human/ghost/spectator. Safes the role the client this GamesStateModel
|
||||
* lives on currently has
|
||||
*/
|
||||
private String yourRole;
|
||||
|
||||
/**
|
||||
* A primitive clone of the passengerTrain in the GameState of the server.
|
||||
* in passengerTrainClone[0] the names of the passengers are stored, in passengerTrainClone[1] the roles
|
||||
@ -18,13 +24,19 @@ public class GameStateModel {
|
||||
*/
|
||||
private String[][] passengerTrainClone;
|
||||
|
||||
private boolean[] kickedOff;
|
||||
|
||||
/**
|
||||
* Constructs a GamesStateModel with the passengerTrainClone length at nrOfPlayers
|
||||
* @param nrOfPlayers the amount of different objects to be saved
|
||||
* Constructs a GamesStateModel with the passengerTrainClone
|
||||
*/
|
||||
public void GameStateModel(int nrOfPlayers) {
|
||||
this.nrOfPlayers = nrOfPlayers;
|
||||
public GameStateModel() {
|
||||
this.nrOfPlayers = 6;
|
||||
passengerTrainClone = new String[2][nrOfPlayers];
|
||||
for(String role : passengerTrainClone[1]) {
|
||||
role = "";
|
||||
}
|
||||
kickedOff = new boolean[nrOfPlayers];
|
||||
isDayClone = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,4 +49,34 @@ public class GameStateModel {
|
||||
passengerTrainClone[1] = roles;
|
||||
|
||||
}
|
||||
|
||||
public String[][] getPassengerTrainClone() {
|
||||
return passengerTrainClone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets your current role to the specified role, must be h for human, g for ghost or s for spectator
|
||||
* @param yourRole the role to set this role to
|
||||
*/
|
||||
public void setYourRole(String yourRole) {
|
||||
if(yourRole.equals("h") || yourRole.equals("g") || yourRole.equals("s")) {
|
||||
this.yourRole = yourRole;
|
||||
}
|
||||
}
|
||||
|
||||
public String getYourRole() {
|
||||
return yourRole;
|
||||
}
|
||||
|
||||
public int getNrOfPlayers() {
|
||||
return nrOfPlayers;
|
||||
}
|
||||
|
||||
public void setDayClone(boolean dayClone) {
|
||||
isDayClone = dayClone;
|
||||
}
|
||||
|
||||
public boolean getDayClone() {
|
||||
return isDayClone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
|
||||
import javafx.event.EventHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
@ -35,6 +36,14 @@ public class GameController {
|
||||
|
||||
private static ClientModel client;
|
||||
|
||||
private static GameStateModel gameStateModel;
|
||||
|
||||
//TODO(Seraina, Sebi): Same issue as ChatController? do with setters?
|
||||
public GameController(ClientModel c, GameStateModel g) {
|
||||
client = c;
|
||||
gameStateModel = g;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private AnchorPane gameBG;
|
||||
@FXML
|
||||
@ -138,14 +147,47 @@ public class GameController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a msg to the room Lable at the specified position
|
||||
* @param names a String array containing all the names
|
||||
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel
|
||||
*/
|
||||
public void addRoomLabels(String[] names) {
|
||||
public void updateRoomLabels() {
|
||||
String[] names = gameStateModel.getPassengerTrainClone()[0];
|
||||
String[] roles = gameStateModel.getPassengerTrainClone()[1];
|
||||
Text name0 = new Text(names[0]);
|
||||
Text name1 = new Text(names[1]);
|
||||
Text name2 = new Text(names[2]);
|
||||
Text name3 = new Text(names[3]);
|
||||
Text name4 = new Text(names[4]);
|
||||
Text name5 = new Text(names[5]);
|
||||
Text role0 = new Text(roles[0]);
|
||||
Text role1 = new Text(roles[1]);
|
||||
Text role2 = new Text(roles[2]);
|
||||
Text role3 = new Text(roles[3]);
|
||||
Text role4 = new Text(roles[4]);
|
||||
Text role5 = new Text(roles[5]);
|
||||
|
||||
lableRoom0.getChildren().clear();
|
||||
lableRoom0.getChildren().add(name0);
|
||||
lableRoom0.getChildren().add(role0);
|
||||
lableRoom1.getChildren().clear();
|
||||
lableRoom1.getChildren().add(name1);
|
||||
lableRoom1.getChildren().add(role1);
|
||||
lableRoom2.getChildren().clear();
|
||||
lableRoom2.getChildren().add(name2);
|
||||
lableRoom2.getChildren().add(role2);
|
||||
lableRoom3.getChildren().clear();
|
||||
lableRoom3.getChildren().add(name3);
|
||||
lableRoom3.getChildren().add(role3);
|
||||
lableRoom4.getChildren().clear();
|
||||
lableRoom4.getChildren().add(name4);
|
||||
lableRoom4.getChildren().add(role4);
|
||||
lableRoom5.getChildren().clear();
|
||||
lableRoom5.getChildren().add(name5);
|
||||
lableRoom5.getChildren().add(role5);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setGameStateModel(
|
||||
GameStateModel gameStateModel) {
|
||||
GameController.gameStateModel = gameStateModel;
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
</HBox>
|
||||
</children>
|
||||
</Group>
|
||||
<Button fx:id="noiseButton" alignment="CENTER" layoutX="267.0" layoutY="636.0" mnemonicParsing="false" prefHeight="114.0" prefWidth="217.0" text="I heard some noise">
|
||||
<Button fx:id="noiseButton" alignment="CENTER" layoutX="267.0" layoutY="636.0" mnemonicParsing="false" onAction="#noise" prefHeight="114.0" prefWidth="217.0" text="I heard some noise">
|
||||
<font>
|
||||
<Font name="System Bold" size="21.0" />
|
||||
</font></Button>
|
||||
|
||||
Reference in New Issue
Block a user