forked from IF-LK-2020/wordle
ZU VIEL gemacht
Mein Brain ist kaputt
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
@@ -63,11 +62,11 @@ public class WordleServer extends Server {
|
||||
switch (u.getState()) {
|
||||
case 1:
|
||||
// Anmeldephase
|
||||
if (m.equalsIgnoreCase("USER")) {
|
||||
if (m.equalsIgnoreCase("USER") && !u.loggedIn()) {
|
||||
m = pMessage.substring(5, pMessage.length());
|
||||
u.setUsername(m);
|
||||
send(pClientIP, pClientPort, "+OK");
|
||||
} else if (m.equalsIgnoreCase("PASS")) {
|
||||
} else if (m.equalsIgnoreCase("PASS") && !u.loggedIn()) {
|
||||
m = pMessage.substring(5, pMessage.length());
|
||||
u.setPassword(m);
|
||||
if (u.getPassword() != null && u.getUsername() != null) {
|
||||
@@ -93,6 +92,14 @@ public class WordleServer extends Server {
|
||||
} else {
|
||||
send(pClientIP, pClientPort, "-ERR game finished");
|
||||
}
|
||||
} else if (m.equalsIgnoreCase("PLAY")) {
|
||||
if (isToday(u.getLastDayWOTDPlayed()) && u.getGame().getGameStatus() != 1) {
|
||||
u.getGame().startGame(query.getWord());
|
||||
u.setState(2);
|
||||
send(pClientIP, pClientPort, "+OK Game ready");
|
||||
} else {
|
||||
send(pClientIP, pClientPort, "-ERR wotd not finished");
|
||||
}
|
||||
} else {
|
||||
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||
}
|
||||
@@ -110,12 +117,15 @@ public class WordleServer extends Server {
|
||||
break;
|
||||
case (2):
|
||||
a += " game won";
|
||||
u.increaseWonInTurnIndex(u.getGame().getGuessesCount() - 1);
|
||||
u.setState(3);
|
||||
break;
|
||||
case (3):
|
||||
a += " game lost";
|
||||
u.setState(3);
|
||||
break;
|
||||
default:
|
||||
a += " what";
|
||||
}
|
||||
send(pClientIP, pClientPort, a);
|
||||
} else {
|
||||
@@ -125,27 +135,35 @@ public class WordleServer extends Server {
|
||||
send(pClientIP, pClientPort, "-ERR wrong format");
|
||||
}
|
||||
} else if (m.equalsIgnoreCase("INFO")) {
|
||||
bruh();
|
||||
String substring = "0";
|
||||
if (m.length() > 4) {
|
||||
substring += pMessage.substring(5, pMessage.length()).replaceAll(" ", "");
|
||||
if (pMessage.length() > 4) {
|
||||
substring += pMessage.substring(4, 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));
|
||||
//TODO:
|
||||
if (guesses[n - 1] != null) {
|
||||
String guess = guesses[n - 1];
|
||||
send(pClientIP, pClientPort, "+OK " + guess + " " + u.getGame().checkGuess(guess));
|
||||
} else {
|
||||
send(pClientIP, pClientPort, "-ERR word not typed yet");
|
||||
}
|
||||
} 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]);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (guesses[i] != null) {
|
||||
a += " " + guesses[i] + " " + u.getGame().checkGuess(guesses[i]);
|
||||
}
|
||||
}
|
||||
send(pClientIP, pClientPort, a);
|
||||
}
|
||||
} else if (m.equalsIgnoreCase("EXIT")) {
|
||||
u.updateLastDayWOTDPlayed();
|
||||
u.getGame().stopGame();
|
||||
u.setState(3);
|
||||
send(pClientIP, pClientPort, "+OK");
|
||||
} else {
|
||||
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||
}
|
||||
@@ -154,13 +172,13 @@ public class WordleServer extends Server {
|
||||
// Zwischenphase(Angemeldet)
|
||||
if (m.equalsIgnoreCase("STAT")) {
|
||||
send(pClientIP, pClientPort,
|
||||
"+OK" + '\n' + "times played: " + u.getTimesPlayed() + '\n' + "win percentage: "
|
||||
+ u.getWinPercentage() + '\n' + "current streak: " + u.getCurrentStreak() + '\n'
|
||||
+ "max streak: " + u.getMaxStreak() + '\n' + "won in 1 turn: "
|
||||
+ u.getWonInTurnIndex(1) + '\n' + "won in 2 turn: " + u.getWonInTurnIndex(2) + '\n'
|
||||
+ "won in 3 turn: " + u.getWonInTurnIndex(3) + '\n' + "won in 4 turn: "
|
||||
+ u.getWonInTurnIndex(4) + '\n' + "won in 5 turn: " + u.getWonInTurnIndex(5) + '\n'
|
||||
+ "won in 6 turn: " + u.getWonInTurnIndex(6) + '\n' + ".");
|
||||
"+OK" + '\n' + "times played: " + u.getTimesPlayed() + "\n" + "win percentage: "
|
||||
+ u.getWinPercentage() + "\n" + "current streak: " + u.getCurrentStreak() + "\n"
|
||||
+ "max streak: " + u.getMaxStreak() + "\n" + "won in 1 turn: "
|
||||
+ u.getWonInTurnIndex(0) + "\n" + "won in 2 turn: " + u.getWonInTurnIndex(1) + "\n"
|
||||
+ "won in 3 turn: " + u.getWonInTurnIndex(2) + "\n" + "won in 4 turn: "
|
||||
+ u.getWonInTurnIndex(3) + "\n" + "won in 5 turn: " + u.getWonInTurnIndex(4) + "\n"
|
||||
+ "won in 6 turn: " + u.getWonInTurnIndex(5) + "\n" + ".");
|
||||
} else if (m.equalsIgnoreCase("PLAY")) {
|
||||
if (isToday(u.getLastDayWOTDPlayed()) && u.getGame().getGameStatus() != 1) {
|
||||
u.getGame().startGame(query.getWord());
|
||||
@@ -178,7 +196,18 @@ public class WordleServer extends Server {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt zurück ob es sich bei dem im Parameter angegebenen Tag um den heutigen
|
||||
* handelt
|
||||
*
|
||||
* @param pDay ,die Anzahl der Tage seit dem Epoch-Day
|
||||
* @return true oder false
|
||||
*/
|
||||
public boolean isToday(int pDay) {
|
||||
return pDay == (int) ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now());
|
||||
}
|
||||
|
||||
public void bruh() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user