From d218b291aaf03e085115ca3cedcb228466306110 Mon Sep 17 00:00:00 2001 From: Meiko Remiorz Date: Wed, 13 Apr 2022 18:52:44 +0200 Subject: [PATCH] Nacken Wordle fertig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jetzt fehlt nur noch eine Datenbank mit wörtern --- .../Pages/Wordle.razor | 108 +++++++++++++----- 1 file changed, 78 insertions(+), 30 deletions(-) diff --git a/GottfriedsNackenWebseite/GottfriedsNackenWebseite/Pages/Wordle.razor b/GottfriedsNackenWebseite/GottfriedsNackenWebseite/Pages/Wordle.razor index 6b826c6..d5feaa2 100644 --- a/GottfriedsNackenWebseite/GottfriedsNackenWebseite/Pages/Wordle.razor +++ b/GottfriedsNackenWebseite/GottfriedsNackenWebseite/Pages/Wordle.razor @@ -1,41 +1,71 @@ @page "/wordle" Nacken Wordle + Rate ein Wort mit 5 Buchstaben: - Willkommen zum Nacken Wordle - + +
- @for(int i = 0; i < 6; i++) + @foreach(var guess in PreviousGuesses) {
- @for(int j = 0; j < 5; j++) + + + @for(int i = 0; i < 5; i++) { - - - - + + var j = i; + if(@guess.ToUpper()[j] == secret.ToUpper()[j]) + { + + @guess.ToUpper()[j] + + }else if (secret.ToUpper().Contains(@guess.ToUpper()[j])) + { + + @guess.ToUpper()[j] + + }else + { + + @guess.ToUpper()[j] + + } } -
+
}
- -
- - Hi - - OK - -
- + + + + + + Hi + + + OK + + + + @code { public string Input { get; set; } @@ -44,17 +74,40 @@ public MudTextField textField; + public List PreviousGuesses = new List(); + //Keine Ahnung wie das funktionert... Danke StackOverflow :) public IMask mask = new RegexMask(@"^[A-Za-z]{0,5}$"); - private string secret = "penis"; + public string secret = "penis"; + private bool found = false; + + public void Check4Enter(KeyboardEventArgs e) + { + Console.Out.WriteLine(e); + Console.Out.WriteLine(e.Code); + if (e.Code == "Enter" || e.Code == "NumpadEnter") + { + if(found) + { + PlayAgain(); + } + else + { + ButtonOnClick(); + } + } + } public void ButtonOnClick() { - if(Input != null) + if(Input != null && Input.Length == 5 && !found) { + Console.Out.WriteLine(Input); + PreviousGuesses.Add(Input); if(secret.ToLower() == Input.ToLower()) { + found = true; textField.Clear(); hideAlert = false; } @@ -63,17 +116,12 @@ textField.Clear(); } } - } - private Color getColor(char letter, int position, string secret) + public void PlayAgain() { - if (position > secret.Length) return Color.Primary; - - if(letter == secret[position]) return Color.Success; - - if (secret.Contains(letter)) return Color.Warning; - - return Color.Primary; + PreviousGuesses.Clear(); + hideAlert = true; + found = false; } }