Ifception der Wordle-Server Klasse

An der Bearbeitung der Abfragen gearbeitet, versucht die giveGuess-Methode zu fixen
This commit is contained in:
2022-03-20 15:56:05 +01:00
parent 02d6252537
commit 81e54b9d39
5 changed files with 124 additions and 87 deletions

View File

@@ -1,14 +1,13 @@
public class Game {
private String word;
private String[] guesses;
private boolean won;
// TODO:
Game() {
word = "";
}
public void startGame() {
won = false;
guesses = new String[5];
}
/**
@@ -22,17 +21,17 @@ public class Game {
* @return Eine Zahlenfolge mit der Korrektheit des Worts
*/
public String giveGuess(String guess) {
String g = guess;
StringBuilder g = new StringBuilder(guess);
StringBuilder word = new StringBuilder(this.word);
String s = "";
for (int i = 0; i < word.length(); i++) {
if (guess.charAt(0) == word.charAt(0)) {
if (g.charAt(0) == word.charAt(0)) {
word.deleteCharAt(0);
s += "2";
} else {
boolean found = false;
for (int r = 0; r < word.length(); r++) {
if (r != i && guess.charAt(0) == word.charAt(r)) {
for (int r = 1; r < word.length(); r++) {
if (g.charAt(0) == word.charAt(r)) {
s += "1";
found = true;
word.deleteCharAt(r);
@@ -43,10 +42,11 @@ public class Game {
s += "0";
}
}
guess.replaceFirst(guess, "");
g.deleteCharAt(0);
}
if(storeInArray(g)) {
if(storeInArray(g.toString())) {
stopGame();
won = !word.isEmpty();
}
return s;
}
@@ -67,12 +67,16 @@ public class Game {
return true;
}
public void startWOTD(String wotd) {
word = wotd;
public void startGame(String word) {
this.word = word;
}
public boolean isGameRunning() {
return word.equals("") || word.equals(null);
return !word.equals("") || !word.equals(null);
}
public boolean won() {
return won;
}
private void stopGame() {