Befehl Info und Exit

Info und Exit implementiert sowie eine neue Methode checkWord() in Game erstellt
This commit is contained in:
Maxim Derksen
2022-03-24 11:33:46 +01:00
parent 2c14b051df
commit 9ecd839df1
2 changed files with 49 additions and 12 deletions

View File

@@ -47,7 +47,6 @@ public class Game {
guess.deleteCharAt(0);
}
if (word.isEmpty()) {
System.out.println("öasdlkihg");
won = 1;
stopGame();
} else if (storeInArray(guess.toString())) {
@@ -56,6 +55,33 @@ public class Game {
}
return s;
}
public String checkGuess(String g) {
StringBuilder guess = new StringBuilder(g);
StringBuilder word = new StringBuilder(this.word);
String s = "";
for (int i = 0; i < this.word.length(); i++) {
if (guess.charAt(0) == word.charAt(0)) {
word.deleteCharAt(0);
s += "2";
} else {
boolean found = false;
for (int r = 1; r < word.length(); r++) {
if (guess.charAt(0) == word.charAt(r)) {
s += "1";
found = true;
word.deleteCharAt(r);
break;
}
}
if (!found) {
s += "0";
}
}
guess.deleteCharAt(0);
}
return s;
}
/**
* Speichert das Wort in der nächsten freien Stelle im Array und gibt danach
@@ -82,7 +108,7 @@ public class Game {
return !word.equals("") || !word.equals(null);
}
private void stopGame() {
public void stopGame() {
word = "";
guesses = new String[guesses.length - 1];
}