forked from IF-LK-2020/wordle
working stats
This commit is contained in:
@@ -117,15 +117,7 @@ public class Game {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
send("-ERR not logged in.");
|
send("-ERR not logged in.");
|
||||||
} else {
|
} else {
|
||||||
databaseConnector.executeStatement("SELECT word FROM words WHERE id = " + (int) (Math.random() * 950));
|
playRandomWordle();
|
||||||
QueryResult result = databaseConnector.getCurrentQueryResult();
|
|
||||||
if (result != null && result.getData().length > 0) {
|
|
||||||
wordle = result.getData()[0][0].toLowerCase();
|
|
||||||
phase = GAME_PHASE;
|
|
||||||
send("+OK game ready");
|
|
||||||
} else {
|
|
||||||
send("-ERR fatal error: Wordle could not be generated.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendUniversalError();
|
sendUniversalError();
|
||||||
@@ -137,7 +129,9 @@ public class Game {
|
|||||||
if (msg.startsWith("send ")) {
|
if (msg.startsWith("send ")) {
|
||||||
|
|
||||||
String args = msg.substring(5);
|
String args = msg.substring(5);
|
||||||
System.out.println(wordle);
|
|
||||||
|
System.out.println(wordle);
|
||||||
|
|
||||||
if (args.length() == 5) {
|
if (args.length() == 5) {
|
||||||
|
|
||||||
databaseConnector.executeStatement("SELECT word FROM words WHERE word LIKE '" + args + "'");
|
databaseConnector.executeStatement("SELECT word FROM words WHERE word LIKE '" + args + "'");
|
||||||
@@ -165,20 +159,33 @@ System.out.println(wordle);
|
|||||||
send(code);
|
send(code);
|
||||||
if (code.equals("22222")) { // und ein wordle ist 5 Buchstaben lang :D
|
if (code.equals("22222")) { // und ein wordle ist 5 Buchstaben lang :D
|
||||||
send("game won");
|
send("game won");
|
||||||
|
|
||||||
|
wordle = null;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
user.increaseCurrentStreak();
|
||||||
|
if (user.getMaxStreak() < user.getCurrentStreak()) {
|
||||||
|
user.setMaxStreak(user.getCurrentStreak());
|
||||||
|
}
|
||||||
|
user.increaseWonInTurn(count + 1);
|
||||||
|
updateStats();
|
||||||
phase = END_PHASE;
|
phase = END_PHASE;
|
||||||
} else {
|
} else {
|
||||||
phase = LOGIN_PHASE;
|
phase = LOGIN_PHASE;
|
||||||
}
|
}
|
||||||
} else if (count == 6) {
|
count = 0;
|
||||||
|
} else if (count == 5) {
|
||||||
send("game lost");
|
send("game lost");
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
user.setCurrentStreak(0);
|
||||||
|
updateStats();
|
||||||
phase = END_PHASE;
|
phase = END_PHASE;
|
||||||
} else {
|
} else {
|
||||||
phase = LOGIN_PHASE;
|
phase = LOGIN_PHASE;
|
||||||
}
|
}
|
||||||
|
count = 0;
|
||||||
} else {
|
} else {
|
||||||
send("game continues");
|
send("game continues");
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -194,6 +201,7 @@ System.out.println(wordle);
|
|||||||
} else if (msg.startsWith("exit")) {
|
} else if (msg.startsWith("exit")) {
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
send("+OK");
|
||||||
phase = END_PHASE;
|
phase = END_PHASE;
|
||||||
} else {
|
} else {
|
||||||
send("-ERR not logged in.");
|
send("-ERR not logged in.");
|
||||||
@@ -210,20 +218,49 @@ System.out.println(wordle);
|
|||||||
|
|
||||||
send("times Played: " + user.getTimesPlayed());
|
send("times Played: " + user.getTimesPlayed());
|
||||||
|
|
||||||
send("win Percentage: " + user.getWinPercentage());
|
send("win Percentage: " + (int) user.getWinPercentage() + "%");
|
||||||
|
|
||||||
send("current Streak: " + user.getCurrentStreak());
|
send("current Streak: " + user.getCurrentStreak());
|
||||||
|
|
||||||
send("max Streak: " + user.getMaxStreak());
|
send("max Streak: " + user.getMaxStreak());
|
||||||
|
|
||||||
for (int i = 1; i < 6; i++) {
|
for (int i = 1; i <= 6; i++) {
|
||||||
send("won in Turn1: " + user.getWonInTurn(i));
|
send("won in Turn" + i + ": " + user.getWonInTurn(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (msg.startsWith("play")) {
|
} else if (msg.startsWith("play")) {
|
||||||
|
if (wordle == null) {
|
||||||
|
playRandomWordle();
|
||||||
|
} else {
|
||||||
phase = GAME_PHASE;
|
phase = GAME_PHASE;
|
||||||
|
send("+OK game ready");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendUniversalError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateStats() {
|
||||||
|
user.increaseTimesPlayed();
|
||||||
|
|
||||||
|
int totalWins = 0;
|
||||||
|
for (int i = 1; i <= 6; i++) {
|
||||||
|
totalWins += user.getWonInTurn(i);
|
||||||
|
}
|
||||||
|
float winP = (float) totalWins / user.getTimesPlayed();
|
||||||
|
|
||||||
|
user.setWinPercentage(Math.round(winP * 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playRandomWordle() {
|
||||||
|
databaseConnector.executeStatement("SELECT word FROM words WHERE id = " + (int) (Math.random() * 950));
|
||||||
|
QueryResult result = databaseConnector.getCurrentQueryResult();
|
||||||
|
if (result != null && result.getData().length > 0) {
|
||||||
|
wordle = result.getData()[0][0].toLowerCase();
|
||||||
|
phase = GAME_PHASE;
|
||||||
|
send("+OK game ready");
|
||||||
|
} else {
|
||||||
|
send("-ERR fatal error: Wordle could not be generated.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user