Fixed some bugs with the noise handeling, seems not work now
Still need to handle connection loss and name-change in gamelogic
This commit is contained in:
parent
fc250da14b
commit
bc136d7b68
@ -17,7 +17,7 @@ public class ClientGameInfoHandler {
|
||||
//relevant:
|
||||
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 = "noise";
|
||||
public static final String noiseNotification = "You heard some noise";
|
||||
public static final String gameOverHumansWin = "Game over: humans win!";
|
||||
public static final String gameOverGhostsWin = "Game over: ghosts win!";
|
||||
|
||||
@ -25,9 +25,9 @@ public class ClientGameInfoHandler {
|
||||
public static final String itsNightTime = "Please wait, ghosts are active";
|
||||
public static final String youGotGhostyfied = "You are now a ghost!";
|
||||
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";
|
||||
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";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -95,19 +95,19 @@ public class GameState {
|
||||
String[] print = new String[6];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].getKickedOff()) {
|
||||
print[i] = "| kicked off: " + array[i].getPosition() + "|";
|
||||
print[i] = "-| kicked off: " + array[i].getPosition() + "|-";
|
||||
} else {
|
||||
if (array[i].getIsPlayer()) {
|
||||
if (array[i].getIsGhost()) {
|
||||
print[i] = "| ghostPlayer: " + array[i].getPosition() + "|";
|
||||
print[i] = "-| ghostPlayer: " + array[i].getPosition() + "|-";
|
||||
} else {
|
||||
print[i] = "| humanPlayer: " + array[i].getPosition() + "|";
|
||||
print[i] = "-| humanPlayer: " + array[i].getPosition() + "|";
|
||||
}
|
||||
} else {
|
||||
if (array[i].getIsGhost()) {
|
||||
print[i] = "| ghostNPC: " + array[i].getPosition() + "|";
|
||||
print[i] = "-| ghostNPC: " + array[i].getPosition() + "|-";
|
||||
} else {
|
||||
print[i] = "| humanNPC: " + array[i].getPosition() + "|";
|
||||
print[i] = "-| humanNPC: " + array[i].getPosition() + "|-";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,7 +130,7 @@ 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].getPosition() + "|-";
|
||||
}
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
|
||||
@ -41,6 +41,31 @@ public class ServerGameInfoHandler {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses for an NPC what they want to say, so they don't sound the same all the time
|
||||
* @return a String saying that sm heard sm noise
|
||||
*/
|
||||
public static String noiseRandomizer() {
|
||||
String a = "I heard some noise tonight";
|
||||
String b = "noise";
|
||||
String c = "I heard smt strange tonight";
|
||||
String d = "Me, noise!";
|
||||
String e = "Uuuuh, spoky noises";
|
||||
int number = (int)(Math.random()*4);
|
||||
switch (number) {
|
||||
case 0:
|
||||
return a;
|
||||
case 1:
|
||||
return d;
|
||||
case 2:
|
||||
return c;
|
||||
case 3:
|
||||
return e;
|
||||
default:
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* decides which action an GhostNpc needs to take, based on a message
|
||||
* @param npc the GhostNpc needing to do smt
|
||||
@ -50,14 +75,12 @@ public class ServerGameInfoHandler {
|
||||
public static void ghostNpcParser(GhostNPC npc, String msg, Game game) {
|
||||
switch (msg) {
|
||||
case ClientGameInfoHandler.noiseNotification:
|
||||
//TODO(Seraina & Alex): noise handling
|
||||
game.getClientHandler().broadcastChatMessage(ClientGameInfoHandler.noiseNotification);
|
||||
String outMsg = npc.getName() + ": " + noiseRandomizer();
|
||||
game.getClientHandler().broadcastNpcChatMessage(outMsg);
|
||||
break;
|
||||
case ClientGameInfoHandler.ghostVoteRequest:
|
||||
npc.vote(game);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +92,8 @@ public class ServerGameInfoHandler {
|
||||
public static void humanNpcParser(HumanNPC npc, String msg, Game game) {
|
||||
switch (msg) {
|
||||
case ClientGameInfoHandler.noiseNotification:
|
||||
game.getClientHandler().broadcastChatMessage(ClientGameInfoHandler.noiseNotification);
|
||||
String outMsg = npc.getName() + ": " + noiseRandomizer();;
|
||||
game.getClientHandler().broadcastNpcChatMessage(outMsg);
|
||||
break;
|
||||
case ClientGameInfoHandler.humanVoteRequest:
|
||||
npc.vote();
|
||||
|
||||
@ -67,4 +67,8 @@ public class Train {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hallo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -78,23 +78,18 @@ public class Client {
|
||||
*/
|
||||
|
||||
public void voteGetter(final String msg) {
|
||||
/*TODO(Jonas): find a way to integrate this with userInput listener, so we can still send the
|
||||
* position to the server. This way doesnt work, after a game is finished it thinks you still
|
||||
* want to vote when entering /c msg
|
||||
*/
|
||||
/*TODO(Seraina): Find out what happens if there is no input*/
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int msgIndex = msg.indexOf('$');
|
||||
String position = msg.substring(0, msgIndex);
|
||||
String justMsg = msg.substring(msgIndex + 1);
|
||||
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
|
||||
while (socket.isConnected() && !socket.isClosed()) {
|
||||
try {
|
||||
if (bfr.ready()) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println(justMsg);
|
||||
try {
|
||||
System.out.println("Please enter your vote");
|
||||
String msgInput = bfr.readLine();
|
||||
String msgInput = input.nextLine();
|
||||
int vote;
|
||||
try {
|
||||
vote = Integer.parseInt(msgInput);
|
||||
@ -109,13 +104,12 @@ public class Client {
|
||||
"msg to server is: " + Protocol.votedFor + "$" + position + "$" + msgInput);
|
||||
|
||||
Thread.sleep(5);
|
||||
}
|
||||
|
||||
//LOGGER.debug("just checked next line");
|
||||
} catch (IOException | InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
@ -158,6 +158,17 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a pseudo chat Message from a NPC to all active clients
|
||||
*
|
||||
* @param msg the Message to be broadcast
|
||||
*/
|
||||
public void broadcastNpcChatMessage(String msg) {
|
||||
for (ClientHandler client : connectedClients) {
|
||||
client.sendMsgToClient(Protocol.printToClientConsole + "$" + msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a non-chat Message to all active clients. This can be used for server
|
||||
* messages / announcements rather than chat messages. The message will be printed to the user
|
||||
|
||||
Reference in New Issue
Block a user