forked from IF-LK-2020/wordle
An den if-Blöcken für die Abfragen gearbeitet
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
public class User {
|
public class User {
|
||||||
private String connectionID;
|
private String connectionID;
|
||||||
private String username;
|
private String username;
|
||||||
String password;
|
private String password;
|
||||||
private int timesPlayed;
|
private int timesPlayed;
|
||||||
private int winPercentage;
|
private int winPercentage;
|
||||||
private int currentStreak;
|
private int currentStreak;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,10 +54,10 @@ public class WordleServer extends Server {
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String m = pMessage.substring(0, 3);
|
||||||
switch (u.getState()) {
|
switch (u.getState()) {
|
||||||
case 1:
|
case 1:
|
||||||
// Anmeldephase
|
// Anmeldephase
|
||||||
String m = pMessage.substring(0, 3);
|
|
||||||
if (m.equalsIgnoreCase("USER")) {
|
if (m.equalsIgnoreCase("USER")) {
|
||||||
m = pMessage.substring(6, pMessage.length() - 1);
|
m = pMessage.substring(6, pMessage.length() - 1);
|
||||||
u.setUsername(m);
|
u.setUsername(m);
|
||||||
@@ -72,18 +73,57 @@ public class WordleServer extends Server {
|
|||||||
send(pClientIP, pClientPort, "+ERR login not valid");
|
send(pClientIP, pClientPort, "+ERR login not valid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if(m.equalsIgnoreCase("WOTD")) {
|
||||||
|
|
||||||
|
} else if(m.equalsIgnoreCase("PLAY")) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Spielphase
|
// Spielphase
|
||||||
|
if(m.equalsIgnoreCase("SEND")) {
|
||||||
|
|
||||||
|
} else if(m.equalsIgnoreCase("INFO")) {
|
||||||
|
int n = Integer.parseInt("0" + pMessage.substring(4,pMessage.length()).replaceAll(" ", ""));
|
||||||
|
if(n != 0) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if(m.equalsIgnoreCase("EXIT")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Zwischenphase(Angemeldet)
|
// 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' + ".");
|
||||||
|
} else if(m.equalsIgnoreCase("PLAY")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isToday(int pDay) {
|
||||||
|
return pDay == (int) (86400000.0 / Instant.now().toEpochMilli());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user