Added a thread to voteGetter so it would interfere with Pinger. Added to do for jonas
This commit is contained in:
parent
159310c7ca
commit
362b965742
@ -77,28 +77,48 @@ public class Client {
|
|||||||
* Tells user to enter a position to vote for passenger at that position
|
* Tells user to enter a position to vote for passenger at that position
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void voteGetter(String msg) {
|
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
|
||||||
|
*/
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
int msgIndex = msg.indexOf('$');
|
int msgIndex = msg.indexOf('$');
|
||||||
String position = msg.substring(0, msgIndex);;
|
String position = msg.substring(0, msgIndex);
|
||||||
msg = msg.substring(msgIndex + 1);
|
String justMsg = msg.substring(msgIndex + 1);
|
||||||
Scanner userInput = new Scanner(System.in);
|
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
|
||||||
//TODO(Seraina): implement
|
while (socket.isConnected() && !socket.isClosed()) {
|
||||||
System.out.println(msg);
|
|
||||||
System.out.println("Please enter your vote");
|
|
||||||
int vote;
|
|
||||||
String input = "";
|
|
||||||
try {
|
try {
|
||||||
input = userInput.nextLine();
|
if (bfr.ready()) {
|
||||||
vote = Integer.parseInt(input);
|
System.out.println(justMsg);
|
||||||
|
System.out.println("Please enter your vote");
|
||||||
|
String msgInput = bfr.readLine();
|
||||||
|
int vote;
|
||||||
|
try {
|
||||||
|
vote = Integer.parseInt(msgInput);
|
||||||
LOGGER.info("input is: " + vote);
|
LOGGER.info("input is: " + vote);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn(e.getMessage());
|
LOGGER.warn(e.getMessage());
|
||||||
System.out.println("Invalid vote");
|
System.out.println("Invalid vote");
|
||||||
input = String.valueOf(Integer.MAX_VALUE);
|
msgInput = String.valueOf(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
sendMsgToServer(Protocol.votedFor + "$" + position + "$" + input);
|
sendMsgToServer(Protocol.votedFor + "$" + position + "$" + msgInput);
|
||||||
LOGGER.debug("msg to server is: " + Protocol.votedFor + "$" + position + "$" + input);
|
LOGGER.debug(
|
||||||
|
"msg to server is: " + Protocol.votedFor + "$" + position + "$" + msgInput);
|
||||||
|
|
||||||
|
Thread.sleep(5);
|
||||||
}
|
}
|
||||||
|
//LOGGER.debug("just checked next line");
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -98,7 +98,7 @@ public class Protocol {
|
|||||||
public static final String startANewGame = "STGAM";
|
public static final String startANewGame = "STGAM";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client informs server that they have voted and delivers this vote in the form of "CVOTE$position"
|
* Client informs server that they have voted and delivers this vote in the form of "CVOTE$position$vote"
|
||||||
*/
|
*/
|
||||||
public static final String votedFor = "CVOTE";
|
public static final String votedFor = "CVOTE";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user