forked from IF-LK-2020/wordle
Befehl Info und Exit
Info und Exit implementiert sowie eine neue Methode checkWord() in Game erstellt
This commit is contained in:
@@ -53,7 +53,6 @@ public class WordleServer extends Server {
|
||||
u.setConnectionID(connectionID);
|
||||
if (pMessage.length() < 4) {
|
||||
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||
|
||||
} else {
|
||||
String m = pMessage.substring(0, 4);
|
||||
System.out.println("Message: " + m + " State: " + u.getState());
|
||||
@@ -65,11 +64,11 @@ public class WordleServer extends Server {
|
||||
case 1:
|
||||
// Anmeldephase
|
||||
if (m.equalsIgnoreCase("USER")) {
|
||||
m = pMessage.substring(5, pMessage.length() - 1);
|
||||
m = pMessage.substring(5, pMessage.length());
|
||||
u.setUsername(m);
|
||||
send(pClientIP, pClientPort, "+OK");
|
||||
} else if (m.equalsIgnoreCase("PASS")) {
|
||||
m = pMessage.substring(5, pMessage.length() - 1);
|
||||
m = pMessage.substring(5, pMessage.length());
|
||||
u.setPassword(m);
|
||||
if (u.getPassword() != null && u.getUsername() != null) {
|
||||
if (query.checkLogin(u.getUsername(), u.getPassword())) {
|
||||
@@ -104,7 +103,6 @@ public class WordleServer extends Server {
|
||||
if (m.length() == 5) {
|
||||
if (query.checkWord(m)) {
|
||||
String a = "+OK " + u.getGame().giveGuess(m);
|
||||
System.out.println(u.getGame().getGameStatus());
|
||||
switch (u.getGame().getGameStatus()) {
|
||||
case (1):
|
||||
a += " game continues";
|
||||
@@ -126,14 +124,27 @@ public class WordleServer extends Server {
|
||||
send(pClientIP, pClientPort, "-ERR wrong format");
|
||||
}
|
||||
} else if (m.equalsIgnoreCase("INFO")) {
|
||||
int n = Integer.parseInt("0" + pMessage.substring(4, pMessage.length()).replaceAll(" ", ""));
|
||||
if (n != 0) {
|
||||
|
||||
} else {
|
||||
|
||||
String substring = "0";
|
||||
if (m.length() > 4) {
|
||||
substring += pMessage.substring(5, pMessage.length()).replaceAll(" ", "");
|
||||
}
|
||||
int n = Integer.parseInt("0" + substring);
|
||||
String[] guesses = u.getGame().getGuesses();
|
||||
if (6 >= n && n >= 1) {
|
||||
String guess = guesses[n];
|
||||
send(pClientIP, pClientPort, "+OK " + guess + " " + u.getGame().checkGuess(guess));
|
||||
} else if (n == 0) {
|
||||
String a = "+OK ";
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (guesses[i] == null) {
|
||||
a += guesses[i] + " " + u.getGame().checkGuess(guesses[i]);
|
||||
}
|
||||
}
|
||||
send(pClientIP, pClientPort, a);
|
||||
}
|
||||
} else if (m.equalsIgnoreCase("EXIT")) {
|
||||
|
||||
u.getGame().stopGame();
|
||||
u.setState(3);
|
||||
} else {
|
||||
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user